Skip to content

Commit

Permalink
capturewidget: optionally show prompt on quit
Browse files Browse the repository at this point in the history
Signed-off-by: y5c4l3 <[email protected]>
  • Loading branch information
y5c4l3 committed Oct 19, 2024
1 parent cfb7d28 commit f278d1f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
39 changes: 38 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,32 @@ bool CaptureWidget::commitCurrentTool()
return false;
}

void CaptureWidget::initQuitPrompt()
{
m_quitPrompt = new QMessageBox;
m_quitPrompt->setStyleSheet("QDialog { background: #aaa; }");
makeChild(m_quitPrompt);
m_quitPrompt->setStyle(style());
m_quitPrompt->hide();
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 +514,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

0 comments on commit f278d1f

Please sign in to comment.