diff --git a/src/utils/configshortcuts.cpp b/src/utils/configshortcuts.cpp index 8bc28d56..61a0095d 100644 --- a/src/utils/configshortcuts.cpp +++ b/src/utils/configshortcuts.cpp @@ -51,6 +51,10 @@ const QVector& ConfigShortcuts::captureShortcutsDefault( m_shortcuts << (QStringList() << "TYPE_MOVE_DOWN" << QObject::tr("Move selection down 1px") << QKeySequence(Qt::Key_Down).toString()); + m_shortcuts << (QStringList() + << "TYPE_COMMIT_CURRENT_TOOL" + << QObject::tr("Commit text in text area") + << QKeySequence(Qt::CTRL + Qt::Key_Return).toString()); m_shortcuts << (QStringList() << "" << QObject::tr("Quit capture") << QKeySequence(Qt::Key_Escape).toString()); diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index fa553636..56dd49cf 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -235,6 +235,26 @@ QPixmap CaptureWidget::pixmap() return m_context.selectedScreenshotArea(); } +// Finish whatever the current tool is doing, if there is a current active +// tool. +bool CaptureWidget::commitCurrentTool() +{ + if (m_activeButton) { + if (m_activeTool) { + if (m_activeTool->isValid() && m_toolWidget) { + pushToolToStack(); + } else { + m_activeTool->deleteLater(); + } + if (m_toolWidget) { + m_toolWidget->deleteLater(); + return true; + } + } + } + return false; +} + void CaptureWidget::deleteToolwidgetOrClose() { if (m_panel->isVisible()) { @@ -335,16 +355,8 @@ void CaptureWidget::mousePressEvent(QMouseEvent* e) m_mouseIsClicked = true; // Click using a tool if (m_activeButton) { - if (m_activeTool) { - if (m_activeTool->isValid() && m_toolWidget) { - pushToolToStack(); - } else { - m_activeTool->deleteLater(); - } - if (m_toolWidget) { - m_toolWidget->deleteLater(); - return; - } + if (commitCurrentTool()) { + return; } m_activeTool = m_activeButton->tool()->copy(this); @@ -997,6 +1009,11 @@ void CaptureWidget::initShortcuts() this, SLOT(downMove())); + new QShortcut( + QKeySequence(ConfigHandler().shortcut("TYPE_COMMIT_CURRENT_TOOL")), + this, + SLOT(commitCurrentTool())); + new QShortcut(Qt::Key_Escape, this, SLOT(deleteToolwidgetOrClose())); } @@ -1145,4 +1162,4 @@ QRect CaptureWidget::extendedRect(QRect* r) const r->top() * devicePixelRatio, r->width() * devicePixelRatio, r->height() * devicePixelRatio); -} \ No newline at end of file +} diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h index 31975ede..7b83a214 100644 --- a/src/widgets/capture/capturewidget.h +++ b/src/widgets/capture/capturewidget.h @@ -60,6 +60,7 @@ public: QPixmap pixmap(); public slots: + bool commitCurrentTool(); void deleteToolwidgetOrClose(); signals: