Do not automatically reset progress details position

Add a "pin" button that appears on hover if the details have been
dragged around. Clicking on it resets the position.

Position is also reset when hiding & re-showing the details with the
button. And the details snap to the original position when dragged near
it.

Fixes: QTCREATORBUG-28829
Change-Id: I6a6f13ca1baac79951c20f2e8edf6fac137a8cfc
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2023-03-27 12:00:13 +02:00
parent de733a4294
commit 29108a1463
2 changed files with 41 additions and 2 deletions

View File

@@ -5,11 +5,19 @@
#include "../coreplugintr.h"
#include <utils/icon.h>
#include <utils/overlaywidget.h>
#include <QApplication>
#include <QEvent>
#include <QMouseEvent>
#include <QPainter>
#include <QVBoxLayout>
using namespace Utils;
const int PIN_SIZE = 12;
namespace Core::Internal {
ProgressView::ProgressView(QWidget *parent)
@@ -21,15 +29,29 @@ ProgressView::ProgressView(QWidget *parent)
m_layout->setSpacing(0);
m_layout->setSizeConstraint(QLayout::SetFixedSize);
setWindowTitle(Tr::tr("Processes"));
auto pinButton = new OverlayWidget(this);
pinButton->attachToWidget(this);
pinButton->setAttribute(Qt::WA_TransparentForMouseEvents, false); // override OverlayWidget
pinButton->setPaintFunction([](QWidget *that, QPainter &p, QPaintEvent *) {
static const QIcon icon = Icon({{":/utils/images/pinned_small.png", Theme::IconsBaseColor}},
Icon::Tint)
.icon();
QRect iconRect(0, 0, PIN_SIZE, PIN_SIZE);
iconRect.moveTopRight(that->rect().topRight());
icon.paint(&p, iconRect);
});
pinButton->setVisible(false);
pinButton->installEventFilter(this);
m_pinButton = pinButton;
}
ProgressView::~ProgressView() = default;
void ProgressView::addProgressWidget(QWidget *widget)
{
if (m_layout->count() == 0)
m_anchorBottomRight = {}; // reset temporarily user-moved progress details
m_layout->insertWidget(0, widget);
m_pinButton->raise();
}
void ProgressView::removeProgressWidget(QWidget *widget)
@@ -63,9 +85,12 @@ bool ProgressView::event(QEvent *event)
reposition();
} else if (event->type() == QEvent::Enter) {
m_hovered = true;
if (m_anchorBottomRight != QPoint())
m_pinButton->setVisible(true);
emit hoveredChanged(m_hovered);
} else if (event->type() == QEvent::Leave) {
m_hovered = false;
m_pinButton->setVisible(false);
emit hoveredChanged(m_hovered);
} else if (event->type() == QEvent::Show) {
m_anchorBottomRight = {}; // reset temporarily user-moved progress details
@@ -78,6 +103,16 @@ bool ProgressView::eventFilter(QObject *obj, QEvent *event)
{
if ((obj == parentWidget() || obj == m_referenceWidget) && event->type() == QEvent::Resize)
reposition();
if (obj == m_pinButton && event->type() == QEvent::MouseButtonRelease) {
auto me = static_cast<QMouseEvent *>(event);
if (me->button() == Qt::LeftButton
&& QRectF(m_pinButton->width() - PIN_SIZE, 0, PIN_SIZE, PIN_SIZE)
.contains(me->position())) {
me->accept();
m_anchorBottomRight = {};
reposition();
}
}
return false;
}
@@ -133,6 +168,9 @@ void ProgressView::reposition()
{
if (!parentWidget() || !m_referenceWidget)
return;
m_pinButton->setVisible(m_anchorBottomRight != QPoint() && m_hovered);
move(boundedInParent(this, topRightReferenceInParent() + m_anchorBottomRight, parentWidget())
- rect().bottomRight());
}

View File

@@ -44,6 +44,7 @@ private:
QVBoxLayout *m_layout;
QWidget *m_referenceWidget = nullptr;
QWidget *m_pinButton = nullptr;
// dragging
std::optional<QPointF> m_clickPosition;