diff --git a/src/blackgui/components/maininfoareacomponent.cpp b/src/blackgui/components/maininfoareacomponent.cpp index 2cfaff496..b991e510b 100644 --- a/src/blackgui/components/maininfoareacomponent.cpp +++ b/src/blackgui/components/maininfoareacomponent.cpp @@ -261,6 +261,12 @@ namespace BlackGui this->selectArea(static_cast(index)); } + void CMainInfoAreaComponent::selectSettingsTab(int index) + { + this->selectArea(InfoAreaSettings); + this->ui->comp_Settings->setSettingsTab(static_cast(index)); + } + void CMainInfoAreaComponent::ps_setDockArea(Qt::DockWidgetArea area) { for (CDockWidgetInfoArea *dw : this->m_dockableWidgets) diff --git a/src/blackgui/components/maininfoareacomponent.h b/src/blackgui/components/maininfoareacomponent.h index 3aa78cdde..ef7d812ac 100644 --- a/src/blackgui/components/maininfoareacomponent.h +++ b/src/blackgui/components/maininfoareacomponent.h @@ -115,6 +115,9 @@ namespace BlackGui //! Select area void selectArea(int index); + //! Select settings with given area + void selectSettingsTab(int index); + protected: //! Override close event virtual void closeEvent(QCloseEvent *event) override; diff --git a/src/blackgui/components/maininfoareacomponent.ui b/src/blackgui/components/maininfoareacomponent.ui index 9f2df72f4..58ac66e0e 100644 --- a/src/blackgui/components/maininfoareacomponent.ui +++ b/src/blackgui/components/maininfoareacomponent.ui @@ -42,8 +42,8 @@ - 127 - 38 + 0 + 0 @@ -103,8 +103,8 @@ - 127 - 38 + 0 + 0 @@ -162,6 +162,12 @@ + + + 0 + 0 + + Qt::TopDockWidgetArea @@ -202,6 +208,12 @@ + + + 0 + 0 + + Qt::TopDockWidgetArea @@ -242,6 +254,12 @@ + + + 0 + 0 + + Qt::TopDockWidgetArea @@ -282,6 +300,12 @@ + + + 0 + 0 + + Qt::TopDockWidgetArea @@ -322,6 +346,12 @@ + + + 0 + 0 + + Qt::TopDockWidgetArea @@ -365,6 +395,12 @@ + + + 0 + 0 + + Qt::TopDockWidgetArea @@ -405,6 +441,12 @@ + + + 0 + 0 + + Qt::TopDockWidgetArea @@ -445,6 +487,12 @@ + + + 0 + 0 + + Qt::TopDockWidgetArea diff --git a/src/blackgui/components/settingscomponent.cpp b/src/blackgui/components/settingscomponent.cpp index ea7778ba8..6a0a3b76b 100644 --- a/src/blackgui/components/settingscomponent.cpp +++ b/src/blackgui/components/settingscomponent.cpp @@ -10,10 +10,12 @@ #include "settingscomponent.h" #include "ui_settingscomponent.h" #include "blackgui/models/atcstationlistmodel.h" +#include "blackgui/stylesheetutility.h" #include "blackcore/dbus_server.h" #include "blackcore/context_network.h" #include "blackmisc/hwkeyboardkeylist.h" #include "blackmisc/setaudio.h" +#include using namespace BlackCore; using namespace BlackMisc; @@ -147,23 +149,35 @@ namespace BlackGui this->ui->cb_SettingsAudioNotificationVoiceRoom->setChecked(as.getNotificationFlag(BlackSound::CNotificationSounds::NotificationVoiceRoomJoined)); } + /* + * Set tab + */ + void CSettingsComponent::setSettingsTab(CSettingsComponent::SettingTab tab) + { + this->setCurrentIndex(static_cast(tab)); + } + + /* + * Runtime set + */ 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); + this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsComponent::ps_changedSettings); + this->connect(this->m_timerAudioTests, &QTimer::timeout, this, &CSettingsComponent::ps_audioTestUpdate); // based on audio context Q_ASSERT(this->getIContextAudio()); + bool connected = false; if (this->getIContextAudio()) { this->initAudioDeviceLists(); - bool connected = this->connect(this->getIContextAudio(), &IContextAudio::audioTestCompleted, this, &CSettingsComponent::audioTestUpdate); + connected = this->connect(this->getIContextAudio(), &IContextAudio::audioTestCompleted, this, &CSettingsComponent::ps_audioTestUpdate); Q_ASSERT(connected); - connected = this->connect(this->ui->cb_SettingsAudioInputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int))); + connected = this->connect(this->ui->cb_SettingsAudioInputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(ps_audioDeviceSelected(int))); Q_ASSERT(connected); - connected = this->connect(this->ui->cb_SettingsAudioOutputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(audioDeviceSelected(int))); + connected = this->connect(this->ui->cb_SettingsAudioOutputDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(ps_audioDeviceSelected(int))); Q_ASSERT(connected); this->connect(this->ui->pb_SettingsAudioMicrophoneTest, &QPushButton::clicked, this, &CSettingsComponent::ps_startAudioTest); this->connect(this->ui->pb_SettingsAudioSquelchTest, &QPushButton::clicked, this, &CSettingsComponent::ps_startAudioTest); @@ -186,6 +200,20 @@ namespace BlackGui this->connect(this->ui->pb_SettingsMiscSave, &QPushButton::clicked, this, &CSettingsComponent::ps_saveHotkeys); this->connect(this->ui->pb_SettingsMiscRemove, &QPushButton::clicked, this, &CSettingsComponent::ps_clearHotkey); + // Font + const QFont font = this->font(); + this->ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(font)); + this->ui->cb_SettingsGuiFont->setCurrentFont(font); + this->ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(font.pointSize())); + this->m_fontColor = QColor(CStyleSheetUtility::instance().fontColor()); + this->ui->le_SettingsGuiFontColor->setText(this->m_fontColor.name()); + connected = this->connect(this->ui->cb_SettingsGuiFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(ps_fontChanged())); + Q_ASSERT(connected); + connected = this->connect(this->ui->cb_SettingsGuiFontSize, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged())); + Q_ASSERT(connected); + connected = this->connect(this->ui->cb_SettingsGuiFontStyle, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged())); + Q_ASSERT(connected); + this->connect(this->ui->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsComponent::ps_fontColorDialog); } /* @@ -335,6 +363,43 @@ namespace BlackGui } } + /* + * Font has been changed + */ + void CSettingsComponent::ps_fontChanged() + { + QString fontSize = this->ui->cb_SettingsGuiFontSize->currentText().append("pt"); + QString fontFamily = this->ui->cb_SettingsGuiFont->currentFont().family(); + QString fontStyleCombined = this->ui->cb_SettingsGuiFontStyle->currentText(); + QString fontColor = this->m_fontColor.name(); + if (!this->m_fontColor.isValid() || this->m_fontColor.name().isEmpty()) + { + fontColor = CStyleSheetUtility::instance().fontColor(); + } + this->ui->le_SettingsGuiFontColor->setText(fontColor); + bool ok = CStyleSheetUtility::instance().updateFonts(fontFamily, fontSize, CStyleSheetUtility::fontStyle(fontStyleCombined), CStyleSheetUtility::fontWeight(fontStyleCombined), fontColor); + if (ok) + { + this->sendStatusMessage(CStatusMessage::getInfoMessage("Updated font style", CStatusMessage::TypeSettings)); + } + else + { + this->sendStatusMessage(CStatusMessage::getErrorMessage("Updating style failed", CStatusMessage::TypeSettings)); + } + } + + /* + * Font color dialog + */ + void CSettingsComponent::ps_fontColorDialog() + { + QColor c = QColorDialog::getColor(this->m_fontColor, this, "Font color"); + if (c == this->m_fontColor) return; + this->m_fontColor = c; + this->ui->le_SettingsGuiFontColor->setText(this->m_fontColor.name()); + this->ps_fontChanged(); + } + /* * Start the voice tests */ diff --git a/src/blackgui/components/settingscomponent.h b/src/blackgui/components/settingscomponent.h index 14ae169eb..05fc60fce 100644 --- a/src/blackgui/components/settingscomponent.h +++ b/src/blackgui/components/settingscomponent.h @@ -17,7 +17,6 @@ #include #include - namespace Ui { class CSettingsComponent; } namespace BlackGui @@ -31,6 +30,18 @@ namespace BlackGui Q_OBJECT public: + + //! Tabs + enum SettingTab + { + SettingTabNetwork = 0, + SettingTabAircraft, + SettingTabAircraftAudio, + SettingTabSimulator, + SettingTabGui, + SettingTabMisc + }; + //! Constructor explicit CSettingsComponent(QWidget *parent = nullptr); @@ -81,6 +92,9 @@ namespace BlackGui //! Reload settings void reloadSettings(); + //! Set the tab + void setSettingsTab(SettingTab tab); + protected: //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet virtual void runtimeHasBeenSet() override; @@ -123,6 +137,12 @@ namespace BlackGui */ void ps_audioDeviceSelected(int index); + //! Font has been changed + void ps_fontChanged(); + + //! Font color dialof + void ps_fontColorDialog(); + private: //! Audio test modes enum AudioTest @@ -135,9 +155,11 @@ namespace BlackGui Ui::CSettingsComponent *ui; QTimer *m_timerAudioTests; //!< audio tests: progress bar, disable/enable buttons AudioTest m_audioTestRunning; + QColor m_fontColor; //! Audio device lists from settings void initAudioDeviceLists(); + }; } } // namespace diff --git a/src/blackgui/components/settingscomponent.ui b/src/blackgui/components/settingscomponent.ui index c1d71aa96..890adce84 100644 --- a/src/blackgui/components/settingscomponent.ui +++ b/src/blackgui/components/settingscomponent.ui @@ -6,7 +6,7 @@ 0 0 - 300 + 354 323 @@ -20,7 +20,7 @@ Settings - 0 + 2 @@ -190,6 +190,12 @@ + + + 0 + 0 + + Save @@ -197,6 +203,12 @@ + + + 0 + 0 + + Remove @@ -204,6 +216,12 @@ + + + 0 + 0 + + Current server @@ -423,6 +441,12 @@ + + + 0 + 0 + + 16777215 @@ -433,12 +457,18 @@ false - Start squelch test + Squelch test + + + 0 + 0 + + 16777215 @@ -446,7 +476,7 @@ - Start microphone test + Mic. test @@ -563,6 +593,12 @@ + + + 0 + 0 + + 100 @@ -586,6 +622,12 @@ + + + 0 + 0 + + 5 @@ -618,6 +660,12 @@ + + + 0 + 0 + + 5 @@ -647,6 +695,12 @@ + + + 0 + 0 + + 5 @@ -667,6 +721,135 @@ + + + + Font + + + + + + + + 0 + 0 + + + + + + + + Font size (pt) + + + + + + + + 6 + + + + + 7 + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 12 + + + + + 14 + + + + + 16 + + + + + + + + Font style + + + + + + + + normal + + + + + bold + + + + + italic + + + + + bold italic + + + + + + + + Font color + + + + + + + + + ... + + + + + + + true + + + + + @@ -719,6 +902,12 @@ + + + 0 + 0 + + Remove @@ -726,6 +915,12 @@ + + + 0 + 0 + + Cancel diff --git a/src/blackgui/components/settingsfsxcomponent.ui b/src/blackgui/components/settingsfsxcomponent.ui index f3f83714b..058f5926d 100644 --- a/src/blackgui/components/settingsfsxcomponent.ui +++ b/src/blackgui/components/settingsfsxcomponent.ui @@ -72,6 +72,12 @@ + + + 0 + 0 + + Open @@ -79,6 +85,12 @@ + + + 0 + 0 + + Delete @@ -86,6 +98,12 @@ + + + 0 + 0 + + Save @@ -93,8 +111,14 @@ + + + 0 + 0 + + - Test connection + Test con. @@ -134,6 +158,12 @@ + + + 0 + 0 + + Check diff --git a/src/blackgui/stylesheetutility.cpp b/src/blackgui/stylesheetutility.cpp index bbce62078..ba2bfb50e 100644 --- a/src/blackgui/stylesheetutility.cpp +++ b/src/blackgui/stylesheetutility.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace BlackGui { @@ -66,6 +67,28 @@ namespace BlackGui } } + QString CStyleSheetUtility::fontAsCombinedWeightStyle(const QFont &font) + { + QString w = fontWeightAsString(font); + QString s = fontStyleAsString(font); + if (w == s) return w; // avoid "normal" "normal" + if (w.isEmpty() && s.isEmpty()) return "normal"; + if (w.isEmpty()) return s; + if (s.isEmpty()) return w; + if (s == "normal") return w; + return w.append(" ").append(s); + } + + QString CStyleSheetUtility::fontColor() + { + QString s = this->style(fileNameFonts()).toLower(); + if (!s.contains("color:")) return "red"; + QRegExp rx("color:\\s*(#*\\w+);"); + rx.indexIn(s); + QString c = rx.cap(1); + return c.isEmpty() ? "red" : c; + } + bool CStyleSheetUtility::read() { QDir directory(qssDirectory()); @@ -109,7 +132,7 @@ namespace BlackGui QString s = this->m_styleSheets[fileName.toLower()]; if (s.isEmpty()) continue; if (!style.isEmpty()) style.append("\n\n"); - style.append("/** file: %1 **/\n").arg(fileName); + style.append("/** file: ").append(fileName).append(" **/\n"); style.append(s); } return style; @@ -123,24 +146,29 @@ namespace BlackGui bool CStyleSheetUtility::updateFonts(const QFont &font) { - const QString indent(" "); - QString fontStyleSheet; - fontStyleSheet.append(indent).append("font-family: \"").append(font.family()).append("\";\n"); - fontStyleSheet.append(indent).append("font-size: "); + QString fs; if (font.pixelSize() >= 0) { - fontStyleSheet.append(font.pixelSize()).append("px\n"); + fs.append(font.pixelSize()).append("px"); } else { - fontStyleSheet.append(QString::number(font.pointSizeF())).append("pt;\n"); + fs.append(QString::number(font.pointSizeF())).append("pt"); } - fontStyleSheet.append(indent).append("font-style: ").append(fontStyleAsString(font)).append(";\n"); - fontStyleSheet.append(indent).append("font-weight: ").append(fontWeightAsString(font)).append(";\n"); - qDebug() << fontStyleSheet; + return updateFonts(font.family(), fs, fontStyleAsString(font), fontWeightAsString(font), "white"); + } + + bool CStyleSheetUtility::updateFonts(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor) + { + const QString indent(" "); + QString fontStyleSheet; + fontStyleSheet.append(indent).append("font-family: \"").append(fontFamily).append("\";\n"); + fontStyleSheet.append(indent).append("font-size: ").append(fontSize).append(";\n"); + fontStyleSheet.append(indent).append("font-style: ").append(fontStyle).append(";\n"); + fontStyleSheet.append(indent).append("font-weight: ").append(fontWeight).append(";\n"); + fontStyleSheet.append(indent).append("color: ").append(fontColor).append(";\n"); QString qss("QWidget {\n"); - qss.append(indent).append("color: white;\n"); qss.append(fontStyleSheet); qss.append("}\n"); @@ -156,6 +184,34 @@ namespace BlackGui return ok; } + QString CStyleSheetUtility::fontStyle(const QString &combinedStyleAndWeight) + { + static const QString n("normal"); + QString c = combinedStyleAndWeight.toLower(); + foreach(QString s, fontStyles()) + { + if (c.contains(s)) + { + return s; + } + } + return n; + } + + QString CStyleSheetUtility::fontWeight(const QString &combinedStyleAndWeight) + { + static const QString n("normal"); + QString c = combinedStyleAndWeight.toLower(); + foreach(QString w, fontWeights()) + { + if (c.contains(w)) + { + return w; + } + } + return n; + } + QString CStyleSheetUtility::qssDirectory() { QString dirPath = QCoreApplication::applicationDirPath(); diff --git a/src/blackgui/stylesheetutility.h b/src/blackgui/stylesheetutility.h index ccc02e7eb..ffc09df8b 100644 --- a/src/blackgui/stylesheetutility.h +++ b/src/blackgui/stylesheetutility.h @@ -15,6 +15,7 @@ #include #include #include +#include namespace BlackGui { @@ -40,6 +41,18 @@ namespace BlackGui //! Update the fonts bool updateFonts(const QFont &font); + //! Update the fonts + bool updateFonts(const QString &fontFamily, const QString &fontSize, const QString &fontStyle, const QString &fontWeight, const QString &fontColor); + + //! Current font color from style sheet + QString fontColor(); + + //! Get the font style + static QString fontStyle(const QString &combinedStyleAndWeight); + + //! Get the font weight + static QString fontWeight(const QString &combinedStyleAndWeight); + //! Central reader static CStyleSheetUtility &instance() { @@ -82,9 +95,32 @@ namespace BlackGui return f; } + //! Font weights + static const QStringList &fontWeights() + { + static const QStringList w( {"bold", "semibold", "light", "black", "normal"}); + return w; + } + + //! Font styles + static const QStringList &fontStyles() + { + static const QStringList s( {"italic", "oblique", "normal"}); + return s; + } + //! qss directory static QString qssDirectory(); + //! Font style as string + static const QString &fontStyleAsString(const QFont &font); + + //! Font weight as string + static const QString &fontWeightAsString(const QFont &font); + + //! Font as combined weight and style + static QString fontAsCombinedWeightStyle(const QFont &font); + signals: //! Sheets have been changed void styleSheetsChanged(); @@ -94,12 +130,6 @@ namespace BlackGui //! Constructor explicit CStyleSheetUtility(QObject *parent = nullptr); - - //! Font style as string - static const QString &fontStyleAsString(const QFont &font); - - //! Font weight as string - static const QString &fontWeightAsString(const QFont &font); }; } diff --git a/src/swiftgui_standard/mainwindow_menus.cpp b/src/swiftgui_standard/mainwindow_menus.cpp index 1b9c99ee0..ef4d90e91 100644 --- a/src/swiftgui_standard/mainwindow_menus.cpp +++ b/src/swiftgui_standard/mainwindow_menus.cpp @@ -49,20 +49,8 @@ void MainWindow::ps_onMenuClicked() } else if (sender == this->ui->menu_FileFont) { - // KB: There seems to be a bug with the font Dialog (Win 7/32), it only works once - // Then the font cannot be changed anymore - bool ok = false; - QFont font = QFontDialog::getFont(&ok, this->font(), this, "Application fonts", QFontDialog::ProportionalFonts); - if (ok) - { - // the user clicked OK and font is set to the font the user selected - this->setFont(font); - CStyleSheetUtility::instance().updateFonts(font); - } - else - { - // the user canceled the dialog; font is set to the initial - } + this->ps_setMainPage(MainPageFoo); + this->ui->comp_MainInfoArea->selectSettingsTab(BlackGui::Components::CSettingsComponent::SettingTabGui); } else if (sender == this->ui->menu_FileClose) {