mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
refs #233, added hot key functionality in GUI. Now hot keys can be defined and show a reaction in the GUI
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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(); });
|
||||
|
||||
}
|
||||
|
||||
@@ -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<IContextSettings::SettingsType>(typeValue);
|
||||
this->reloadSettings();
|
||||
if (type == IContextSettings::SettingsHotKeys) this->setHotkeys();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user