Browse Source

Some tweaks to the capture GUI (#1841)

* Don't show buttons if selection is inactive

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Move tool creates new selection if not visible

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Make thickness adjustment methods uniform

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Hide  cursor while changing thickness

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
Haris Gušić 3 years ago
parent
commit
ac3e918960

+ 43 - 43
src/widgets/capture/capturewidget.cpp

@@ -49,7 +49,7 @@ CaptureWidget::CaptureWidget(uint id,
                              QWidget* parent)
   : QWidget(parent)
   , m_mouseIsClicked(false)
-  , m_newSelection(false)
+  , m_newSelection(true)
   , m_grabbing(false)
   , m_captureDone(false)
   , m_previewEnabled(true)
@@ -188,6 +188,10 @@ CaptureWidget::CaptureWidget(uint id,
     // Init notification widget
     m_notifierBox = new NotifierBox(this);
     m_notifierBox->hide();
+    connect(m_notifierBox, &NotifierBox::hidden, this, [this]() {
+        // Show cursor if it was hidden while adjusting tool thickness
+        updateCursor();
+    });
 
     initPanel();
 }
@@ -215,6 +219,7 @@ void CaptureWidget::initButtons()
             m_sizeIndButton = b;
         }
         b->setColor(m_uiColor);
+        b->hide();
         makeChild(b);
 
         switch (t) {
@@ -253,8 +258,6 @@ void CaptureWidget::initButtons()
                     this,
                     &CaptureWidget::setState);
             vectorButtons << b;
-        } else {
-            b->hide();
         }
     }
     m_buttonHandler->setButtons(vectorButtons);
@@ -494,7 +497,6 @@ void CaptureWidget::mousePressEvent(QMouseEvent* e)
                 m_selection->setGeometry(
                   QRect(m_mousePressedPos, m_mousePressedPos));
                 m_selection->setVisible(false);
-                m_newSelection = true;
                 m_buttonHandler->hide();
                 update();
             } else {
@@ -663,7 +665,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent* e)
               m_buttonHandler->contains(m_context.mousePos);
             if (containsMouse) {
                 m_buttonHandler->hide();
-            } else {
+            } else if (m_selection->isVisible()) {
                 m_buttonHandler->show();
             }
         }
@@ -741,8 +743,10 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
     }
     m_mouseIsClicked = false;
     m_activeToolIsMoved = false;
-    m_newSelection = false;
     m_grabbing = false;
+    if (m_selection->isVisible()) {
+        m_newSelection = false;
+    }
 
     updateCursor();
 }
@@ -752,6 +756,36 @@ void CaptureWidget::moveSelection(QPoint p)
     adjustSelection(QMargins(-p.x(), -p.y(), p.x(), p.y()));
 }
 
+void CaptureWidget::updateThickness(int thicknessOffset)
+{
+    m_context.thickness += thicknessOffset;
+    m_context.thickness = qBound(1, m_context.thickness, 100);
+
+    QPoint topLeft =
+      QGuiAppCurrentScreen().currentScreen()->geometry().topLeft();
+    int offset = m_notifierBox->width() / 4;
+    m_notifierBox->move(mapFromGlobal(topLeft) + QPoint(offset, offset));
+    m_notifierBox->showMessage(QString::number(m_context.thickness));
+
+    if (m_activeButton && m_activeButton->tool() &&
+        m_activeButton->tool()->showMousePreview()) {
+        setCursor(Qt::BlankCursor);
+        update();
+    }
+
+    // update selected object thickness
+    auto toolItem = activeToolObject();
+    if (toolItem) {
+        toolItem->thicknessChanged(m_context.thickness);
+        if (!m_existingObjectIsChanged) {
+            m_captureToolObjectsBackup = m_captureToolObjects;
+            m_existingObjectIsChanged = true;
+        }
+    }
+
+    emit thicknessChanged(m_context.thickness);
+}
+
 void CaptureWidget::moveLeft()
 {
     moveSelection(QPoint(-1, 0));
@@ -826,29 +860,7 @@ void CaptureWidget::wheelEvent(QWheelEvent* e)
         }
     }
 
-    m_context.thickness += thicknessOffset;
-    m_context.thickness = qBound(1, m_context.thickness, 100);
-    QPoint topLeft =
-      QGuiAppCurrentScreen().currentScreen()->geometry().topLeft();
-    int offset = m_notifierBox->width() / 4;
-    m_notifierBox->move(mapFromGlobal(topLeft) + QPoint(offset, offset));
-    m_notifierBox->showMessage(QString::number(m_context.thickness));
-    if (m_activeButton && m_activeButton->tool() &&
-        m_activeButton->tool()->showMousePreview()) {
-        update();
-    }
-
-    // update selected object thickness
-    // Reset selection if mouse pos is not in selection area
-    auto toolItem = activeToolObject();
-    if (toolItem) {
-        toolItem->thicknessChanged(m_context.thickness);
-        if (!m_existingObjectIsChanged) {
-            m_captureToolObjectsBackup = m_captureToolObjects;
-            m_existingObjectIsChanged = true;
-        }
-    }
-    emit thicknessChanged(m_context.thickness);
+    updateThickness(thicknessOffset);
 }
 
 void CaptureWidget::resizeEvent(QResizeEvent* e)
@@ -1148,22 +1160,10 @@ void CaptureWidget::handleToolSignal(CaptureTool::Request r)
             }
             break;
         case CaptureTool::REQ_INCREASE_TOOL_SIZE:
-            // increase thickness
-            m_context.thickness = qBound(1, m_context.thickness + 1, 100);
-
-            // show notifier circle
-            m_notifierBox->showMessage(QString::number(m_context.thickness));
-
-            emit thicknessChanged(m_context.thickness);
+            updateThickness(1);
             break;
         case CaptureTool::REQ_DECREASE_TOOL_SIZE:
-            // decrease thickness
-            m_context.thickness = qBound(1, m_context.thickness - 1, 100);
-
-            // show notifier circle
-            m_notifierBox->showMessage(QString::number(m_context.thickness));
-
-            emit thicknessChanged(m_context.thickness);
+            updateThickness(-1);
             break;
         default:
             break;

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

@@ -127,6 +127,7 @@ private:
     void repositionSelection(QRect r);
     void adjustSelection(QMargins m);
     void moveSelection(QPoint p);
+    void updateThickness(int thicknessOffset);
 
     QRect extendedSelection() const;
     QRect extendedRect(const QRect& r) const;

+ 5 - 0
src/widgets/capture/notifierbox.cpp

@@ -57,3 +57,8 @@ void NotifierBox::showColor(const QColor& color)
     Q_UNUSED(color)
     m_message = QLatin1String("");
 }
+
+void NotifierBox::hideEvent(QHideEvent* event)
+{
+    emit hidden();
+}

+ 5 - 0
src/widgets/capture/notifierbox.h

@@ -17,6 +17,9 @@ protected:
     virtual void enterEvent(QEvent*);
     virtual void paintEvent(QPaintEvent*);
 
+signals:
+    void hidden();
+
 public slots:
     void showMessage(const QString& msg);
     void showColor(const QColor& color);
@@ -26,4 +29,6 @@ private:
     QString m_message;
     QColor m_bgColor;
     QColor m_foregroundColor;
+
+    void hideEvent(QHideEvent* event) override;
 };