Browse Source

Make m_context.selection synced with m_selection (#1894)

Haris Gušić 3 years ago
parent
commit
e0cd397dc1

+ 5 - 4
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();

+ 1 - 0
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)

+ 1 - 0
src/widgets/capture/selectionwidget.h

@@ -40,6 +40,7 @@ protected:
 
 signals:
     void animationEnded();
+    void resized();
 
 public slots:
     void updateColor(const QColor& c);