From 6c6bcb4e086cbeabd6167f8aaf23ad691a946351 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 25 Jun 2014 19:23:31 +0200 Subject: [PATCH] refs #273, encapsulated settings GUI into own component This removed a considerable amount of code from mainwindow --- samples/blackgui/mainwindow.cpp | 55 +- samples/blackgui/mainwindow.h | 68 +- samples/blackgui/mainwindow.ui | 771 +---------------------- samples/blackgui/mainwindow_init.cpp | 75 +-- samples/blackgui/mainwindow_menus.cpp | 2 +- samples/blackgui/mainwindow_settings.cpp | 151 ----- samples/blackgui/mainwindow_voice.cpp | 146 +---- src/blackgui/settingscomponent.cpp | 405 ++++++++++++ src/blackgui/settingscomponent.h | 130 ++++ src/blackgui/settingscomponent.ui | 754 ++++++++++++++++++++++ 10 files changed, 1363 insertions(+), 1194 deletions(-) delete mode 100644 samples/blackgui/mainwindow_settings.cpp create mode 100644 src/blackgui/settingscomponent.cpp create mode 100644 src/blackgui/settingscomponent.h create mode 100644 src/blackgui/settingscomponent.ui diff --git a/samples/blackgui/mainwindow.cpp b/samples/blackgui/mainwindow.cpp index 94040f748..c465fa968 100644 --- a/samples/blackgui/mainwindow.cpp +++ b/samples/blackgui/mainwindow.cpp @@ -17,6 +17,7 @@ using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Geo; using namespace BlackMisc::Settings; using namespace BlackMisc::Audio; +using namespace BlackMisc::Hardware; /* * Constructor @@ -25,21 +26,19 @@ MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) : QMainWindow(parent, windowMode == GuiModes::WindowFrameless ? (Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) : (Qt::Tool | Qt::WindowStaysOnTopHint)), ui(new Ui::MainWindow), m_compInfoWindow(nullptr), - m_init(false), m_windowMode(windowMode), m_audioTestRunning(NoAudioTest), + m_init(false), m_windowMode(windowMode), m_keyboard(nullptr), // contexts and runtime m_coreAvailable(false), m_contextNetworkAvailable(false), m_contextAudioAvailable(false), // timers m_timerContextWatchdog(nullptr), - m_timerStatusBar(nullptr), m_timerAudioTests(nullptr), m_timerSimulator(nullptr), + m_timerStatusBar(nullptr), m_timerSimulator(nullptr), // context menus m_contextMenuAudio(nullptr), m_contextMenuStatusMessageList(nullptr), // cockpit m_inputFocusedWidget(nullptr), // status bar - m_statusBarIcon(nullptr), m_statusBarLabel(nullptr), - // keyboard /hotkeys - m_keyboard(nullptr) + m_statusBarIcon(nullptr), m_statusBarLabel(nullptr) { if (windowMode == GuiModes::WindowFrameless) { @@ -197,11 +196,9 @@ void MainWindow::toggleNetworkConnection() { // validation of data here is not required, network context does this // in prephase of login - this->m_ownAircraft.setCallsign(this->ui->le_SettingsAircraftCallsign->text()); + this->m_ownAircraft.setCallsign(this->ui->comp_Settings->getOwnCallsignFromGui()); CAircraftIcao icao = this->m_ownAircraft.getIcaoInfo(); - icao.setAirlineDesignator(this->ui->le_SettingsIcaoAirlineDesignator->text()); - icao.setAircraftDesignator(this->ui->le_SettingsIcaoAircraftDesignator->text()); - icao.setAircraftCombinedType(this->ui->le_SettingsIcaoCombinedType->text()); + this->ui->comp_Settings->setOwnAircraftIcaoDataFromGui(icao); this->m_ownAircraft.setIcaoInfo(icao); // set latest aircraft @@ -212,12 +209,12 @@ void MainWindow::toggleNetworkConnection() // Login is based on setting current server INetwork::LoginMode mode = INetwork::LoginNormal; - if (this->ui->rb_SettingsLoginStealthMode->isChecked()) + if (this->ui->comp_Settings->loginStealth()) { mode = INetwork::LoginStealth; this->displayStatusMessage(CStatusMessage::getInfoMessage("login in stealth mode")); } - else if (this->ui->rb_SettingsLoginObserver->isChecked()) + else if (this->ui->comp_Settings->loginAsObserver()) { mode = INetwork::LoginAsObserver; this->displayStatusMessage(CStatusMessage::getInfoMessage("login in observer mode")); @@ -292,6 +289,12 @@ void MainWindow::displayRedirectedOutput(const CStatusMessage &statusMessage, qi this->ui->te_StatusPageConsole->appendHtml(statusMessage.toHtml()); } +void MainWindow::changedSetttings(uint typeValue) +{ + IContextSettings::SettingsType type = static_cast(typeValue); + if (type == IContextSettings::SettingsHotKeys) this->registerHotkeys(); +} + /* * Connection terminated */ @@ -427,7 +430,7 @@ void MainWindow::changeWindowOpacity(int opacity) qreal o = opacity / 100.0; o = o < 0.3 ? 0.3 : o; QWidget::setWindowOpacity(o); - this->ui->hs_SettingsGuiOpacity->setValue(o * 100.0); + this->ui->comp_Settings->setGuiOpacity(o * 100.0); } void MainWindow::updateSimulatorData() @@ -483,3 +486,31 @@ void MainWindow::toogleWindowStayOnTop() this->setWindowFlags(flags); this->show(); } + +/* + * Hotkeys + */ +void MainWindow::registerHotkeys() +{ + if (!this->getIContextSettings()) qFatal("Missing settings"); + if (!this->m_keyboard) + { + this->m_keyboard = BlackInput::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.h b/samples/blackgui/mainwindow.h index be06571c3..34b02078c 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -83,20 +83,12 @@ protected: MainPageSimulator = 8 }; - //! Audio test modes - enum AudioTest - { - NoAudioTest, - SquelchTest, - MicrophoneTest - }; - private: QScopedPointer ui; BlackGui::CInfoWindowComponent *m_compInfoWindow; bool m_init; GuiModes::WindowMode m_windowMode; - AudioTest m_audioTestRunning; + BlackInput::IKeyboard *m_keyboard; //!< hotkeys // contexts bool m_coreAvailable; @@ -105,7 +97,6 @@ private: BlackMisc::Aviation::CAircraft m_ownAircraft; /*!< own aircraft's state */ QTimer *m_timerContextWatchdog; /*!< core available? */ QTimer *m_timerStatusBar; /*!< cleaning up status bar */ - QTimer *m_timerAudioTests; /*!< audio tests: progress bar, disable/enable buttons */ QTimer *m_timerSimulator; /*!< update simulator data */ // pixmaps @@ -131,21 +122,9 @@ private: QLabel *m_statusBarIcon; /*!< status bar icon */ QLabel *m_statusBarLabel; /*!< status bar label */ - // Hotkeys - BlackInput::IKeyboard *m_keyboard; - //! GUI status update void updateGuiStatusInformation(); - /*! - * \brief Update the selected server textboxes - * \param server to be displayed - */ - void updateGuiSelectedServerTextboxes(const BlackMisc::Network::CServer &server); - - //! Selected server from textboxes - BlackMisc::Network::CServer selectedServerFromTextboxes() const; - //! 1st data reads void initialDataReads(); @@ -194,18 +173,12 @@ private: */ void stopAllTimers(bool disconnect); - //! Audio test updates (timer) for progressbar and fetching results - void audioTestUpdate(); - //! Play notifcation sound void playNotifcationSound(BlackSound::CNotificationSounds::Notification notification) const; //! Update simulator page with latest user aircraft data void updateSimulatorData(); - //! Set the hotkeys - void setHotkeys(); - //! Originator for aircraft context static const QString &sampleBlackGuiOriginator() { @@ -223,13 +196,16 @@ private slots: bool reloadOwnAircraft(); //! Display status message - void displayStatusMessage(const BlackMisc::CStatusMessage &statusMessage); + void displayStatusMessage(const BlackMisc::CStatusMessage &sendStatusMessage); //! Display status messages void displayStatusMessages(const BlackMisc::CStatusMessageList &messages); //! Redirected output - void displayRedirectedOutput(const BlackMisc::CStatusMessage &statusMessage, qint64 contextId); + void displayRedirectedOutput(const BlackMisc::CStatusMessage &sendStatusMessage, qint64 contextId); + + //! Settings have been changed + void changedSetttings(uint typeValue); /*! * \brief Connection status changed @@ -238,9 +214,6 @@ private slots: */ void connectionStatusChanged(uint from, uint to, const QString &message); - //! Reload settings - void reloadSettings(); - //! Simulator available void simulatorConnectionChanged(bool isAvailable); @@ -269,27 +242,9 @@ private slots: //! Terminated connection void connectionTerminated(); - /*! - * \brief Network server selected - * \param index - */ - void networkServerSelected(QModelIndex index); - - //! Alter traffic server - void alterTrafficServer(); - - //! Settings have been changed - void changedSettings(uint typeValue); - //! Update timer void timerBasedUpdates(); - /*! - * \brief Audio device selected - * \param index audio device index (COM1, COM2) - */ - void audioDeviceSelected(int index); - //! Audio volume handling and mute void audioVolumes(); @@ -302,18 +257,11 @@ private slots: //! Context menu for audio void audioIconContextMenu(const QPoint &position); - //! start the MIC tests (Squelch) - void startAudioTest(); - - //! Save the Hotkeys - void saveHotkeys(); - - //! Clear single hotkey - void clearHotkey(); - //! Toogle Windows stay on top void toogleWindowStayOnTop(); + //! Set the hotkeys + void registerHotkeys(); }; #pragma pop_macro("interface") diff --git a/samples/blackgui/mainwindow.ui b/samples/blackgui/mainwindow.ui index 7f39f7e8a..472fed902 100644 --- a/samples/blackgui/mainwindow.ui +++ b/samples/blackgui/mainwindow.ui @@ -571,7 +571,7 @@ QStatusBar QLabel { 0 0 - 90 + 86 59 @@ -857,724 +857,10 @@ QStatusBar QLabel { 0 - + - 1 + -1 - - - Traffic Network - - - - 2 - - - 1 - - - 1 - - - 1 - - - 1 - - - - - QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - false - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - 6 - - - 6 - - - 6 - - - 6 - - - - - Name - - - - - - - - - - - - - - Description - - - - - - - - - - Address - - - - - - - - - - Port - - - - - - - 5 - - - - - - - Real name - - - - - - - - - - - - - - Id: - - - - - - - - - - - - - - Password - - - - - - - - - - 32 - - - QLineEdit::Password - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 3 - - - 3 - - - - - Save - - - - - - - Remove - - - - - - - Current server - - - - - - - - - - - Aircraft - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Callsign - - - - - - - Qt::ImhLatinOnly|Qt::ImhUppercaseOnly - - - BLACK - - - 20 - - - - - - - ICAO type (e.g. A320) - - - - - - - Qt::ImhUppercaseOnly - - - C172 - - - - - - - ICAO airline (e.g.DLH) - - - - - - - SGN - - - - - - - Aircraft type (e.g. L2J) - - - - - - - L1P - - - - - - - Login modes - - - - - - - - - - - - - Normal - - - true - - - - - - - Stealth mode - - - - - - - Observer - - - - - - - - - - - - - Audio - - - - 2 - - - 2 - - - - - QFormLayout::AllNonFixedFieldsGrow - - - 2 - - - 4 - - - 2 - - - 2 - - - - - In - - - - - - - - - - Out - - - - - - - - - - Qt::Vertical - - - - 20 - 20 - - - - - - - - Tests - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - 16777215 - 16777215 - - - - false - - - Start squelch test - - - - - - - - 16777215 - 16777215 - - - - Start microphone test - - - - - - - - - - - - Result - - - - - - - - 16777215 - 40 - - - - true - - - - - - - 0 - - - - - - - Qt::Vertical - - - - 20 - 20 - - - - - - - - play notification sounds - - - - - - - notification for text messages - - - - - - - Notification sounds - - - - - - - notification for join/leave voice room - - - - - - - - - - Simulator - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - - GUI - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Opacity (0-100%) - - - - - - - 100 - - - 10 - - - 100 - - - Qt::Horizontal - - - - - - - Aircraft refresh time (5-30s) - - - - - - - 5 - - - 30 - - - 5 - - - 5 - - - 10 - - - Qt::Horizontal - - - QSlider::NoTicks - - - - - - - ATC refresh time (5-30s) - - - - - - - 5 - - - 30 - - - 5 - - - 5 - - - 10 - - - Qt::Horizontal - - - - - - - User refresh time (5-30s) - - - - - - - 5 - - - 30 - - - 5 - - - 5 - - - 10 - - - Qt::Horizontal - - - - - - - - - - Misc - - - - 3 - - - 2 - - - 2 - - - 2 - - - 2 - - - - - true - - - false - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - Save - - - - - - - Remove - - - - - - - Cancel - - - - - - - - @@ -2241,28 +1527,12 @@ QStatusBar QLabel { QTableView
blackgui/statusmessageview.h
- - BlackGui::CKeyboardKeyView - QTableView -
blackgui/keyboardkeyview.h
-
- - BlackGui::CServerView - QTableView -
blackgui/serverview.h
-
BlackGui::CFlightPlanComponent QTabWidget
blackgui/flightplancomponent.h
1
- - BlackGui::CSettingsFsxComponent - QFrame -
blackgui/settingsfsxcomponent.h
- 1 -
BlackGui::CUserComponent QTabWidget @@ -2293,6 +1563,12 @@ QStatusBar QLabel {
blackgui/cockpitv1component.h
1
+ + BlackGui::CSettingsComponent + QTabWidget +
blackgui/settingscomponent.h
+ 1 +
cb_StatusWithDBus @@ -2302,27 +1578,7 @@ QStatusBar QLabel { le_CommandLineInput comp_AtcStations comp_TextMessages - tw_Settings - tvp_SettingsTnServers - le_SettingsTnCsName - le_SettingsTnCsDescription - le_SettingsTnCsAddress - le_SettingsTnCsPort - le_SettingsTnCsRealName - le_SettingsTnCsNetworkId - le_SettingsTnCsPassword - pb_SettingsTnSaveServer - pb_SettingsTnRemoveServer - pb_SettingsTnCurrentServer - le_SettingsAircraftCallsign - le_SettingsIcaoAircraftDesignator - le_SettingsIcaoAirlineDesignator - le_SettingsIcaoCombinedType - cb_SettingsAudioInputDevice - cb_SettingsAudioOutputDevice - hs_SettingsGuiOpacity - hs_SettingsGuiAircraftRefreshTime - hs_SettingsGuiAtcRefreshTime + comp_Settings pb_MainConnect pb_MainStatus pb_MainWeather @@ -2340,13 +1596,6 @@ QStatusBar QLabel { pb_SoundMute pb_SoundMaxVolume te_StatusPageConsole - rb_SetttingsNormalLoginMode - rb_SettingsLoginStealthMode - rb_SettingsLoginObserver - pb_SettingsAudioSquelchTest - pb_SettingsAudioMicrophoneTest - pte_SettingsAudioTestActionAndResult - hs_SettingsGuiUserRefreshTime diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index dc2465a35..b7cfc5ede 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -61,7 +61,6 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) // timers if (this->m_timerContextWatchdog == nullptr) this->m_timerContextWatchdog = new QTimer(this); - if (this->m_timerAudioTests == nullptr) this->m_timerAudioTests = new QTimer(this); if (this->m_timerSimulator == nullptr) this->m_timerSimulator = new QTimer(this); // context @@ -100,18 +99,17 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) this->connect(this->getIContextApplication(), &IContextApplication::redirectedOutput, this, &MainWindow::displayRedirectedOutput); this->connect(this->getIContextNetwork(), &IContextNetwork::connectionTerminated, this, &MainWindow::connectionTerminated); this->connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &MainWindow::connectionStatusChanged); - this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &MainWindow::changedSettings); connect = this->connect(this->getIContextNetwork(), SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList)), this->ui->comp_TextMessages, SLOT(appendTextMessagesToGui(BlackMisc::Network::CTextMessageList))); Q_ASSERT(connect); this->connect(this->getIContextSimulator(), &IContextSimulator::connectionChanged, this, &MainWindow::simulatorConnectionChanged); this->connect(this->m_timerContextWatchdog, &QTimer::timeout, this, &MainWindow::timerBasedUpdates); - this->connect(this->m_timerAudioTests, &QTimer::timeout, this, &MainWindow::audioTestUpdate); this->connect(this->m_timerSimulator, &QTimer::timeout, this, &MainWindow::timerBasedUpdates); - connect = this->connect(this->getIContextAudio(), &IContextAudio::audioTestCompleted, this, &MainWindow::audioTestUpdate); + this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &MainWindow::changedSetttings); // sliders - this->connect(this->ui->hs_SettingsGuiUserRefreshTime, &QSlider::valueChanged, this->ui->comp_Users, &BlackGui::CUserComponent::setUpdateIntervalSeconds); - this->connect(this->ui->hs_SettingsGuiAircraftRefreshTime, &QSlider::valueChanged, this->ui->comp_Aircrafts, &BlackGui::CAircraftComponent::setUpdateIntervalSeconds); + this->connect(this->ui->comp_Settings, &CSettingsComponent::changedUsersUpdateInterval, this->ui->comp_Users, &BlackGui::CUserComponent::setUpdateIntervalSeconds); + this->connect(this->ui->comp_Settings, &CSettingsComponent::changedAircraftsUpdateInterval, this->ui->comp_Aircrafts, &BlackGui::CAircraftComponent::setUpdateIntervalSeconds); + this->connect(this->ui->comp_Settings, &CSettingsComponent::changedAtcStationsUpdateInterval, this->ui->comp_AtcStations, &BlackGui::CAtcStationComponent::setUpdateIntervalSeconds); Q_ASSERT(connect); Q_UNUSED(connect); // suppress GCC warning in release build @@ -122,10 +120,6 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) // init availability this->setContextAvailability(); - // voice panel - this->setAudioDeviceLists(); - this->ui->prb_SettingsAudioTestProgress->setVisible(false); - // cockpit external buttons this->ui->comp_Cockpit->setExternalIdentButton(this->ui->pb_CockpitIdent); @@ -149,7 +143,7 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) this->ui->te_StatusPageConsole->appendPlainText(CProject::compiledInfo()); // hotkeys - this->setHotkeys(); + this->registerHotkeys(); // do this as last statement, so it can be used as flag // whether init has been completed @@ -217,27 +211,8 @@ void MainWindow::initGuiSignals() this->connect(this->ui->comp_TextMessages, &CTextMessageComponent::displayInInfoWindow, this->m_compInfoWindow, &CInfoWindowComponent::display); this->ui->comp_TextMessages->setSelcalCallback(std::bind(&CCockpitV1Component::getSelcalCode, this->ui->comp_Cockpit)); - // voice - connected = this->connect(this->ui->cb_SettingsAudioInputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int))); - Q_ASSERT(connected); - connected = this->connect(this->ui->cb_SettingsAudioOutputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int))); - Q_ASSERT(connected); - this->connect(this->ui->pb_SettingsAudioMicrophoneTest, &QPushButton::clicked, this, &MainWindow::startAudioTest); - this->connect(this->ui->pb_SettingsAudioSquelchTest, &QPushButton::clicked, this, &MainWindow::startAudioTest); - - // Settings server - this->connect(this->ui->pb_SettingsTnCurrentServer, &QPushButton::released, this, &MainWindow::alterTrafficServer); - this->connect(this->ui->pb_SettingsTnRemoveServer, &QPushButton::released, this, &MainWindow::alterTrafficServer); - this->connect(this->ui->pb_SettingsTnSaveServer, &QPushButton::released, this, &MainWindow::alterTrafficServer); - this->connect(this->ui->tvp_SettingsTnServers, &QTableView::clicked, this, &MainWindow::networkServerSelected); - - // Settings - this->connect(this->ui->hs_SettingsGuiOpacity, &QSlider::valueChanged, this, &MainWindow::changeWindowOpacity); - - // Settings hotkeys - this->connect(this->ui->pb_SettingsMiscCancel, &QPushButton::clicked, this, &MainWindow::reloadSettings); - this->connect(this->ui->pb_SettingsMiscSave, &QPushButton::clicked, this, &MainWindow::saveHotkeys); - this->connect(this->ui->pb_SettingsMiscRemove, &QPushButton::clicked, this, &MainWindow::clearHotkey); + // settings (GUI component) + this->connect(this->ui->comp_Settings, &CSettingsComponent::changedWindowsOpacity, this, &MainWindow::changeWindowOpacity); // no warnings in release build Q_UNUSED(connected); @@ -257,7 +232,7 @@ void MainWindow::initialDataReads() return; } - this->reloadSettings(); // init read + this->ui->comp_Settings->reloadSettings(); // init read this->reloadOwnAircraft(); // init read, independent of traffic network // also reads bookings if not connected @@ -285,9 +260,9 @@ void MainWindow::initialDataReads() */ void MainWindow::startUpdateTimers() { - this->ui->comp_Aircrafts->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiAtcRefreshTime->value()); - this->ui->comp_AtcStations->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiAircraftRefreshTime->value()); - this->ui->comp_Users->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiUserRefreshTime->value()); + this->ui->comp_Aircrafts->setUpdateIntervalSeconds(this->ui->comp_Settings->getAircraftUpdateIntervalSeconds()); + this->ui->comp_AtcStations->setUpdateIntervalSeconds(this->ui->comp_Settings->getAtcUpdateIntervalSeconds()); + this->ui->comp_Users->setUpdateIntervalSeconds(this->ui->comp_Settings->getUsersUpdateIntervalSeconds()); } /* @@ -304,38 +279,10 @@ void MainWindow::stopAllTimers(bool disconnect) { this->m_timerStatusBar->stop(); this->m_timerContextWatchdog->stop(); - this->m_timerAudioTests->stop(); this->m_timerSimulator->stop(); this->stopUpdateTimers(); if (!disconnect) return; this->disconnect(this->m_timerStatusBar); this->disconnect(this->m_timerContextWatchdog); - this->disconnect(this->m_timerAudioTests); this->disconnect(this->m_timerSimulator); } - -void MainWindow::setHotkeys() -{ - Q_ASSERT(this->getIContextSettings()); - if (!this->m_keyboard) - { - this->m_keyboard = BlackInput::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_menus.cpp b/samples/blackgui/mainwindow_menus.cpp index 4fef109fd..53d8726cf 100644 --- a/samples/blackgui/mainwindow_menus.cpp +++ b/samples/blackgui/mainwindow_menus.cpp @@ -37,7 +37,7 @@ void MainWindow::menuClicked() } else if (sender == this->ui->menu_ReloadSettings) { - this->reloadSettings(); + this->ui->comp_Settings->reloadSettings(); msgs.insert(CStatusMessage::getInfoMessage("Settings reloaded")); } else if (sender == this->ui->menu_FileClose) diff --git a/samples/blackgui/mainwindow_settings.cpp b/samples/blackgui/mainwindow_settings.cpp deleted file mode 100644 index 9e9161abe..000000000 --- a/samples/blackgui/mainwindow_settings.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "blackgui/atcstationlistmodel.h" -#include "blackcore/dbus_server.h" -#include "blackcore/context_network.h" -#include "blackmisc/hwkeyboardkey.h" -#include "blackmisc/setaudio.h" - -using namespace BlackCore; -using namespace BlackMisc; -using namespace BlackGui; -using namespace BlackMisc::Network; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Geo; -using namespace BlackMisc::Settings; - -/* - * Reload settings - */ -void MainWindow::reloadSettings() -{ - // local copy - CSettingsNetwork nws = this->getIContextSettings()->getNetworkSettings(); - CSettingsAudio as = this->getIContextSettings()->getAudioSettings(); - - // update servers - this->ui->tvp_SettingsTnServers->setSelectedServer(nws.getCurrentTrafficNetworkServer()); - this->ui->tvp_SettingsTnServers->update(nws.getTrafficNetworkServers()); - - // 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(as.getNotificationFlag(BlackSound::CNotificationSounds::NotificationTextMessagePrivate)); - this->ui->cb_SettingsAudioNotificationVoiceRoom->setChecked(as.getNotificationFlag(BlackSound::CNotificationSounds::NotificationVoiceRoomJoined)); -} - -/* - * Network has been selected - */ -void MainWindow::networkServerSelected(QModelIndex index) -{ - const CServer clickedServer = this->ui->tvp_SettingsTnServers->at(index); - this->updateGuiSelectedServerTextboxes(clickedServer); -} - -/* - * Alter server - */ -void MainWindow::alterTrafficServer() -{ - CServer server = this->selectedServerFromTextboxes(); - if (!server.isValidForLogin()) - { - const CStatusMessage validation = CStatusMessage::getValidationError("Wrong settings for server"); - this->displayStatusMessage(validation); - return; - } - - const QString path = CSettingUtilities::appendPaths(IContextSettings::PathNetworkSettings(), CSettingsNetwork::ValueTrafficServers()); - QObject *sender = QObject::sender(); - CStatusMessageList msgs; - if (sender == this->ui->pb_SettingsTnCurrentServer) - { - msgs = this->getIContextSettings()->value(path, CSettingsNetwork::CmdSetCurrentServer(), server.toQVariant()); - } - else if (sender == this->ui->pb_SettingsTnRemoveServer) - { - msgs = this->getIContextSettings()->value(path, CSettingUtilities::CmdRemove(), server.toQVariant()); - } - else if (sender == this->ui->pb_SettingsTnSaveServer) - { - msgs = this->getIContextSettings()->value(path, CSettingUtilities::CmdUpdate(), server.toQVariant()); - } - - // status messages - this->displayStatusMessages(msgs); -} - -/* - * Settings did changed - */ -void MainWindow::changedSettings(uint typeValue) -{ - IContextSettings::SettingsType type = static_cast(typeValue); - this->reloadSettings(); - if (type == IContextSettings::SettingsHotKeys) this->setHotkeys(); -} - -/* - * Textboxes from server - */ -void MainWindow::updateGuiSelectedServerTextboxes(const CServer &server) -{ - this->ui->le_SettingsTnCsName->setText(server.getName()); - this->ui->le_SettingsTnCsDescription->setText(server.getDescription()); - this->ui->le_SettingsTnCsAddress->setText(server.getAddress()); - this->ui->le_SettingsTnCsPort->setText(QString::number(server.getPort())); - this->ui->le_SettingsTnCsRealName->setText(server.getUser().getRealName()); - this->ui->le_SettingsTnCsNetworkId->setText(server.getUser().getId()); - this->ui->le_SettingsTnCsPassword->setText(server.getUser().getPassword()); -} - -/* - * Server settings from textboxes - */ -CServer MainWindow::selectedServerFromTextboxes() const -{ - CServer server; - bool portOk = false; - server.setName(this->ui->le_SettingsTnCsName->text()); - server.setDescription(this->ui->le_SettingsTnCsDescription->text()); - server.setAddress(this->ui->le_SettingsTnCsAddress->text()); - server.setPort(this->ui->le_SettingsTnCsPort->text().toInt(&portOk)); - if (!portOk) server.setPort(-1); - - CUser user; - user.setRealName(this->ui->le_SettingsTnCsRealName->text()); - user.setId(this->ui->le_SettingsTnCsNetworkId->text()); - user.setPassword(this->ui->le_SettingsTnCsPassword->text()); - server.setUser(user); - - return server; -} - -/* - * Save the hotkeys - */ -void MainWindow::saveHotkeys() -{ - const QString path = CSettingUtilities::appendPaths(IContextSettings::PathRoot(), IContextSettings::PathHotkeys()); - CStatusMessageList msgs = this->getIContextSettings()->value(path, CSettingUtilities::CmdUpdate(), this->ui->tvp_SettingsMiscHotkeys->derivedModel()->getContainer().toQVariant()); - - // status messages - this->displayStatusMessages(msgs); -} - -/* - * Clear particular hotkey - */ -void MainWindow::clearHotkey() -{ - QModelIndex i = this->ui->tvp_SettingsMiscHotkeys->currentIndex(); - if (i.row() < 0 || i.row() >= this->ui->tvp_SettingsMiscHotkeys->rowCount()) return; - BlackMisc::Hardware::CKeyboardKey key = this->ui->tvp_SettingsMiscHotkeys->at(i); - BlackMisc::Hardware::CKeyboardKey defaultKey; - defaultKey.setFunction(key.getFunction()); - this->ui->tvp_SettingsMiscHotkeys->derivedModel()->update(i, defaultKey); -} diff --git a/samples/blackgui/mainwindow_voice.cpp b/samples/blackgui/mainwindow_voice.cpp index ac1f721e6..55c6b6798 100644 --- a/samples/blackgui/mainwindow_voice.cpp +++ b/samples/blackgui/mainwindow_voice.cpp @@ -18,68 +18,6 @@ using namespace BlackMisc::Geo; using namespace BlackMisc::Settings; using namespace BlackMisc::Math; -/* - * Set audio device lists - */ -void MainWindow::setAudioDeviceLists() -{ - if (!this->isContextAudioAvailableCheck()) return; - this->ui->cb_SettingsAudioOutputDevice->clear(); - this->ui->cb_SettingsAudioInputDevice->clear(); - - foreach(CAudioDevice device, this->getIContextAudio()->getAudioDevices()) - { - if (device.getType() == CAudioDevice::InputDevice) - { - this->ui->cb_SettingsAudioInputDevice->addItem(device.toQString(true)); - } - else if (device.getType() == CAudioDevice::OutputDevice) - { - this->ui->cb_SettingsAudioOutputDevice->addItem(device.toQString(true)); - } - } - - foreach(CAudioDevice device, this->getIContextAudio()->getCurrentAudioDevices()) - { - if (device.getType() == CAudioDevice::InputDevice) - { - this->ui->cb_SettingsAudioInputDevice->setCurrentText(device.toQString(true)); - } - else if (device.getType() == CAudioDevice::OutputDevice) - { - this->ui->cb_SettingsAudioOutputDevice->setCurrentText(device.toQString(true)); - } - } -} - -/* - * Select audio device - */ -void MainWindow::audioDeviceSelected(int index) -{ - if (!this->m_init) return; // not during init - if (!this->isContextAudioAvailableCheck()) return; - if (index < 0)return; - CAudioDeviceList devices = this->getIContextAudio()->getAudioDevices(); - if (devices.isEmpty()) return; - CAudioDevice selectedDevice; - QObject *sender = QObject::sender(); - if (sender == this->ui->cb_SettingsAudioInputDevice) - { - CAudioDeviceList inputDevices = devices.getInputDevices(); - if (index >= inputDevices.size()) return; - selectedDevice = inputDevices[index]; - this->getIContextAudio()->setCurrentAudioDevice(selectedDevice); - } - else if (sender == this->ui->cb_SettingsAudioOutputDevice) - { - CAudioDeviceList outputDevices = devices.getOutputDevices(); - if (index >= outputDevices.size()) return; - selectedDevice = outputDevices[index]; - this->getIContextAudio()->setCurrentAudioDevice(selectedDevice); - } -} - /* * Select audio device */ @@ -148,94 +86,12 @@ void MainWindow::audioVolumes() this->getIContextAudio()->setVolumes(this->m_ownAircraft.getCom1System(), this->m_ownAircraft.getCom2System()); } -/* - * Start the voice tests - */ -void MainWindow::startAudioTest() -{ - if (!this->m_contextAudioAvailable) - { - CStatusMessage m(CStatusMessage::TypeAudio, CStatusMessage::SeverityError, "voice context not available"); - this->displayStatusMessage(m); - return; - } - if (this->m_timerAudioTests->isActive()) - { - CStatusMessage m(CStatusMessage::TypeAudio, CStatusMessage::SeverityError, "test running, wait until completed"); - this->displayStatusMessage(m); - return; - } - - QObject *sender = QObject::sender(); - this->m_timerAudioTests->start(600); // I let this run for ms, so there is enough overhead to really complete it - this->ui->prb_SettingsAudioTestProgress->setValue(0); - this->ui->pte_SettingsAudioTestActionAndResult->clear(); - if (sender == this->ui->pb_SettingsAudioMicrophoneTest) - { - this->m_audioTestRunning = MicrophoneTest; - this->getIContextAudio()->runMicrophoneTest(); - this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText("Speak normally for 5 seconds"); - } - else if (sender == this->ui->pb_SettingsAudioSquelchTest) - { - this->m_audioTestRunning = SquelchTest; - this->getIContextAudio()->runSquelchTest(); - this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText("Silence for 5 seconds"); - } - this->ui->prb_SettingsAudioTestProgress->setVisible(true); - this->ui->pb_SettingsAudioMicrophoneTest->setEnabled(false); - this->ui->pb_SettingsAudioSquelchTest->setEnabled(false); -} - -/* - * Start the voice tests - */ -void MainWindow::audioTestUpdate() -{ - int v = this->ui->prb_SettingsAudioTestProgress->value(); - QObject *sender = this->sender(); - - if (v < 100 && (sender == m_timerAudioTests)) - { - // timer update, increasing progress - this->ui->prb_SettingsAudioTestProgress->setValue(v + 10); - } - else - { - this->m_timerAudioTests->stop(); - this->ui->prb_SettingsAudioTestProgress->setValue(100); - if (sender == m_timerAudioTests) return; // just timer update - - // getting here we assume the audio test finished signal - // fetch results - this->ui->pte_SettingsAudioTestActionAndResult->clear(); - if (this->m_contextAudioAvailable) - { - if (this->m_audioTestRunning == SquelchTest) - { - double s = this->getIContextAudio()->getSquelchValue(); - this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText(QString::number(s)); - } - else if (this->m_audioTestRunning == MicrophoneTest) - { - QString m = this->getIContextAudio()->getMicrophoneTestResult(); - this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText(m); - } - } - this->m_audioTestRunning = NoAudioTest; - this->m_timerAudioTests->stop(); - this->ui->pb_SettingsAudioMicrophoneTest->setEnabled(true); - this->ui->pb_SettingsAudioSquelchTest->setEnabled(true); - this->ui->prb_SettingsAudioTestProgress->setVisible(false); - } -} - /* * Notification */ void MainWindow::playNotifcationSound(CNotificationSounds::Notification notification) const { if (!this->m_contextAudioAvailable) return; - if (!this->ui->cb_SettingsAudioPlayNotificationSounds->isChecked()) return; + if (!this->ui->comp_Settings->playNotificationSounds()) return; this->getIContextAudio()->playNotification(static_cast(notification), true); } diff --git a/src/blackgui/settingscomponent.cpp b/src/blackgui/settingscomponent.cpp new file mode 100644 index 000000000..921e00615 --- /dev/null +++ b/src/blackgui/settingscomponent.cpp @@ -0,0 +1,405 @@ +#include "settingscomponent.h" +#include "ui_settingscomponent.h" +#include "blackgui/atcstationlistmodel.h" +#include "blackcore/dbus_server.h" +#include "blackcore/context_network.h" +#include "blackmisc/hwkeyboardkeylist.h" +#include "blackmisc/setaudio.h" + +using namespace BlackCore; +using namespace BlackMisc; +using namespace BlackGui; +using namespace BlackMisc::Network; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Audio; +using namespace BlackMisc::PhysicalQuantities; +using namespace BlackMisc::Geo; +using namespace BlackMisc::Settings; +using namespace BlackMisc::Hardware; + +namespace BlackGui +{ + + CSettingsComponent::CSettingsComponent(QWidget *parent) : + QTabWidget(parent), CRuntimeBasedComponent(nullptr, false), ui(new Ui::CSettingsComponent), + m_audioTestRunning(NoAudioTest) + { + ui->setupUi(this); + this->ui->prb_SettingsAudioTestProgress->setVisible(false); + this->m_timerAudioTests = new QTimer(this); + } + + CSettingsComponent::~CSettingsComponent() + { + delete ui; + } + + /* + * Update own ICAO data from GUI + */ + void CSettingsComponent::setOwnAircraftIcaoDataFromGui(CAircraftIcao &icao) const + { + icao.setAirlineDesignator(this->ui->le_SettingsIcaoAirlineDesignator->text()); + icao.setAircraftDesignator(this->ui->le_SettingsIcaoAircraftDesignator->text()); + icao.setAircraftCombinedType(this->ui->le_SettingsIcaoCombinedType->text()); + } + + void CSettingsComponent::setGuiOpacity(double value) + { + this->ui->hs_SettingsGuiOpacity->setValue(value); + } + + bool CSettingsComponent::loginAsObserver() const + { + return this->ui->rb_SettingsLoginStealthMode->isChecked(); + } + + bool CSettingsComponent::loginStealth() const + { + return this->ui->rb_SettingsLoginStealthMode->isChecked(); + } + + bool CSettingsComponent::playNotificationSounds() const + { + return this->ui->cb_SettingsAudioPlayNotificationSounds->isChecked(); + } + + int CSettingsComponent::getAtcUpdateIntervalSeconds() const + { + return this->ui->hs_SettingsGuiAtcRefreshTime->value(); + } + + int CSettingsComponent::getAircraftUpdateIntervalSeconds() const + { + return this->ui->hs_SettingsGuiAircraftRefreshTime->value(); + } + + int CSettingsComponent::getUsersUpdateIntervalSeconds() const + { + return this->ui->hs_SettingsGuiUserRefreshTime->value(); + } + + QString CSettingsComponent::getOwnCallsignFromGui() const + { + return this->ui->le_SettingsAircraftCallsign->text(); + } + + /* + * Reload settings + */ + void CSettingsComponent::reloadSettings() + { + // local copy + CSettingsNetwork nws = this->getIContextSettings()->getNetworkSettings(); + CSettingsAudio as = this->getIContextSettings()->getAudioSettings(); + + // update servers + this->ui->tvp_SettingsTnServers->setSelectedServer(nws.getCurrentTrafficNetworkServer()); + this->ui->tvp_SettingsTnServers->update(nws.getTrafficNetworkServers()); + + // 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(as.getNotificationFlag(BlackSound::CNotificationSounds::NotificationTextMessagePrivate)); + this->ui->cb_SettingsAudioNotificationVoiceRoom->setChecked(as.getNotificationFlag(BlackSound::CNotificationSounds::NotificationVoiceRoomJoined)); + } + + void CSettingsComponent::runtimeHasBeenSet() + { + if (!this->getIContextSettings()) qFatal("Settings missing"); + + this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsComponent::changedSettings); + this->connect(this->m_timerAudioTests, &QTimer::timeout, this, &CSettingsComponent::audioTestUpdate); + + // based on audio context + Q_ASSERT(this->getIContextAudio()); + if (this->getIContextAudio()) + { + this->initAudioDeviceLists(); + bool connected = this->connect(this->getIContextAudio(), &IContextAudio::audioTestCompleted, this, &CSettingsComponent::audioTestUpdate); + Q_ASSERT(connected); + connected = this->connect(this->ui->cb_SettingsAudioInputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int))); + Q_ASSERT(connected); + connected = this->connect(this->ui->cb_SettingsAudioOutputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int))); + Q_ASSERT(connected); + this->connect(this->ui->pb_SettingsAudioMicrophoneTest, &QPushButton::clicked, this, &CSettingsComponent::startAudioTest); + this->connect(this->ui->pb_SettingsAudioSquelchTest, &QPushButton::clicked, this, &CSettingsComponent::startAudioTest); + } + + // Opacity, intervals + this->connect(this->ui->hs_SettingsGuiOpacity, &QSlider::valueChanged, this, &CSettingsComponent::changedWindowsOpacity); + this->connect(this->ui->hs_SettingsGuiAircraftRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedAircraftsUpdateInterval); + this->connect(this->ui->hs_SettingsGuiAtcRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedAtcStationsUpdateInterval); + this->connect(this->ui->hs_SettingsGuiUserRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedUsersUpdateInterval); + + // Settings server + this->connect(this->ui->pb_SettingsTnCurrentServer, &QPushButton::released, this, &CSettingsComponent::alterTrafficServer); + this->connect(this->ui->pb_SettingsTnRemoveServer, &QPushButton::released, this, &CSettingsComponent::alterTrafficServer); + this->connect(this->ui->pb_SettingsTnSaveServer, &QPushButton::released, this, &CSettingsComponent::alterTrafficServer); + this->connect(this->ui->tvp_SettingsTnServers, &QTableView::clicked, this, &CSettingsComponent::networkServerSelected); + + // Settings hotkeys + this->connect(this->ui->pb_SettingsMiscCancel, &QPushButton::clicked, this, &CSettingsComponent::reloadSettings); + this->connect(this->ui->pb_SettingsMiscSave, &QPushButton::clicked, this, &CSettingsComponent::saveHotkeys); + this->connect(this->ui->pb_SettingsMiscRemove, &QPushButton::clicked, this, &CSettingsComponent::clearHotkey); + } + + /* + * Network has been selected + */ + void CSettingsComponent::networkServerSelected(QModelIndex index) + { + const CServer clickedServer = this->ui->tvp_SettingsTnServers->at(index); + this->updateGuiSelectedServerTextboxes(clickedServer); + } + + /* + * Alter server + */ + void CSettingsComponent::alterTrafficServer() + { + CServer server = this->selectedServerFromTextboxes(); + if (!server.isValidForLogin()) + { + const CStatusMessage validation = CStatusMessage::getValidationError("Wrong settings for server"); + this->sendStatusMessage(validation); + return; + } + + const QString path = CSettingUtilities::appendPaths(IContextSettings::PathNetworkSettings(), CSettingsNetwork::ValueTrafficServers()); + QObject *sender = QObject::sender(); + CStatusMessageList msgs; + if (sender == this->ui->pb_SettingsTnCurrentServer) + { + msgs = this->getIContextSettings()->value(path, CSettingsNetwork::CmdSetCurrentServer(), server.toQVariant()); + } + else if (sender == this->ui->pb_SettingsTnRemoveServer) + { + msgs = this->getIContextSettings()->value(path, CSettingUtilities::CmdRemove(), server.toQVariant()); + } + else if (sender == this->ui->pb_SettingsTnSaveServer) + { + msgs = this->getIContextSettings()->value(path, CSettingUtilities::CmdUpdate(), server.toQVariant()); + } + + // status messages + this->sendStatusMessages(msgs); + } + + /* + * Settings did changed + */ + void CSettingsComponent::changedSettings(uint typeValue) + { + IContextSettings::SettingsType type = static_cast(typeValue); + this->reloadSettings(); + Q_UNUSED(type); + } + + /* + * Textboxes from server + */ + void CSettingsComponent::updateGuiSelectedServerTextboxes(const CServer &server) + { + this->ui->le_SettingsTnCsName->setText(server.getName()); + this->ui->le_SettingsTnCsDescription->setText(server.getDescription()); + this->ui->le_SettingsTnCsAddress->setText(server.getAddress()); + this->ui->le_SettingsTnCsPort->setText(QString::number(server.getPort())); + this->ui->le_SettingsTnCsRealName->setText(server.getUser().getRealName()); + this->ui->le_SettingsTnCsNetworkId->setText(server.getUser().getId()); + this->ui->le_SettingsTnCsPassword->setText(server.getUser().getPassword()); + } + + /* + * Server settings from textboxes + */ + CServer CSettingsComponent::selectedServerFromTextboxes() const + { + CServer server; + bool portOk = false; + server.setName(this->ui->le_SettingsTnCsName->text()); + server.setDescription(this->ui->le_SettingsTnCsDescription->text()); + server.setAddress(this->ui->le_SettingsTnCsAddress->text()); + server.setPort(this->ui->le_SettingsTnCsPort->text().toInt(&portOk)); + if (!portOk) server.setPort(-1); + + CUser user; + user.setRealName(this->ui->le_SettingsTnCsRealName->text()); + user.setId(this->ui->le_SettingsTnCsNetworkId->text()); + user.setPassword(this->ui->le_SettingsTnCsPassword->text()); + server.setUser(user); + + return server; + } + + /* + * Save the hotkeys + */ + void CSettingsComponent::saveHotkeys() + { + const QString path = CSettingUtilities::appendPaths(IContextSettings::PathRoot(), IContextSettings::PathHotkeys()); + CStatusMessageList msgs = this->getIContextSettings()->value(path, CSettingUtilities::CmdUpdate(), this->ui->tvp_SettingsMiscHotkeys->derivedModel()->getContainer().toQVariant()); + + // status messages + this->sendStatusMessages(msgs); + } + + /* + * Clear particular hotkey + */ + void CSettingsComponent::clearHotkey() + { + QModelIndex i = this->ui->tvp_SettingsMiscHotkeys->currentIndex(); + if (i.row() < 0 || i.row() >= this->ui->tvp_SettingsMiscHotkeys->rowCount()) return; + BlackMisc::Hardware::CKeyboardKey key = this->ui->tvp_SettingsMiscHotkeys->at(i); + BlackMisc::Hardware::CKeyboardKey defaultKey; + defaultKey.setFunction(key.getFunction()); + this->ui->tvp_SettingsMiscHotkeys->derivedModel()->update(i, defaultKey); + } + + /* + * Set audio device lists + */ + void CSettingsComponent::initAudioDeviceLists() + { + if (!this->getIContextAudio()) return; + this->ui->cb_SettingsAudioOutputDevice->clear(); + this->ui->cb_SettingsAudioInputDevice->clear(); + + foreach(CAudioDevice device, this->getIContextAudio()->getAudioDevices()) + { + if (device.getType() == CAudioDevice::InputDevice) + { + this->ui->cb_SettingsAudioInputDevice->addItem(device.toQString(true)); + } + else if (device.getType() == CAudioDevice::OutputDevice) + { + this->ui->cb_SettingsAudioOutputDevice->addItem(device.toQString(true)); + } + } + + foreach(CAudioDevice device, this->getIContextAudio()->getCurrentAudioDevices()) + { + if (device.getType() == CAudioDevice::InputDevice) + { + this->ui->cb_SettingsAudioInputDevice->setCurrentText(device.toQString(true)); + } + else if (device.getType() == CAudioDevice::OutputDevice) + { + this->ui->cb_SettingsAudioOutputDevice->setCurrentText(device.toQString(true)); + } + } + } + + /* + * Start the voice tests + */ + void CSettingsComponent::startAudioTest() + { + if (!this->getIContextAudio()) + { + CStatusMessage m(CStatusMessage::TypeAudio, CStatusMessage::SeverityError, "voice context not available"); + this->sendStatusMessage(m); + return; + } + if (this->m_timerAudioTests->isActive()) + { + CStatusMessage m(CStatusMessage::TypeAudio, CStatusMessage::SeverityError, "test running, wait until completed"); + this->sendStatusMessage(m); + return; + } + + QObject *sender = QObject::sender(); + this->m_timerAudioTests->start(600); // I let this run for ms, so there is enough overhead to really complete it + this->ui->prb_SettingsAudioTestProgress->setValue(0); + this->ui->pte_SettingsAudioTestActionAndResult->clear(); + if (sender == this->ui->pb_SettingsAudioMicrophoneTest) + { + this->m_audioTestRunning = MicrophoneTest; + this->getIContextAudio()->runMicrophoneTest(); + this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText("Speak normally for 5 seconds"); + } + else if (sender == this->ui->pb_SettingsAudioSquelchTest) + { + this->m_audioTestRunning = SquelchTest; + this->getIContextAudio()->runSquelchTest(); + this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText("Silence for 5 seconds"); + } + this->ui->prb_SettingsAudioTestProgress->setVisible(true); + this->ui->pb_SettingsAudioMicrophoneTest->setEnabled(false); + this->ui->pb_SettingsAudioSquelchTest->setEnabled(false); + } + + /* + * Start the voice tests + */ + void CSettingsComponent::audioTestUpdate() + { + Q_ASSERT(this->getIContextAudio()); + if (!this->getIContextAudio()) return; + int v = this->ui->prb_SettingsAudioTestProgress->value(); + QObject *sender = this->sender(); + + if (v < 100 && (sender == m_timerAudioTests)) + { + // timer update, increasing progress + this->ui->prb_SettingsAudioTestProgress->setValue(v + 10); + } + else + { + this->m_timerAudioTests->stop(); + this->ui->prb_SettingsAudioTestProgress->setValue(100); + if (sender == m_timerAudioTests) return; // just timer update + + // getting here we assume the audio test finished signal + // fetch results + this->ui->pte_SettingsAudioTestActionAndResult->clear(); + if (this->m_audioTestRunning == SquelchTest) + { + double s = this->getIContextAudio()->getSquelchValue(); + this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText(QString::number(s)); + } + else if (this->m_audioTestRunning == MicrophoneTest) + { + QString m = this->getIContextAudio()->getMicrophoneTestResult(); + this->ui->pte_SettingsAudioTestActionAndResult->appendPlainText(m); + } + this->m_audioTestRunning = NoAudioTest; + this->m_timerAudioTests->stop(); + this->ui->pb_SettingsAudioMicrophoneTest->setEnabled(true); + this->ui->pb_SettingsAudioSquelchTest->setEnabled(true); + this->ui->prb_SettingsAudioTestProgress->setVisible(false); + } + } + + /* + * Select audio device + */ + void CSettingsComponent::audioDeviceSelected(int index) + { + if (!this->getIContextAudio()) return; + if (index < 0)return; + + CAudioDeviceList devices = this->getIContextAudio()->getAudioDevices(); + if (devices.isEmpty()) return; + CAudioDevice selectedDevice; + QObject *sender = QObject::sender(); + if (sender == this->ui->cb_SettingsAudioInputDevice) + { + CAudioDeviceList inputDevices = devices.getInputDevices(); + if (index >= inputDevices.size()) return; + selectedDevice = inputDevices[index]; + this->getIContextAudio()->setCurrentAudioDevice(selectedDevice); + } + else if (sender == this->ui->cb_SettingsAudioOutputDevice) + { + CAudioDeviceList outputDevices = devices.getOutputDevices(); + if (index >= outputDevices.size()) return; + selectedDevice = outputDevices[index]; + this->getIContextAudio()->setCurrentAudioDevice(selectedDevice); + } + } + +} // namespace diff --git a/src/blackgui/settingscomponent.h b/src/blackgui/settingscomponent.h new file mode 100644 index 000000000..246d3cb61 --- /dev/null +++ b/src/blackgui/settingscomponent.h @@ -0,0 +1,130 @@ +#ifndef BLACKGUI_SETTINGSCOMPONENT_H +#define BLACKGUI_SETTINGSCOMPONENT_H + +#include "blackgui/runtimebasedcomponent.h" +#include +#include +#include + + +namespace Ui { class CSettingsComponent; } + +namespace BlackGui +{ + //! Settings component + class CSettingsComponent : public QTabWidget, public CRuntimeBasedComponent + { + Q_OBJECT + + public: + //! Constructor + explicit CSettingsComponent(QWidget *parent = nullptr); + + //! Destructor + ~CSettingsComponent(); + + //! ICAO data from GUI + void setOwnAircraftIcaoDataFromGui(BlackMisc::Aviation::CAircraftIcao &icao) const; + + //! GUI Opacity 0-100% + void setGuiOpacity(double value); + + //! Login as observer + bool loginAsObserver() const; + + //! Login as observer + bool loginStealth() const; + + //! Play notification sounds (at all) + bool playNotificationSounds() const; + + //! ATC refresh time + int getAtcUpdateIntervalSeconds() const; + + //! Aircraft refresh time + int getAircraftUpdateIntervalSeconds() const; + + //! Aircraft refresh time + int getUsersUpdateIntervalSeconds() const; + + //! Own callsign + QString getOwnCallsignFromGui() const; + + signals: + //! Change the windows opacity 0..100 + void changedWindowsOpacity(int opacity); + + //! Update interval changed (ATC) + void changedAtcStationsUpdateInterval(int seconds); + + //! Update interval changed (aircrafts) + void changedAircraftsUpdateInterval(int seconds); + + //! Update interval changed (users) + void changedUsersUpdateInterval(int seconds); + + public slots: + //! Reload settings + void reloadSettings(); + + protected: + //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet + virtual void runtimeHasBeenSet() override; + + private slots: + + //! Network server selected + void networkServerSelected(QModelIndex index); + + //! Alter traffic server + void alterTrafficServer(); + + /*! + * \brief Update the selected server textboxes + * \param server to be displayed + */ + void updateGuiSelectedServerTextboxes(const BlackMisc::Network::CServer &server); + + //! Selected server from textboxes + BlackMisc::Network::CServer selectedServerFromTextboxes() const; + + //! Settings have been changed + void changedSettings(uint typeValue); + + //! Save the Hotkeys + void saveHotkeys(); + + //! Clear single hotkey + void clearHotkey(); + + //! start the MIC tests (Squelch) + void startAudioTest(); + + //! Audio test updates (timer) for progressbar and fetching results + void audioTestUpdate(); + + /*! + * \brief Audio device selected + * \param index audio device index (COM1, COM2) + */ + void audioDeviceSelected(int index); + + private: + //! Audio test modes + enum AudioTest + { + NoAudioTest, + SquelchTest, + MicrophoneTest + }; + + Ui::CSettingsComponent *ui; + QTimer *m_timerAudioTests; //!< audio tests: progress bar, disable/enable buttons + AudioTest m_audioTestRunning; + + //! Audio device lists from settings + void initAudioDeviceLists(); + }; +} // namespace + +#endif // guard diff --git a/src/blackgui/settingscomponent.ui b/src/blackgui/settingscomponent.ui new file mode 100644 index 000000000..05d636c72 --- /dev/null +++ b/src/blackgui/settingscomponent.ui @@ -0,0 +1,754 @@ + + + CSettingsComponent + + + + 0 + 0 + 400 + 323 + + + + TabWidget + + + 0 + + + + Traffic Network + + + + 2 + + + 1 + + + 1 + + + 1 + + + 1 + + + + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Name + + + + + + + + + + + + + + Description + + + + + + + + + + Address + + + + + + + + + + Port + + + + + + + 5 + + + + + + + Real name + + + + + + + + + + + + + + Id: + + + + + + + + + + + + + + Password + + + + + + + + + + 32 + + + QLineEdit::Password + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 3 + + + 3 + + + + + Save + + + + + + + Remove + + + + + + + Current server + + + + + + + + + + + Aircraft + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Callsign + + + + + + + Qt::ImhLatinOnly|Qt::ImhUppercaseOnly + + + BLACK + + + 20 + + + + + + + ICAO type (e.g. A320) + + + + + + + Qt::ImhUppercaseOnly + + + C172 + + + + + + + ICAO airline (e.g.DLH) + + + + + + + SGN + + + + + + + Aircraft type (e.g. L2J) + + + + + + + L1P + + + + + + + Login modes + + + + + + + + + + + + + Normal + + + true + + + + + + + Stealth mode + + + + + + + Observer + + + + + + + + + + + + + Audio + + + + 2 + + + 2 + + + + + QFormLayout::AllNonFixedFieldsGrow + + + 2 + + + 4 + + + 2 + + + 2 + + + + + In + + + + + + + + + + Out + + + + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + Tests + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 16777215 + 16777215 + + + + false + + + Start squelch test + + + + + + + + 16777215 + 16777215 + + + + Start microphone test + + + + + + + + + + + + Result + + + + + + + + 16777215 + 40 + + + + true + + + + + + + 0 + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + play notification sounds + + + + + + + notification for text messages + + + + + + + Notification sounds + + + + + + + notification for join/leave voice room + + + + + + + + + + Simulator + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + GUI + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Opacity (0-100%) + + + + + + + 100 + + + 10 + + + 100 + + + Qt::Horizontal + + + + + + + Aircraft refresh time (5-30s) + + + + + + + 5 + + + 30 + + + 5 + + + 5 + + + 10 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + + ATC refresh time (5-30s) + + + + + + + 5 + + + 30 + + + 5 + + + 5 + + + 10 + + + Qt::Horizontal + + + + + + + User refresh time (5-30s) + + + + + + + 5 + + + 30 + + + 5 + + + 5 + + + 10 + + + Qt::Horizontal + + + + + + + + + + Misc + + + + 3 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + true + + + false + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Save + + + + + + + Remove + + + + + + + Cancel + + + + + + + + + + + + BlackGui::CKeyboardKeyView + QTableView +
blackgui/keyboardkeyview.h
+
+ + BlackGui::CServerView + QTableView +
blackgui/serverview.h
+
+ + BlackGui::CSettingsFsxComponent + QFrame +
blackgui/settingsfsxcomponent.h
+ 1 +
+
+ + +