From 29c7a5f7814f4b167d647e31e6df3cd515b385c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Gu=C5=A1i=C4=87?= Date: Tue, 31 Aug 2021 22:00:58 +0200 Subject: [PATCH] Fix selection bug introduced in ac3e9189 (#1860) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Haris Gušić --- src/widgets/capture/capturewidget.cpp | 43 +++++++++++++++------------ src/widgets/capture/capturewidget.h | 1 + 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 631086bd..bfb44c5c 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -51,6 +51,7 @@ CaptureWidget::CaptureWidget(uint id, , m_mouseIsClicked(false) , m_newSelection(true) , m_grabbing(false) + , m_movingSelection(false) , m_captureDone(false) , m_previewEnabled(true) , m_adjustmentButtonPressed(false) @@ -586,25 +587,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent* e) m_buttonHandler->hide(); } QRect inputRect; - if (m_newSelection) { - // Drawing a new selection - inputRect = symmetryMod - ? QRect(m_dragStartPoint * 2 - m_context.mousePos, - m_context.mousePos) - : QRect(m_dragStartPoint, m_context.mousePos); - - } else if (m_mouseOverHandle == SelectionWidget::NO_SIDE) { - // Moving the whole selection - if (m_adjustmentButtonPressed || activeToolObject().isNull()) { - setCursor(Qt::OpenHandCursor); - QRect initialRect = m_selection->savedGeometry().normalized(); - QPoint newTopLeft = - initialRect.topLeft() + (e->pos() - m_dragStartPoint); - inputRect = QRect(newTopLeft, initialRect.size()); - } else { - return; - } - } else { + if (m_mouseOverHandle != SelectionWidget::NO_SIDE) { // Dragging a handle inputRect = m_selection->savedGeometry(); QPoint offset = e->pos() - m_dragStartPoint; @@ -647,6 +630,27 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent* e) r.setLeft(r.left() - offset.x()); } } + } else if (!m_movingSelection && + (!m_selection->geometry().contains(e->pos()) || + m_newSelection)) { + m_newSelection = true; + // Drawing a new selection + inputRect = symmetryMod + ? QRect(m_dragStartPoint * 2 - m_context.mousePos, + m_context.mousePos) + : QRect(m_dragStartPoint, m_context.mousePos); + } else if (m_mouseOverHandle == SelectionWidget::NO_SIDE) { + // Moving the whole selection + m_movingSelection = true; + if (m_adjustmentButtonPressed || activeToolObject().isNull()) { + setCursor(Qt::OpenHandCursor); + QRect initialRect = m_selection->savedGeometry().normalized(); + QPoint newTopLeft = + initialRect.topLeft() + (e->pos() - m_dragStartPoint); + inputRect = QRect(newTopLeft, initialRect.size()); + } else { + return; + } } m_selection->setGeometry(inputRect.intersected(rect()).normalized()); update(); @@ -744,6 +748,7 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e) m_mouseIsClicked = false; m_activeToolIsMoved = false; m_grabbing = false; + m_movingSelection = false; if (m_selection->isVisible()) { m_newSelection = false; } diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h index abe07fb7..bc5395c6 100644 --- a/src/widgets/capture/capturewidget.h +++ b/src/widgets/capture/capturewidget.h @@ -157,6 +157,7 @@ private: bool m_mouseIsClicked; bool m_newSelection; bool m_grabbing; + bool m_movingSelection; bool m_showInitialMsg; bool m_captureDone; bool m_previewEnabled;