From 568c50deff6de84bdee8de9749fcbc0a1d6b2a3d Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sun, 3 Nov 2019 17:15:50 +0800 Subject: [PATCH] feat: use spacebar to quit app --- mainwindow.cpp | 16 +++++++++++++--- mainwindow.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index cf84e33..360015c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -101,6 +102,10 @@ MainWindow::MainWindow(QWidget *parent) : m_gv->setOpacity(0, false); m_closeButton->setOpacity(0, false); + QShortcut * quitAppShorucut = new QShortcut(QKeySequence(Qt::Key_Space), this); + connect(quitAppShorucut, &QShortcut::activated, + std::bind(&MainWindow::quitAppAction, this, false)); + centerWindow(); } @@ -202,9 +207,7 @@ void MainWindow::mouseReleaseEvent(QMouseEvent *event) void MainWindow::mouseDoubleClickEvent(QMouseEvent *event) { - if (!m_protectedMode) { - closeWindow(); - } + quitAppAction(); return QMainWindow::mouseDoubleClickEvent(event); } @@ -395,3 +398,10 @@ bool MainWindow::stayOnTop() { return windowFlags().testFlag(Qt::WindowStaysOnTopHint); } + +void MainWindow::quitAppAction(bool force) +{ + if (!m_protectedMode || force) { + closeWindow(); + } +} diff --git a/mainwindow.h b/mainwindow.h index c4bab33..df182b9 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -46,6 +46,7 @@ protected slots: void toggleProtectedMode(); void toggleStayOnTop(); bool stayOnTop(); + void quitAppAction(bool force = false); private: QPoint m_oldMousePos;