diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index d6184dce..631086bd 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/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; diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h index 50760470..abe07fb7 100644 --- a/src/widgets/capture/capturewidget.h +++ b/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; diff --git a/src/widgets/capture/notifierbox.cpp b/src/widgets/capture/notifierbox.cpp index e13c8a4b..1bf3f33a 100644 --- a/src/widgets/capture/notifierbox.cpp +++ b/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(); +} diff --git a/src/widgets/capture/notifierbox.h b/src/widgets/capture/notifierbox.h index 66063be9..6d581954 100644 --- a/src/widgets/capture/notifierbox.h +++ b/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; };