From 94b27f5b6acd815f8ca6f7b92ea31b381f2ae7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20J=C3=BCrgens?= Date: Fri, 23 Jun 2023 17:48:33 +0200 Subject: [PATCH] implement ctrl+q keybind --- src/mainwindow.cpp | 22 ++++++++++++++++------ src/mainwindow.h | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 98623cf..94f1398 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,8 @@ MainWindow::MainWindow(bool useNotifySend, QWidget *parent) setCentralWidget(m_centralWidget); setupTrayIcon(); setMinimumSize(800, 300); + connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this), + &QShortcut::activated, this, &MainWindow::toggleOrCloseWindow); if (m_settings->contains("geometry")) { restoreGeometry(m_settings->value("geometry").toByteArray()); } else { @@ -79,12 +82,7 @@ void MainWindow::setupTrayIcon() { connect(m_trayIcon, &QSystemTrayIcon::activated, [this](auto reason) { if (reason == QSystemTrayIcon::Trigger) { - if (isVisible()) { - hide(); - } else { - show(); - activateWindow(); - } + toggleOrCloseWindow(); } }); } @@ -131,3 +129,15 @@ MainWindow *MainWindow::instance() { return m_instance; } CentralWidget *MainWindow::centralWidget() { return instance()->m_centralWidget; }; + +void MainWindow::toggleOrCloseWindow() { + if (isVisible()) { + if (m_trayIcon == nullptr) + QApplication::quit(); + else + hide(); + } else { + show(); + activateWindow(); + } +} diff --git a/src/mainwindow.h b/src/mainwindow.h index d85c249..b8822a8 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -36,4 +36,5 @@ private: public Q_SLOTS: void setTrayIcon(bool enabled); void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest); + void toggleOrCloseWindow(); };