From dba5a9bcf89a0a8e050ce50e8400856ed6ce0bd5 Mon Sep 17 00:00:00 2001 From: Keshav Bhatt Date: Thu, 16 Jun 2022 16:25:19 +0530 Subject: chore: use Ctrl+W to hide window to tray - replace Ctrl+H with Ctrl+W to hide window to tray - fix the minimize behavior --- src/mainwindow.cpp | 17 +++++++++-------- src/settingswidget.cpp | 8 ++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 913ca0d..8b00d80 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -511,24 +512,26 @@ void MainWindow::notify(QString title, QString message) { void MainWindow::createActions() { openUrlAction = new QAction("New Chat", this); - this->addAction(openUrlAction); openUrlAction->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key_N)); connect(openUrlAction, &QAction::triggered, this, &MainWindow::newChat); + addAction(openUrlAction); fullscreenAction = new QAction(tr("Fullscreen"), this); fullscreenAction->setShortcut(Qt::Key_F11); connect(fullscreenAction, &QAction::triggered, fullscreenAction, [=]() { setWindowState(windowState() ^ Qt::WindowFullScreen); }); - this->addAction(fullscreenAction); + addAction(fullscreenAction); minimizeAction = new QAction(tr("Mi&nimize to tray"), this); - minimizeAction->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key_H)); - connect(minimizeAction, &QAction::triggered, this, &QWidget::hide); + connect(minimizeAction, &QAction::triggered, this, &QMainWindow::hide); addAction(minimizeAction); - this->addAction(minimizeAction); + + QShortcut *minimizeShortcut = new QShortcut( + QKeySequence(Qt::Modifier::CTRL + Qt::Key_W), this, SLOT(hide())); + minimizeShortcut->setAutoRepeat(false); restoreAction = new QAction(tr("&Restore"), this); - connect(restoreAction, &QAction::triggered, this, &QWidget::show); + connect(restoreAction, &QAction::triggered, this, &QMainWindow::show); addAction(restoreAction); reloadAction = new QAction(tr("Re&load"), this); @@ -540,7 +543,6 @@ void MainWindow::createActions() { lockAction->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key_L)); connect(lockAction, &QAction::triggered, this, &MainWindow::lockApp); addAction(lockAction); - this->addAction(lockAction); settingsAction = new QAction(tr("&Settings"), this); connect(settingsAction, &QAction::triggered, this, &MainWindow::showSettings); @@ -552,7 +554,6 @@ void MainWindow::createActions() { quitAction->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key_Q)); connect(quitAction, &QAction::triggered, this, &MainWindow::quitApp); addAction(quitAction); - this->addAction(quitAction); } void MainWindow::quitApp() { diff --git a/src/settingswidget.cpp b/src/settingswidget.cpp index fcc348d..8e61b38 100644 --- a/src/settingswidget.cpp +++ b/src/settingswidget.cpp @@ -486,6 +486,14 @@ void SettingsWidget::on_showShortcutsButton_clicked() { label->setAlignment(Qt::AlignHCenter); layout->addWidget(label); } + // handle special case for minimize to try action + if (action->text().contains("minimize", Qt::CaseInsensitive) || + action->text().contains("Mi&nimize to tray")) { + QLabel *label = new QLabel( + action->text().remove("&") + " | " + "Ctrl+W", sheet); + label->setAlignment(Qt::AlignHCenter); + layout->addWidget(label); + } } } sheet->setAttribute(Qt::WA_DeleteOnClose); -- cgit v1.2.3