diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2014-10-28 09:06:16 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2014-10-28 09:11:15 +0100 |
commit | f2bb47e9261df4f060fcaec3c808ea6537a68eab (patch) | |
tree | 22564a695bf512daacfde1f885b5fde03a6e89a6 /facetracknoir/ui.cpp | |
parent | 1abdbee5bfa16df9ca8f0e7a9462503e86d672dd (diff) |
hook up tray to build
Issue: #64
Diffstat (limited to 'facetracknoir/ui.cpp')
-rw-r--r-- | facetracknoir/ui.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp index edd3a818..44eff98e 100644 --- a/facetracknoir/ui.cpp +++ b/facetracknoir/ui.cpp @@ -81,11 +81,13 @@ MainWindow::MainWindow() : ensure_tray(); if (s.tray_enabled) - hide(); + setWindowState(Qt::WindowMinimized); } MainWindow::~MainWindow() { + if (tray) + tray->hide(); stopTracker(); save(); _exit(0); @@ -413,12 +415,28 @@ void MainWindow::shortcutToggled() void MainWindow::ensure_tray() { + if (tray) + tray->hide(); tray = nullptr; if (s.tray_enabled) { tray = std::make_shared<QSystemTrayIcon>(this); tray->setIcon(QIcon(":/images/facetracknoir.png")); tray->show(); - connect(tray.get(), SIGNAL(activated()), this, SLOT(show())); + connect(tray.get(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + this, SLOT(restore_from_tray(QSystemTrayIcon::ActivationReason))); } } + +void MainWindow::restore_from_tray(QSystemTrayIcon::ActivationReason) +{ + show(); + setWindowState(Qt::WindowNoState); +} + +void MainWindow::changeEvent(QEvent* e) +{ + if (e->type() == QEvent::WindowStateChange && (windowState() & Qt::WindowMinimized)) + hide(); + QMainWindow::changeEvent(e); +} |