Skip to content

Commit

Permalink
implement ctrl+q keybind
Browse files Browse the repository at this point in the history
  • Loading branch information
maltejur committed Jun 23, 2023
1 parent 8a6f49b commit 94b27f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QShortcut>
#include <QSpacerItem>
#include <QThread>
#include <QTimer>
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
}
});
}
Expand Down Expand Up @@ -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();
}
}
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ class MainWindow : public QMainWindow {
public Q_SLOTS:
void setTrayIcon(bool enabled);
void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
void toggleOrCloseWindow();
};

2 comments on commit 94b27f5

@Vitalii-code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this shortcut should be optional

@maltejur
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that? Does it interfere with another keybind on your PC?

Please sign in to comment.