From cfb7d28785249a28390379071db874d07032bbf6 Mon Sep 17 00:00:00 2001 From: y5c4l3 Date: Sat, 19 Oct 2024 16:21:57 +0800 Subject: [PATCH 1/2] config: add `showQuitPrompt` option Signed-off-by: y5c4l3 --- src/config/generalconf.cpp | 15 +++++++++++++++ src/config/generalconf.h | 2 ++ src/utils/confighandler.cpp | 1 + src/utils/confighandler.h | 1 + 4 files changed, 19 insertions(+) diff --git a/src/config/generalconf.cpp b/src/config/generalconf.cpp index 8c8024def7..b8af50e453 100644 --- a/src/config/generalconf.cpp +++ b/src/config/generalconf.cpp @@ -42,6 +42,7 @@ GeneralConf::GeneralConf(QWidget* parent) initCheckForUpdates(); #endif initShowStartupLaunchMessage(); + initShowQuitPrompt(); initAllowMultipleGuiInstances(); initSaveLastRegion(); initShowHelp(); @@ -101,6 +102,7 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath) m_predefinedColorPaletteLarge->setChecked( config.predefinedColorPaletteLarge()); m_showStartupLaunchMessage->setChecked(config.showStartupLaunchMessage()); + m_showQuitPrompt->setChecked(config.showQuitPrompt()); m_screenshotPathFixedCheck->setChecked(config.savePathFixed()); m_uploadHistoryMax->setValue(config.uploadHistoryMax()); m_undoLimit->setValue(config.undoLimit()); @@ -414,6 +416,19 @@ void GeneralConf::initShowStartupLaunchMessage() }); } +void GeneralConf::initShowQuitPrompt() +{ + m_showQuitPrompt = new QCheckBox(tr("Ask before quit capture"), this); + ConfigHandler config; + m_showQuitPrompt->setToolTip( + tr("Show the confirmation prompt before ESC quit")); + m_scrollAreaLayout->addWidget(m_showQuitPrompt); + + connect(m_showQuitPrompt, &QCheckBox::clicked, [](bool checked) { + ConfigHandler().setShowQuitPrompt(checked); + }); +} + void GeneralConf::initPredefinedColorPaletteLarge() { m_predefinedColorPaletteLarge = diff --git a/src/config/generalconf.h b/src/config/generalconf.h index e1f4979163..6b6b2f34e0 100644 --- a/src/config/generalconf.h +++ b/src/config/generalconf.h @@ -80,6 +80,7 @@ private slots: void initShowDesktopNotification(); void initShowHelp(); void initShowMagnifier(); + void initShowQuitPrompt(); void initShowSidePanelButton(); void initShowStartupLaunchMessage(); void initShowTrayIcon(); @@ -110,6 +111,7 @@ private slots: QCheckBox* m_autoCloseIdleDaemon; QCheckBox* m_autostart; QCheckBox* m_showStartupLaunchMessage; + QCheckBox* m_showQuitPrompt; QCheckBox* m_copyURLAfterUpload; QCheckBox* m_copyPathAfterSave; QCheckBox* m_antialiasingPinZoom; diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 485fb26575..3fbfef6783 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -91,6 +91,7 @@ static QMap> #endif OPTION("startupLaunch" ,Bool ( false )), OPTION("showStartupLaunchMessage" ,Bool ( true )), + OPTION("showQuitPrompt" ,Bool ( false )), OPTION("copyURLAfterUpload" ,Bool ( true )), OPTION("copyPathAfterSave" ,Bool ( false )), OPTION("antialiasingPinZoom" ,Bool ( true )), diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index f2eb4ad940..af33e221d0 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -102,6 +102,7 @@ class ConfigHandler : public QObject CONFIG_GETTER_SETTER(showStartupLaunchMessage, setShowStartupLaunchMessage, bool) + CONFIG_GETTER_SETTER(showQuitPrompt, setShowQuitPrompt, bool) CONFIG_GETTER_SETTER(contrastOpacity, setContrastOpacity, int) CONFIG_GETTER_SETTER(copyURLAfterUpload, setCopyURLAfterUpload, bool) CONFIG_GETTER_SETTER(historyConfirmationToDelete, From ed4b657c3e6419b4dc9442187c125e3263f82842 Mon Sep 17 00:00:00 2001 From: y5c4l3 Date: Sun, 20 Oct 2024 06:46:12 +0800 Subject: [PATCH 2/2] 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;