Skip to content

Commit 50cfcce

Browse files
committed
capturewidget: optionally show prompt on quit
Signed-off-by: y5c4l3 <[email protected]>
1 parent cfb7d28 commit 50cfcce

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/widgets/capture/capturewidget.cpp

+38-1
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,32 @@ bool CaptureWidget::commitCurrentTool()
465469
return false;
466470
}
467471

472+
void CaptureWidget::initQuitPrompt()
473+
{
474+
m_quitPrompt = new QMessageBox;
475+
m_quitPrompt->setStyleSheet("QDialog { background: #aaa; }");
476+
makeChild(m_quitPrompt);
477+
m_quitPrompt->setStyle(style());
478+
m_quitPrompt->hide();
479+
m_quitPrompt->setWindowTitle(tr("Quit Capture"));
480+
m_quitPrompt->setText(tr("Are you sure you want to quit capture?"));
481+
m_quitPrompt->setIcon(QMessageBox::Icon::Question);
482+
m_quitPrompt->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
483+
m_quitPrompt->setDefaultButton(QMessageBox::No);
484+
485+
auto* check = new QCheckBox(tr("Do not show this again"));
486+
m_quitPrompt->setCheckBox(check);
487+
488+
QObject::connect(check, &QCheckBox::clicked, [](bool checked) {
489+
ConfigHandler().setShowQuitPrompt(!checked);
490+
});
491+
}
492+
493+
bool CaptureWidget::promptQuit()
494+
{
495+
return m_quitPrompt->exec() == QMessageBox::Yes;
496+
}
497+
468498
void CaptureWidget::deleteToolWidgetOrClose()
469499
{
470500
if (m_activeButton != nullptr) {
@@ -484,7 +514,14 @@ void CaptureWidget::deleteToolWidgetOrClose()
484514
m_colorPicker->hide();
485515
} else {
486516
// close CaptureWidget
487-
close();
517+
if (m_config.showQuitPrompt()) {
518+
// need to show prompt
519+
if (m_quitPrompt->isHidden() && promptQuit()) {
520+
close();
521+
}
522+
} else {
523+
close();
524+
}
488525
}
489526
}
490527

src/widgets/capture/capturewidget.h

+4
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)