feat: use spacebar to quit app

This commit is contained in:
Gary Wang 2019-11-03 17:15:50 +08:00
parent fb9207cb71
commit 568c50deff
2 changed files with 14 additions and 3 deletions

View File

@ -14,6 +14,7 @@
#include <QStyle> #include <QStyle>
#include <QScreen> #include <QScreen>
#include <QMenu> #include <QMenu>
#include <QShortcut>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -101,6 +102,10 @@ MainWindow::MainWindow(QWidget *parent) :
m_gv->setOpacity(0, false); m_gv->setOpacity(0, false);
m_closeButton->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(); centerWindow();
} }
@ -202,9 +207,7 @@ void MainWindow::mouseReleaseEvent(QMouseEvent *event)
void MainWindow::mouseDoubleClickEvent(QMouseEvent *event) void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
{ {
if (!m_protectedMode) { quitAppAction();
closeWindow();
}
return QMainWindow::mouseDoubleClickEvent(event); return QMainWindow::mouseDoubleClickEvent(event);
} }
@ -395,3 +398,10 @@ bool MainWindow::stayOnTop()
{ {
return windowFlags().testFlag(Qt::WindowStaysOnTopHint); return windowFlags().testFlag(Qt::WindowStaysOnTopHint);
} }
void MainWindow::quitAppAction(bool force)
{
if (!m_protectedMode || force) {
closeWindow();
}
}

View File

@ -46,6 +46,7 @@ protected slots:
void toggleProtectedMode(); void toggleProtectedMode();
void toggleStayOnTop(); void toggleStayOnTop();
bool stayOnTop(); bool stayOnTop();
void quitAppAction(bool force = false);
private: private:
QPoint m_oldMousePos; QPoint m_oldMousePos;