mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-01 14:45:42 +08:00
refs #313 Register hotkey functions instead keyboard keys
This commit is contained in:
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#include "blacksound/soundgenerator.h"
|
#include "blacksound/soundgenerator.h"
|
||||||
#include "blackmisc/notificationsounds.h"
|
#include "blackmisc/notificationsounds.h"
|
||||||
|
#include "blackmisc/voiceroomlist.h"
|
||||||
|
#include "blackmisc/hotkeyfunction.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
@@ -27,14 +29,16 @@ namespace BlackCore
|
|||||||
* Init this context
|
* Init this context
|
||||||
*/
|
*/
|
||||||
CContextAudio::CContextAudio(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
|
CContextAudio::CContextAudio(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
|
||||||
IContextAudio(mode, runtime), m_voice(nullptr), m_keyboard(nullptr)
|
IContextAudio(mode, runtime), m_voice(nullptr), m_inputManager(nullptr)
|
||||||
{
|
{
|
||||||
// 1. Init by "voice driver"
|
// 1. Init by "voice driver"
|
||||||
this->m_voice = new CVoiceVatlib();
|
this->m_voice = new CVoiceVatlib();
|
||||||
m_voice->moveToThread(&m_threadVoice);
|
m_voice->moveToThread(&m_threadVoice);
|
||||||
m_threadVoice.start();
|
m_threadVoice.start();
|
||||||
|
|
||||||
m_keyboard = BlackInput::IKeyboard::getInstance();
|
// 2. Register PTT hotkey function
|
||||||
|
m_inputManager = CInputManager::getInstance();
|
||||||
|
m_handlePtt = m_inputManager->registerHotkeyFunc(CHotkeyFunction::Ptt(), m_voice, &CVoiceVatlib::handlePushToTalk);
|
||||||
|
|
||||||
// 3. own aircraft, if possible
|
// 3. own aircraft, if possible
|
||||||
//if (this->getIContextOwnAircraft()) m_voice->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
|
//if (this->getIContextOwnAircraft()) m_voice->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
|
||||||
@@ -366,28 +370,6 @@ namespace BlackCore
|
|||||||
m_voice->enableAudioLoopback(enable);
|
m_voice->enableAudioLoopback(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Settings changed
|
|
||||||
*/
|
|
||||||
void CContextAudio::ps_settingsChanged(uint typeValue)
|
|
||||||
{
|
|
||||||
if (this->getIContextOwnAircraft())
|
|
||||||
{
|
|
||||||
m_channelCom1->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
|
|
||||||
m_channelCom2->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
|
|
||||||
}
|
|
||||||
if (!this->getIContextSettings()) return;
|
|
||||||
IContextSettings::SettingsType type = static_cast<IContextSettings::SettingsType>(typeValue);
|
|
||||||
if (type == IContextSettings::SettingsHotKeys)
|
|
||||||
{
|
|
||||||
CKeyboardKeyList hotKeys = this->getIContextSettings()->getHotkeys();
|
|
||||||
Q_ASSERT(!hotKeys.isEmpty());
|
|
||||||
CKeyboardKey pttKey = hotKeys.findBy(&BlackMisc::Hardware::CKeyboardKey::getFunction, BlackMisc::Hardware::CKeyboardKey::HotkeyPtt).front();
|
|
||||||
m_keyboard->unregisterHotkey(m_handlePtt);
|
|
||||||
m_handlePtt = m_keyboard->registerHotkey(pttKey, m_voice, &CVoiceVatlib::handlePushToTalk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Connection status changed
|
* Connection status changed
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "dbus_server.h"
|
#include "dbus_server.h"
|
||||||
#include "voice_vatlib.h"
|
#include "voice_vatlib.h"
|
||||||
#include "voice_channel.h"
|
#include "voice_channel.h"
|
||||||
|
#include "input_manager.h"
|
||||||
#include "blackinput/keyboard.h"
|
#include "blackinput/keyboard.h"
|
||||||
#include "blackmisc/voiceroomlist.h"
|
#include "blackmisc/voiceroomlist.h"
|
||||||
|
|
||||||
@@ -117,8 +118,6 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Settings have been changed
|
|
||||||
void ps_settingsChanged(uint typeValue);
|
|
||||||
|
|
||||||
//! \copydoc IVoice::connectionStatusChanged
|
//! \copydoc IVoice::connectionStatusChanged
|
||||||
//! \sa IContextAudio::changedVoiceRooms
|
//! \sa IContextAudio::changedVoiceRooms
|
||||||
@@ -136,8 +135,8 @@ namespace BlackCore
|
|||||||
bool inTransitionState() const;
|
bool inTransitionState() const;
|
||||||
|
|
||||||
CVoiceVatlib *m_voice; //!< underlying voice lib
|
CVoiceVatlib *m_voice; //!< underlying voice lib
|
||||||
BlackInput::IKeyboard *m_keyboard;
|
CInputManager *m_inputManager;
|
||||||
BlackInput::IKeyboard::RegistrationHandle m_handlePtt;
|
CInputManager::RegistrationHandle m_handlePtt;
|
||||||
QThread m_threadVoice;
|
QThread m_threadVoice;
|
||||||
QPointer<IVoiceChannel> m_channelCom1;
|
QPointer<IVoiceChannel> m_channelCom1;
|
||||||
QPointer<IVoiceChannel> m_channelCom2;
|
QPointer<IVoiceChannel> m_channelCom2;
|
||||||
|
|||||||
@@ -79,8 +79,6 @@ void MainWindow::gracefulShutdown()
|
|||||||
if (!this->m_init) return;
|
if (!this->m_init) return;
|
||||||
this->m_init = false;
|
this->m_init = false;
|
||||||
|
|
||||||
if (this->m_keyboard) this->m_keyboard->unregisterAllHotkeys();
|
|
||||||
|
|
||||||
if (this->getIContextApplication())
|
if (this->getIContextApplication())
|
||||||
this->getIContextApplication()->notifyAboutComponentChange(IContextApplication::ComponentGui, IContextApplication::ActionStops);
|
this->getIContextApplication()->notifyAboutComponentChange(IContextApplication::ComponentGui, IContextApplication::ActionStops);
|
||||||
|
|
||||||
@@ -333,7 +331,7 @@ void MainWindow::displayRedirectedOutput(const CStatusMessage &statusMessage, qi
|
|||||||
void MainWindow::ps_onChangedSetttings(uint typeValue)
|
void MainWindow::ps_onChangedSetttings(uint typeValue)
|
||||||
{
|
{
|
||||||
IContextSettings::SettingsType type = static_cast<IContextSettings::SettingsType>(typeValue);
|
IContextSettings::SettingsType type = static_cast<IContextSettings::SettingsType>(typeValue);
|
||||||
if (type == IContextSettings::SettingsHotKeys) this->ps_registerHotkeys();
|
if (type == IContextSettings::SettingsHotKeys) this->ps_registerHotkeyFunctions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -521,31 +519,26 @@ void MainWindow::ps_toogleWindowStayOnTop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hotkeys
|
* Hotkey functions
|
||||||
*/
|
*/
|
||||||
void MainWindow::ps_registerHotkeys()
|
void MainWindow::ps_registerHotkeyFunctions()
|
||||||
{
|
{
|
||||||
if (!this->getIContextSettings()) qFatal("Missing settings");
|
CInputManager *m_inputManager = BlackCore::CInputManager::getInstance();
|
||||||
if (!this->m_keyboard)
|
|
||||||
|
m_inputManager->registerHotkeyFunc(CHotkeyFunction::Opacity50(), this, [ this ](bool isPressed)
|
||||||
{
|
{
|
||||||
this->m_keyboard = BlackInput::IKeyboard::getInstance();
|
if (isPressed) this->changeWindowOpacity(50);
|
||||||
}
|
});
|
||||||
else
|
|
||||||
|
m_inputManager->registerHotkeyFunc(CHotkeyFunction::Opacity100(), this, [ this ](bool isPressed)
|
||||||
{
|
{
|
||||||
this->m_keyboard->unregisterAllHotkeys();
|
if (isPressed) this->changeWindowOpacity(100);
|
||||||
}
|
});
|
||||||
|
|
||||||
CKeyboardKeyList keys = this->getIContextSettings()->getHotkeys();
|
m_inputManager->registerHotkeyFunc(CHotkeyFunction::ToogleWindowsStayOnTop(), this, [ this ](bool isPressed)
|
||||||
if (keys.isEmpty()) return;
|
{
|
||||||
|
if (isPressed) this->toogleWindowStayOnTop();
|
||||||
CKeyboardKey key = keys.keyForFunction(CKeyboardKey::HotkeyOpacity50);
|
});
|
||||||
if (!key.isEmpty()) this->m_keyboard->registerHotkey(key, this, [ this ](bool isPressed) { if (isPressed) this->ps_changeWindowOpacity(50); });
|
|
||||||
|
|
||||||
key = keys.keyForFunction(CKeyboardKey::HotkeyOpacity100);
|
|
||||||
if (!key.isEmpty()) this->m_keyboard->registerHotkey(key, this, [ this ](bool isPressed) { if (isPressed) this->ps_changeWindowOpacity(100); });
|
|
||||||
|
|
||||||
key = keys.keyForFunction(CKeyboardKey::HotkeyToogleWindowsStayOnTop);
|
|
||||||
if (!key.isEmpty()) this->m_keyboard->registerHotkey(key, this, [ this ](bool isPressed) { if (isPressed) this->ps_toogleWindowStayOnTop(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -15,13 +15,13 @@
|
|||||||
#undef interface
|
#undef interface
|
||||||
|
|
||||||
#include "guimodeenums.h"
|
#include "guimodeenums.h"
|
||||||
#include "blackinput/keyboard.h"
|
|
||||||
#include "blackcore/context_audio.h"
|
#include "blackcore/context_audio.h"
|
||||||
#include "blackcore/context_network.h"
|
#include "blackcore/context_network.h"
|
||||||
#include "blackcore/context_settings.h"
|
#include "blackcore/context_settings.h"
|
||||||
#include "blackcore/context_application.h"
|
#include "blackcore/context_application.h"
|
||||||
#include "blackcore/context_simulator.h"
|
#include "blackcore/context_simulator.h"
|
||||||
#include "blackcore/context_runtime.h"
|
#include "blackcore/context_runtime.h"
|
||||||
|
#include "blackcore/input_manager.h"
|
||||||
#include "blackgui/components/runtimebasedcomponent.h"
|
#include "blackgui/components/runtimebasedcomponent.h"
|
||||||
#include "blackgui/components/infowindowcomponent.h"
|
#include "blackgui/components/infowindowcomponent.h"
|
||||||
#include "blackgui/transpondermodeselector.h"
|
#include "blackgui/transpondermodeselector.h"
|
||||||
@@ -240,8 +240,8 @@ private slots:
|
|||||||
//! Toogle Windows stay on top
|
//! Toogle Windows stay on top
|
||||||
void ps_toogleWindowStayOnTop();
|
void ps_toogleWindowStayOnTop();
|
||||||
|
|
||||||
//! Set the hotkeys
|
//! Set the hotkey functions
|
||||||
void ps_registerHotkeys();
|
void ps_registerHotkeyFunctions();
|
||||||
|
|
||||||
//! Style sheet has been changed
|
//! Style sheet has been changed
|
||||||
void ps_onStyleSheetsChanged();
|
void ps_onStyleSheetsChanged();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "blackmisc/icons.h"
|
#include "blackmisc/icons.h"
|
||||||
#include "blackmisc/avselcal.h"
|
#include "blackmisc/avselcal.h"
|
||||||
#include "blackmisc/project.h"
|
#include "blackmisc/project.h"
|
||||||
|
#include "blackmisc/hotkeyfunction.h"
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QSizeGrip>
|
#include <QSizeGrip>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
@@ -140,7 +141,7 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig)
|
|||||||
this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole(CProject::compiledInfo());
|
this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole(CProject::compiledInfo());
|
||||||
|
|
||||||
// hotkeys
|
// hotkeys
|
||||||
this->ps_registerHotkeys();
|
this->ps_registerHotkeyFunctions();
|
||||||
|
|
||||||
// update timers
|
// update timers
|
||||||
this->startUpdateTimers();
|
this->startUpdateTimers();
|
||||||
|
|||||||
Reference in New Issue
Block a user