From ed4b657c3e6419b4dc9442187c125e3263f82842 Mon Sep 17 00:00:00 2001 From: y5c4l3 Date: Sun, 20 Oct 2024 06:46:12 +0800 Subject: [PATCH] capturewidget: optionally show prompt on quit Signed-off-by: y5c4l3 --- src/widgets/capture/capturewidget.cpp | 38 ++++++++++++++++++++++++++- src/widgets/capture/capturewidget.h | 4 +++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 49ebff9720..2579d3a7a1 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -30,11 +30,13 @@ #include "src/widgets/panel/sidepanelwidget.h" #include "src/widgets/panel/utilitypanel.h" #include +#include #include #include #include #include #include +#include #include #include #include @@ -256,6 +258,8 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req, OverlayMessage::push(m_helpMessage); } + initQuitPrompt(); + updateCursor(); } @@ -465,6 +469,31 @@ bool CaptureWidget::commitCurrentTool() return false; } +void CaptureWidget::initQuitPrompt() +{ + m_quitPrompt = new QMessageBox; + makeChild(m_quitPrompt); + m_quitPrompt->hide(); + m_quitPrompt->setStyleSheet("QDialog { background: #aaa; }"); + m_quitPrompt->setWindowTitle(tr("Quit Capture")); + m_quitPrompt->setText(tr("Are you sure you want to quit capture?")); + m_quitPrompt->setIcon(QMessageBox::Icon::Question); + m_quitPrompt->setStandardButtons(QMessageBox::Yes | QMessageBox::No); + m_quitPrompt->setDefaultButton(QMessageBox::No); + + auto* check = new QCheckBox(tr("Do not show this again")); + m_quitPrompt->setCheckBox(check); + + QObject::connect(check, &QCheckBox::clicked, [](bool checked) { + ConfigHandler().setShowQuitPrompt(!checked); + }); +} + +bool CaptureWidget::promptQuit() +{ + return m_quitPrompt->exec() == QMessageBox::Yes; +} + void CaptureWidget::deleteToolWidgetOrClose() { if (m_activeButton != nullptr) { @@ -484,7 +513,14 @@ void CaptureWidget::deleteToolWidgetOrClose() m_colorPicker->hide(); } else { // close CaptureWidget - close(); + if (m_config.showQuitPrompt()) { + // need to show prompt + if (m_quitPrompt->isHidden() && promptQuit()) { + close(); + } + } else { + close(); + } } } diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h index 12087e8b4e..4602e30e47 100644 --- a/src/widgets/capture/capturewidget.h +++ b/src/widgets/capture/capturewidget.h @@ -20,6 +20,7 @@ #include "src/utils/confighandler.h" #include "src/widgets/capture/magnifierwidget.h" #include "src/widgets/capture/selectionwidget.h" +#include #include #include #include @@ -121,11 +122,13 @@ private slots: void initShortcuts(); void initButtons(); void initHelpMessage(); + void initQuitPrompt(); void updateSizeIndicator(); void updateCursor(); void updateSelectionState(); void updateTool(CaptureTool* tool); void updateLayersPanel(); + bool promptQuit(); void pushToolToStack(); void makeChild(QWidget* w); void restoreCircleCountState(); @@ -186,6 +189,7 @@ private slots: QPointer m_activeTool; bool m_activeToolIsMoved; QPointer m_toolWidget; + QPointer m_quitPrompt; ButtonHandler* m_buttonHandler; UtilityPanel* m_panel;