diff --git a/samples/blackgui/introwindow.cpp b/samples/blackgui/introwindow.cpp index a9b9ec6fe..6130bf623 100644 --- a/samples/blackgui/introwindow.cpp +++ b/samples/blackgui/introwindow.cpp @@ -11,7 +11,7 @@ * Constructor */ CIntroWindow::CIntroWindow(QWidget *parent) : - QDialog(parent, Qt::Tool), + QDialog(parent, (Qt::Tool | Qt::WindowStaysOnTopHint)), ui(new Ui::CIntroWindow) { ui->setupUi(this); diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index 2f26706f3..43cdaa693 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -22,7 +22,7 @@ using namespace BlackMisc::Audio; * Constructor */ MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) : - QMainWindow(parent, windowMode == GuiModes::WindowFrameless ? (Qt::Window | Qt::FramelessWindowHint) : Qt::Tool), + QMainWindow(parent, windowMode == GuiModes::WindowFrameless ? (Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) : (Qt::Tool | Qt::WindowStaysOnTopHint)), ui(new Ui::MainWindow), m_infoWindow(nullptr), m_init(false), m_windowMode(windowMode), m_audioTestRunning(NoAudioTest), @@ -38,7 +38,9 @@ MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) : // cockpit m_inputFocusedWidget(nullptr), // status bar - m_statusBarIcon(nullptr), m_statusBarLabel(nullptr) + m_statusBarIcon(nullptr), m_statusBarLabel(nullptr), + // keyboard /hotkeys + m_keyboard(nullptr) { if (windowMode == GuiModes::WindowFrameless) { @@ -62,6 +64,9 @@ void MainWindow::gracefulShutdown() { if (!this->m_init) return; this->m_init = false; + + if (this->m_keyboard) this->m_keyboard->unregisterAllHotkeys(); + if (this->getIContextApplication()) this->getIContextApplication()->notifyAboutComponentChange(IContextApplication::ComponentGui, IContextApplication::ActionStops); @@ -510,3 +515,25 @@ void MainWindow::simulatorConnectionChanged(bool isAvailable) else this->m_timerSimulator->stop(); } + +/* + * Stay on top + */ +void MainWindow::toogleWindowStayOnTop() +{ + Qt::WindowFlags flags = this->windowFlags(); + if (Qt::WindowStaysOnTopHint & flags) + { + flags ^= Qt::WindowStaysOnTopHint; + flags |= Qt::WindowStaysOnBottomHint; + this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeGui, CStatusMessage::SeverityInfo, "on bottom")); + } + else + { + flags ^= Qt::WindowStaysOnBottomHint; + flags |= Qt::WindowStaysOnTopHint; + this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeGui, CStatusMessage::SeverityInfo, "on top")); + } + this->setWindowFlags(flags); + this->show(); +} diff --git a/samples/blackgui/mainwindow.h b/samples/blackgui/mainwindow.h index 9ebb5d8ff..bbb1078c9 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -12,6 +12,7 @@ #include "infowindow.h" #include "guimodeenums.h" +#include "blackcore/keyboard.h" #include "blackcore/context_audio.h" #include "blackcore/context_network.h" #include "blackcore/context_settings.h" @@ -133,6 +134,9 @@ private: QLabel *m_statusBarIcon; /*!< status bar icon */ QLabel *m_statusBarLabel; /*!< status bar label */ + // Hotkeys + BlackCore::IKeyboard *m_keyboard; + //! GUI status update void updateGuiStatusInformation(); @@ -249,6 +253,9 @@ private: //! Update simulator page with latest user aircraft data void updateSimulatorData(); + //! Set the hotkeys + void setHotkeys(); + private slots: // @@ -409,6 +416,9 @@ private slots: //! Clear single hotkey void clearHotkey(); + //! Toogle Windows stay on top + void toogleWindowStayOnTop(); + }; #pragma pop_macro("interface") diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index 99f6a33a2..2852f37b2 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -22,6 +22,7 @@ using namespace BlackCore; using namespace BlackMisc; +using namespace BlackMisc::Hardware; using namespace BlackGui; @@ -159,6 +160,9 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) this->ui->te_StatusPageConsole->appendPlainText(CProject::systemNameAndVersion()); this->ui->te_StatusPageConsole->appendPlainText(CProject::compiledInfo()); + // hotkeys + this->setHotkeys(); + // do this as last statement, so it can be used as flag // whether init has been completed this->m_init = true; @@ -348,3 +352,29 @@ void MainWindow::stopAllTimers(bool disconnect) this->disconnect(this->m_timerAudioTests); this->disconnect(this->m_timerSimulator); } + +void MainWindow::setHotkeys() +{ + Q_ASSERT(this->getIContextSettings()); + if (!this->m_keyboard) + { + this->m_keyboard = BlackCore::IKeyboard::getInstance(); + } + else + { + this->m_keyboard->unregisterAllHotkeys(); + } + + CKeyboardKeyList keys = this->getIContextSettings()->getHotkeys(); + if (keys.isEmpty()) return; + + CKeyboardKey key = keys.keyForFunction(CKeyboardKey::HotkeyOpacity50); + if (!key.isEmpty()) this->m_keyboard->registerHotkey(key, this, [ this ](bool isPressed) { if (isPressed) this->changeWindowOpacity(50); }); + + key = keys.keyForFunction(CKeyboardKey::HotkeyOpacity100); + if (!key.isEmpty()) this->m_keyboard->registerHotkey(key, this, [ this ](bool isPressed) { if (isPressed) this->changeWindowOpacity(100); }); + + key = keys.keyForFunction(CKeyboardKey::HotkeyToogleWindowsStayOnTop); + if (!key.isEmpty()) this->m_keyboard->registerHotkey(key, this, [ this ](bool isPressed) { if (isPressed) this->toogleWindowStayOnTop(); }); + +} diff --git a/samples/blackgui/mainwindow_settings.cpp b/samples/blackgui/mainwindow_settings.cpp index e4f563c94..ac4228c17 100644 --- a/samples/blackgui/mainwindow_settings.cpp +++ b/samples/blackgui/mainwindow_settings.cpp @@ -29,6 +29,9 @@ void MainWindow::reloadSettings() // update hot keys this->ui->tvp_SettingsMiscHotkeys->update(this->getIContextSettings()->getHotkeys()); + + + // fake setting for sound notifications this->ui->cb_SettingsAudioPlayNotificationSounds->setChecked(true); this->ui->cb_SettingsAudioNotificationTextMessage->setChecked(true); @@ -81,8 +84,9 @@ void MainWindow::alterTrafficServer() */ void MainWindow::changedSettings(uint typeValue) { - Q_UNUSED(typeValue); + IContextSettings::SettingsType type = static_cast(typeValue); this->reloadSettings(); + if (type == IContextSettings::SettingsHotKeys) this->setHotkeys(); } /*