30
30
#include " src/widgets/panel/sidepanelwidget.h"
31
31
#include " src/widgets/panel/utilitypanel.h"
32
32
#include < QApplication>
33
+ #include < QCheckBox>
33
34
#include < QDateTime>
34
35
#include < QDebug>
35
36
#include < QDesktopWidget>
36
37
#include < QFontMetrics>
37
38
#include < QLabel>
39
+ #include < QMessageBox>
38
40
#include < QPaintEvent>
39
41
#include < QPainter>
40
42
#include < QScreen>
@@ -256,6 +258,8 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req,
256
258
OverlayMessage::push (m_helpMessage);
257
259
}
258
260
261
+ initQuitPrompt ();
262
+
259
263
updateCursor ();
260
264
}
261
265
@@ -465,6 +469,32 @@ bool CaptureWidget::commitCurrentTool()
465
469
return false ;
466
470
}
467
471
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
+
468
498
void CaptureWidget::deleteToolWidgetOrClose ()
469
499
{
470
500
if (m_activeButton != nullptr ) {
@@ -484,7 +514,14 @@ void CaptureWidget::deleteToolWidgetOrClose()
484
514
m_colorPicker->hide ();
485
515
} else {
486
516
// 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
+ }
488
525
}
489
526
}
490
527
0 commit comments