Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally confirm to quit after pressing Escape #3758

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/config/generalconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ GeneralConf::GeneralConf(QWidget* parent)
initCheckForUpdates();
#endif
initShowStartupLaunchMessage();
initShowQuitPrompt();
initAllowMultipleGuiInstances();
initSaveLastRegion();
initShowHelp();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions src/config/generalconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private slots:
void initShowDesktopNotification();
void initShowHelp();
void initShowMagnifier();
void initShowQuitPrompt();
void initShowSidePanelButton();
void initShowStartupLaunchMessage();
void initShowTrayIcon();
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/utils/confighandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
#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 )),
Expand Down
1 change: 1 addition & 0 deletions src/utils/confighandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 37 additions & 1 deletion src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
#include "src/widgets/panel/sidepanelwidget.h"
#include "src/widgets/panel/utilitypanel.h"
#include <QApplication>
#include <QCheckBox>
#include <QDateTime>
#include <QDebug>
#include <QDesktopWidget>
#include <QFontMetrics>
#include <QLabel>
#include <QMessageBox>
#include <QPaintEvent>
#include <QPainter>
#include <QScreen>
Expand Down Expand Up @@ -256,6 +258,8 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req,
OverlayMessage::push(m_helpMessage);
}

initQuitPrompt();

updateCursor();
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/widgets/capture/capturewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "src/utils/confighandler.h"
#include "src/widgets/capture/magnifierwidget.h"
#include "src/widgets/capture/selectionwidget.h"
#include <QMessageBox>
#include <QPointer>
#include <QTimer>
#include <QUndoStack>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -186,6 +189,7 @@ private slots:
QPointer<CaptureTool> m_activeTool;
bool m_activeToolIsMoved;
QPointer<QWidget> m_toolWidget;
QPointer<QMessageBox> m_quitPrompt;

ButtonHandler* m_buttonHandler;
UtilityPanel* m_panel;
Expand Down