From e0cd397dc1933b17e646129cfc03b85fb5a98d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Gu=C5=A1i=C4=87?= Date: Tue, 14 Sep 2021 15:16:03 +0200 Subject: [PATCH] Make m_context.selection synced with m_selection (#1894) --- src/widgets/capture/capturewidget.cpp | 9 +++++---- src/widgets/capture/selectionwidget.cpp | 1 + src/widgets/capture/selectionwidget.h | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index c7cd1b95..6fe2727d 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -750,7 +750,6 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e) newGeometry.setBottom(top); } m_selection->setGeometry(newGeometry); - m_context.selection = extendedRect(newGeometry); updateSizeIndicator(); m_buttonHandler->updatePosition(newGeometry); m_buttonHandler->show(); @@ -1046,6 +1045,11 @@ void CaptureWidget::initSelection() connect(m_selection, &SelectionWidget::animationEnded, this, [this]() { this->m_buttonHandler->updatePosition(this->m_selection->geometry()); }); + connect(m_selection, &SelectionWidget::resized, this, [this]() { + QRect constrainedToCaptureArea = + m_selection->geometry().intersected(rect()); + m_context.selection = extendedRect(constrainedToCaptureArea); + }); m_selection->setVisible(false); m_selection->setGeometry(QRect()); } @@ -1289,8 +1293,6 @@ void CaptureWidget::repositionSelection(QRect r) { if (m_selection->isVisible()) { m_selection->setGeometry(r); - QRect newGeometry = m_selection->geometry().intersected(rect()); - m_context.selection = extendedRect(newGeometry); m_buttonHandler->updatePosition(m_selection->geometry()); updateSizeIndicator(); update(); @@ -1329,7 +1331,6 @@ void CaptureWidget::selectAll() { QRect newGeometry = rect(); m_selection->setGeometry(newGeometry); - m_context.selection = extendedRect(newGeometry); m_selection->setVisible(true); m_buttonHandler->updatePosition(m_selection->geometry()); updateSizeIndicator(); diff --git a/src/widgets/capture/selectionwidget.cpp b/src/widgets/capture/selectionwidget.cpp index 9a0ef686..514728a8 100644 --- a/src/widgets/capture/selectionwidget.cpp +++ b/src/widgets/capture/selectionwidget.cpp @@ -97,6 +97,7 @@ void SelectionWidget::resizeEvent(QResizeEvent*) void SelectionWidget::moveEvent(QMoveEvent*) { updateAreas(); + emit resized(); } void SelectionWidget::updateColor(const QColor& c) diff --git a/src/widgets/capture/selectionwidget.h b/src/widgets/capture/selectionwidget.h index 6684aafe..f1179d28 100644 --- a/src/widgets/capture/selectionwidget.h +++ b/src/widgets/capture/selectionwidget.h @@ -40,6 +40,7 @@ protected: signals: void animationEnded(); + void resized(); public slots: void updateColor(const QColor& c);