Skip to content

Commit b6b36d9

Browse files
committed
Fix Quit Button if Tray is active (#353)
Modify the Quit button on the Main Window to be a Hide button if the Tray is active.
1 parent 494bbf1 commit b6b36d9

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/core/ui/mainwindow.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent),
4747
actOptions = new QAction(QIcon::fromTheme(QStringLiteral("configure")), tr("Options"), this);
4848
actAbout = new QAction(QIcon::fromTheme(QStringLiteral("help-about")), tr("About"), this);
4949
actQuit = new QAction(QIcon::fromTheme(QStringLiteral("application-exit")), tr("Quit"), this);
50+
actHideQuit = new QAction(QIcon::fromTheme(QStringLiteral("application-exit")), tr("QuitHide"), this);
5051

5152
// connect actions to slots
5253
Core *c = Core::instance();
@@ -67,9 +68,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent),
6768

6869
QWidget* spacer = new QWidget();
6970
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
70-
_ui->toolBar->addWidget(spacer);
71+
_ui->toolBar->addWidget(spacer);
7172

72-
_ui->toolBar->addAction(actQuit);
73+
_ui->toolBar->addAction(actHideQuit);
7374

7475
connect(_ui->delayBox, &QSpinBox::valueChanged, this, &MainWindow::delayBoxChange);
7576
connect(_ui->checkIncludeCursor, &QCheckBox::toggled, this, &MainWindow::checkIncludeCursor);
@@ -285,14 +286,14 @@ void MainWindow::show()
285286
{
286287
if (!isVisible() && !_trayed)
287288
showNormal();
288-
if (_trayIcon){
289+
if (_trayIcon) {
289290
if (_conf->getShowTrayIcon())
290291
{
291292
_trayIcon->blockSignals(false);
292293
_trayIcon->setContextMenu(_trayMenu);
293294
}
294295

295-
_trayIcon->setVisible(true);
296+
_trayIcon->setVisible(true);
296297
}
297298
QMainWindow::show();
298299
}
@@ -511,6 +512,17 @@ void MainWindow::updateUI()
511512
_ui->checkIncludeCursor->setChecked(_conf->getIncludeCursor());
512513

513514
updateShortcuts();
515+
Core* c = Core::instance();
516+
517+
if (_conf->getShowTrayIcon()) {
518+
disconnect(actHideQuit, &QAction::triggered, c, &Core::coreQuit);
519+
connect(actHideQuit, &QAction::triggered, this, &MainWindow::windowHideShow);
520+
actHideQuit->setText(tr("Hide"));
521+
} else {
522+
disconnect(actHideQuit, &QAction::triggered, this, &MainWindow::windowHideShow);
523+
connect(actHideQuit, &QAction::triggered, c, &Core::coreQuit);
524+
actHideQuit->setText(tr("Quit"));
525+
}
514526

515527
// create tray object, but not with the "-n" option
516528
if (!Core::instance()->noWin() && _conf->getShowTrayIcon() && !_trayIcon)

src/core/ui/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public Q_SLOTS:
7474
QAction *actOptions;
7575
QAction *actAbout;
7676
QAction *actQuit;
77+
QAction *actHideQuit;
7778
Config *_conf;
7879
QMenu *_trayMenu;
7980
bool _trayed;

0 commit comments

Comments
 (0)