From f2bb47e9261df4f060fcaec3c808ea6537a68eab Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 28 Oct 2014 09:06:16 +0100 Subject: hook up tray to build Issue: #64 --- facetracknoir/ui.cpp | 22 ++- facetracknoir/ui.h | 7 +- opentrack/keyboard.ui | 335 +++++++++++++++++++++++--------------------- opentrack/main-settings.hpp | 2 +- opentrack/shortcuts.cpp | 2 + opentrack/shortcuts.h | 7 +- 6 files changed, 210 insertions(+), 165 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(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); +} diff --git a/facetracknoir/ui.h b/facetracknoir/ui.h index 9419936f..4158e29e 100644 --- a/facetracknoir/ui.h +++ b/facetracknoir/ui.h @@ -44,7 +44,7 @@ # include #endif -#include "ui_facetracknoir.h" +#include "ui_main.h" #include "opentrack/options.hpp" #include "opentrack/main-settings.hpp" @@ -85,13 +85,14 @@ class MainWindow : public QMainWindow, private State return modules.filters().value(ui.iconcomboFilter->currentIndex(), nullptr); } + void changeEvent(QEvent* e) override; + void createIconGroupBox(); void load_settings(); void updateButtonState(bool running, bool inertialp); void fill_profile_combobox(); void display_pose(const double* mapped, const double* raw); void ensure_tray(); - public slots: void shortcutRecentered(); void shortcutToggled(); @@ -112,6 +113,8 @@ private slots: void startTracker(); void stopTracker(); + + void restore_from_tray(QSystemTrayIcon::ActivationReason); public: MainWindow(); ~MainWindow(); diff --git a/opentrack/keyboard.ui b/opentrack/keyboard.ui index f576d8fb..321992e2 100644 --- a/opentrack/keyboard.ui +++ b/opentrack/keyboard.ui @@ -7,7 +7,7 @@ 0 0 415 - 143 + 332 @@ -29,175 +29,194 @@ false - - - - - - 0 - 0 - - - - Toggle - - - false - - - - - - - - 0 - 0 - - - - Center - - - false - + + + + + QFrame::StyledPanel + + + QFrame::Plain + + + + + + + 0 + 0 + + + + Keyboard + + + Qt::AlignCenter + + + false + + + + + + + + 0 + 0 + + + + Center + + + false + + + + + + + + 50 + 16777215 + + + + Shift + + + + + + + + 50 + 16777215 + + + + Ctrl + + + + + + + + 50 + 16777215 + + + + Alt + + + + + + + + 90 + 0 + + + + Select Number + + + QComboBox::InsertAlphabetically + + + + + + + + 0 + 0 + + + + Toggle + + + false + + + + + + + + 50 + 16777215 + + + + Shift + + + + + + + + 50 + 16777215 + + + + Ctrl + + + + + + + + 50 + 16777215 + + + + Alt + + + + + + + + 90 + 0 + + + + Select Number + + + QComboBox::InsertAlphabetically + + + + - - - - - 50 - 16777215 - - + + - Shift + Start in tray, minimize to tray - - - - - 90 - 0 - - - - Select Number - - - QComboBox::InsertAlphabetically - - - - - - - - 50 - 16777215 - - - - Alt - - - - - - - - 50 - 16777215 - - - - Ctrl - - - - - - - - 0 - 0 - - - - Keyboard - - - Qt::AlignCenter - - - false - - - - - - - - 50 - 16777215 - - - - Alt - - - - + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - 50 - 16777215 - - - - Ctrl - - - - - - - - 50 - 16777215 - - - - Shift - - - - - - - - 90 - 0 - - - - Select Number - - - QComboBox::InsertAlphabetically - - - diff --git a/opentrack/main-settings.hpp b/opentrack/main-settings.hpp index 83ec8968..4f1eff31 100644 --- a/opentrack/main-settings.hpp +++ b/opentrack/main-settings.hpp @@ -42,6 +42,6 @@ struct main_settings { a_roll(b, "roll", Roll), tcomp_p(b, "compensate-translation", true), tcomp_tz(b, "compensate-translation-disable-z-axis", false), - tray_enabled(false, "use-system-tray", true) + tray_enabled(b, "use-system-tray", false) {} }; diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index 851c5826..75b86a29 100644 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -21,6 +21,8 @@ KeyboardShortcutDialog::KeyboardShortcutDialog() tie_setting(s.toggle.alt, ui.chkToggleAlt); tie_setting(s.toggle.shift, ui.chkToggleShift); tie_setting(s.toggle.ctrl, ui.chkToggleCtrl); + + tie_setting(s.s_main.tray_enabled, ui.trayp); } void KeyboardShortcutDialog::doOK() { diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h index 298907c7..523bc7b2 100644 --- a/opentrack/shortcuts.h +++ b/opentrack/shortcuts.h @@ -10,7 +10,8 @@ #include "qxt-mini/QxtGlobalShortcut" #include "opentrack/plugin-support.h" #include "opentrack/options.hpp" -#include "ui_ftnoir_keyboardshortcuts.h" +#include "opentrack/main-settings.hpp" +#include "ui_keyboard.h" using namespace options; @@ -95,10 +96,12 @@ struct Shortcuts { struct settings { pbundle b; key_opts center, toggle; + main_settings s_main; settings() : b(bundle("keyboard-shortcuts")), center(b, "center"), - toggle(b, "toggle") + toggle(b, "toggle"), + s_main(bundle("opentrack-ui")) {} } s; -- cgit v1.2.3