Skip to content

Commit 7236570

Browse files
authored
Optionally confirm to quit after pressing Escape (flameshot-org#3758)
* config: add `showQuitPrompt` option Signed-off-by: y5c4l3 <[email protected]> * capturewidget: optionally show prompt on quit Signed-off-by: y5c4l3 <[email protected]> * capturewidget: apply theme in quit prompt Signed-off-by: y5c4l3 <[email protected]> --------- Signed-off-by: y5c4l3 <[email protected]>
1 parent 7eb5627 commit 7236570

File tree

6 files changed

+67
-1
lines changed

6 files changed

+67
-1
lines changed

src/config/generalconf.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ GeneralConf::GeneralConf(QWidget* parent)
4242
initCheckForUpdates();
4343
#endif
4444
initShowStartupLaunchMessage();
45+
initShowQuitPrompt();
4546
initAllowMultipleGuiInstances();
4647
initSaveLastRegion();
4748
initShowHelp();
@@ -101,6 +102,7 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath)
101102
m_predefinedColorPaletteLarge->setChecked(
102103
config.predefinedColorPaletteLarge());
103104
m_showStartupLaunchMessage->setChecked(config.showStartupLaunchMessage());
105+
m_showQuitPrompt->setChecked(config.showQuitPrompt());
104106
m_screenshotPathFixedCheck->setChecked(config.savePathFixed());
105107
m_uploadHistoryMax->setValue(config.uploadHistoryMax());
106108
m_undoLimit->setValue(config.undoLimit());
@@ -414,6 +416,19 @@ void GeneralConf::initShowStartupLaunchMessage()
414416
});
415417
}
416418

419+
void GeneralConf::initShowQuitPrompt()
420+
{
421+
m_showQuitPrompt = new QCheckBox(tr("Ask before quit capture"), this);
422+
ConfigHandler config;
423+
m_showQuitPrompt->setToolTip(
424+
tr("Show the confirmation prompt before ESC quit"));
425+
m_scrollAreaLayout->addWidget(m_showQuitPrompt);
426+
427+
connect(m_showQuitPrompt, &QCheckBox::clicked, [](bool checked) {
428+
ConfigHandler().setShowQuitPrompt(checked);
429+
});
430+
}
431+
417432
void GeneralConf::initPredefinedColorPaletteLarge()
418433
{
419434
m_predefinedColorPaletteLarge =

src/config/generalconf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private slots:
8080
void initShowDesktopNotification();
8181
void initShowHelp();
8282
void initShowMagnifier();
83+
void initShowQuitPrompt();
8384
void initShowSidePanelButton();
8485
void initShowStartupLaunchMessage();
8586
void initShowTrayIcon();
@@ -110,6 +111,7 @@ private slots:
110111
QCheckBox* m_autoCloseIdleDaemon;
111112
QCheckBox* m_autostart;
112113
QCheckBox* m_showStartupLaunchMessage;
114+
QCheckBox* m_showQuitPrompt;
113115
QCheckBox* m_copyURLAfterUpload;
114116
QCheckBox* m_copyPathAfterSave;
115117
QCheckBox* m_antialiasingPinZoom;

src/utils/confighandler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
9191
#endif
9292
OPTION("startupLaunch" ,Bool ( false )),
9393
OPTION("showStartupLaunchMessage" ,Bool ( true )),
94+
OPTION("showQuitPrompt" ,Bool ( false )),
9495
OPTION("copyURLAfterUpload" ,Bool ( true )),
9596
OPTION("copyPathAfterSave" ,Bool ( false )),
9697
OPTION("antialiasingPinZoom" ,Bool ( true )),

src/utils/confighandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class ConfigHandler : public QObject
102102
CONFIG_GETTER_SETTER(showStartupLaunchMessage,
103103
setShowStartupLaunchMessage,
104104
bool)
105+
CONFIG_GETTER_SETTER(showQuitPrompt, setShowQuitPrompt, bool)
105106
CONFIG_GETTER_SETTER(contrastOpacity, setContrastOpacity, int)
106107
CONFIG_GETTER_SETTER(copyURLAfterUpload, setCopyURLAfterUpload, bool)
107108
CONFIG_GETTER_SETTER(historyConfirmationToDelete,

src/widgets/capture/capturewidget.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
#include "src/widgets/panel/sidepanelwidget.h"
3131
#include "src/widgets/panel/utilitypanel.h"
3232
#include <QApplication>
33+
#include <QCheckBox>
3334
#include <QDateTime>
3435
#include <QDebug>
3536
#include <QDesktopWidget>
3637
#include <QFontMetrics>
3738
#include <QLabel>
39+
#include <QMessageBox>
3840
#include <QPaintEvent>
3941
#include <QPainter>
4042
#include <QScreen>
@@ -256,6 +258,8 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req,
256258
OverlayMessage::push(m_helpMessage);
257259
}
258260

261+
initQuitPrompt();
262+
259263
updateCursor();
260264
}
261265

@@ -465,6 +469,38 @@ bool CaptureWidget::commitCurrentTool()
465469
return false;
466470
}
467471

472+
void CaptureWidget::initQuitPrompt()
473+
{
474+
m_quitPrompt = new QMessageBox;
475+
makeChild(m_quitPrompt);
476+
m_quitPrompt->hide();
477+
478+
QString baseSheet = "QDialog { background-color: %1; }"
479+
"QLabel, QCheckBox { color: %2 }"
480+
"QPushButton { background-color: %1; color: %2 }";
481+
QColor text = ColorUtils::colorIsDark(m_uiColor) ? Qt::white : Qt::black;
482+
QString styleSheet = baseSheet.arg(m_uiColor.name()).arg(text.name());
483+
484+
m_quitPrompt->setStyleSheet(styleSheet);
485+
m_quitPrompt->setWindowTitle(tr("Quit Capture"));
486+
m_quitPrompt->setText(tr("Are you sure you want to quit capture?"));
487+
m_quitPrompt->setIcon(QMessageBox::Icon::Question);
488+
m_quitPrompt->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
489+
m_quitPrompt->setDefaultButton(QMessageBox::No);
490+
491+
auto* check = new QCheckBox(tr("Do not show this again"));
492+
m_quitPrompt->setCheckBox(check);
493+
494+
QObject::connect(check, &QCheckBox::clicked, [](bool checked) {
495+
ConfigHandler().setShowQuitPrompt(!checked);
496+
});
497+
}
498+
499+
bool CaptureWidget::promptQuit()
500+
{
501+
return m_quitPrompt->exec() == QMessageBox::Yes;
502+
}
503+
468504
void CaptureWidget::deleteToolWidgetOrClose()
469505
{
470506
if (m_activeButton != nullptr) {
@@ -484,7 +520,14 @@ void CaptureWidget::deleteToolWidgetOrClose()
484520
m_colorPicker->hide();
485521
} else {
486522
// close CaptureWidget
487-
close();
523+
if (m_config.showQuitPrompt()) {
524+
// need to show prompt
525+
if (m_quitPrompt->isHidden() && promptQuit()) {
526+
close();
527+
}
528+
} else {
529+
close();
530+
}
488531
}
489532
}
490533

src/widgets/capture/capturewidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "src/utils/confighandler.h"
2121
#include "src/widgets/capture/magnifierwidget.h"
2222
#include "src/widgets/capture/selectionwidget.h"
23+
#include <QMessageBox>
2324
#include <QPointer>
2425
#include <QTimer>
2526
#include <QUndoStack>
@@ -121,11 +122,13 @@ private slots:
121122
void initShortcuts();
122123
void initButtons();
123124
void initHelpMessage();
125+
void initQuitPrompt();
124126
void updateSizeIndicator();
125127
void updateCursor();
126128
void updateSelectionState();
127129
void updateTool(CaptureTool* tool);
128130
void updateLayersPanel();
131+
bool promptQuit();
129132
void pushToolToStack();
130133
void makeChild(QWidget* w);
131134
void restoreCircleCountState();
@@ -186,6 +189,7 @@ private slots:
186189
QPointer<CaptureTool> m_activeTool;
187190
bool m_activeToolIsMoved;
188191
QPointer<QWidget> m_toolWidget;
192+
QPointer<QMessageBox> m_quitPrompt;
189193

190194
ButtonHandler* m_buttonHandler;
191195
UtilityPanel* m_panel;

0 commit comments

Comments
 (0)