diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index ec436c05..162dcb29 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -69,6 +69,7 @@ CaptureWidget::CaptureWidget(uint id, , m_selection(nullptr) , m_existingObjectIsChanged(false) , m_startMove(false) + , m_thicknessByKeyboard(0) { m_undoStack.setUndoLimit(ConfigHandler().undoLimit()); @@ -193,6 +194,8 @@ CaptureWidget::CaptureWidget(uint id, connect(m_notifierBox, &NotifierBox::hidden, this, [this]() { // Show cursor if it was hidden while adjusting tool thickness updateCursor(); + m_thicknessByKeyboard = 0; + setDrawThickness(m_context.thickness); }); initPanel(); @@ -762,10 +765,9 @@ void CaptureWidget::moveSelection(QPoint p) adjustSelection(QMargins(-p.x(), -p.y(), p.x(), p.y())); } -void CaptureWidget::updateThickness(int thicknessOffset) +void CaptureWidget::updateThickness(int thickness) { - m_context.thickness += thicknessOffset; - m_context.thickness = qBound(1, m_context.thickness, 100); + m_context.thickness = qBound(1, thickness, 100); QPoint topLeft = QGuiAppCurrentScreen().currentScreen()->geometry().topLeft(); @@ -788,7 +790,6 @@ void CaptureWidget::updateThickness(int thicknessOffset) m_existingObjectIsChanged = true; } } - emit thicknessChanged(m_context.thickness); } @@ -814,6 +815,20 @@ void CaptureWidget::moveDown() void CaptureWidget::keyPressEvent(QKeyEvent* e) { + // If the key is a digit, change the thickness + bool ok; + int digit = e->text().toInt(&ok); + if (ok && e->modifiers() == Qt::NoModifier) { // digit received + m_thicknessByKeyboard = 10 * m_thicknessByKeyboard + digit; + updateThickness(m_thicknessByKeyboard); + if (m_context.thickness != m_thicknessByKeyboard) { + // The thickness was out of range and was clipped by updateThickness + m_thicknessByKeyboard = 0; + } + } else { + m_thicknessByKeyboard = 0; + } + if (!m_selection->isVisible()) { return; } else if (e->key() == Qt::Key_Control) { @@ -866,7 +881,7 @@ void CaptureWidget::wheelEvent(QWheelEvent* e) } } - updateThickness(thicknessOffset); + updateThickness(m_context.thickness + thicknessOffset); } void CaptureWidget::resizeEvent(QResizeEvent* e) @@ -1166,10 +1181,10 @@ void CaptureWidget::handleToolSignal(CaptureTool::Request r) } break; case CaptureTool::REQ_INCREASE_TOOL_SIZE: - updateThickness(1); + updateThickness(m_context.thickness + 1); break; case CaptureTool::REQ_DECREASE_TOOL_SIZE: - updateThickness(-1); + updateThickness(m_context.thickness - 1); break; default: break; diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h index bc5395c6..6eea5ee2 100644 --- a/src/widgets/capture/capturewidget.h +++ b/src/widgets/capture/capturewidget.h @@ -152,6 +152,7 @@ private: // Outside selection opacity int m_opacity; + int m_thicknessByKeyboard; // utility flags bool m_mouseIsClicked; diff --git a/src/widgets/capture/notifierbox.cpp b/src/widgets/capture/notifierbox.cpp index 1bf3f33a..e6b778d9 100644 --- a/src/widgets/capture/notifierbox.cpp +++ b/src/widgets/capture/notifierbox.cpp @@ -14,7 +14,7 @@ NotifierBox::NotifierBox(QWidget* parent) { m_timer = new QTimer(this); m_timer->setSingleShot(true); - m_timer->setInterval(1200); + m_timer->setInterval(600); connect(m_timer, &QTimer::timeout, this, &NotifierBox::hide); m_bgColor = ConfigHandler().uiMainColorValue(); m_foregroundColor = diff --git a/src/widgets/panel/sidepanelwidget.cpp b/src/widgets/panel/sidepanelwidget.cpp index b9e71edb..a1e55d8c 100644 --- a/src/widgets/panel/sidepanelwidget.cpp +++ b/src/widgets/panel/sidepanelwidget.cpp @@ -65,9 +65,9 @@ SidePanelWidget::SidePanelWidget(QPixmap* p, QWidget* parent) m_layout->addLayout(colorForm); connect(m_thicknessSlider, - &QSlider::valueChanged, + &QSlider::sliderMoved, this, - &SidePanelWidget::updateCurrentThickness); + &SidePanelWidget::thicknessChanged); connect(this, &SidePanelWidget::thicknessChanged, this, @@ -120,11 +120,6 @@ void SidePanelWidget::updateColorNoWheel(const QColor& c) QStringLiteral("QLabel { background-color : %1; }").arg(c.name())); } -void SidePanelWidget::updateCurrentThickness(int value) -{ - emit thicknessChanged(value); -} - void SidePanelWidget::colorGrabberActivated() { grabKeyboard(); diff --git a/src/widgets/panel/sidepanelwidget.h b/src/widgets/panel/sidepanelwidget.h index 806a4604..d726afe1 100644 --- a/src/widgets/panel/sidepanelwidget.h +++ b/src/widgets/panel/sidepanelwidget.h @@ -32,7 +32,6 @@ public slots: private slots: void updateColorNoWheel(const QColor& c); - void updateCurrentThickness(int value); private slots: void colorGrabberActivated();