From ccf5f6a3d827172bb97359d3699bb19de3be8c3d Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Mon, 28 Oct 2024 13:00:39 -0400 Subject: [PATCH] Added custom theme file selection dialog --- scwx-qt/source/scwx/qt/main/main.cpp | 16 +- .../scwx/qt/settings/general_settings.cpp | 9 + .../scwx/qt/settings/general_settings.hpp | 1 + scwx-qt/source/scwx/qt/types/qt_types.cpp | 3 + scwx-qt/source/scwx/qt/types/qt_types.hpp | 3 +- scwx-qt/source/scwx/qt/ui/settings_dialog.cpp | 41 ++ scwx-qt/source/scwx/qt/ui/settings_dialog.ui | 460 ++++++++++-------- 7 files changed, 311 insertions(+), 222 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index 11b7f098..05b7c933 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -166,14 +166,20 @@ static void ConfigureTheme(const std::vector& args) QGuiApplication::styleHints()->setColorScheme(qtColorScheme); - std::optional paletteFile = - scwx::qt::types::GetQtPaletteFile(uiStyle); + std::optional paletteFile; + if (uiStyle == scwx::qt::types::UiStyle::FusionCustom) { + paletteFile = generalSettings.theme_file().GetValue(); + } + else + { + paletteFile = scwx::qt::types::GetQtPaletteFile(uiStyle); + } + if (paletteFile) { QPalette defaultPalette = QApplication::style()->standardPalette(); - QPalette palette = - Qt6CT::loadColorScheme(QString::fromStdString(*paletteFile), - defaultPalette); + QPalette palette = Qt6CT::loadColorScheme( + QString::fromStdString(*paletteFile), defaultPalette); if (defaultPalette == palette) { diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.cpp b/scwx-qt/source/scwx/qt/settings/general_settings.cpp index fe3982e2..9eca4348 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.cpp @@ -73,6 +73,7 @@ public: showMapCenter_.SetDefault(false); showMapLogo_.SetDefault(true); theme_.SetDefault(defaultThemeValue); + themeFile_.SetDefault(""); trackLocation_.SetDefault(false); updateNotificationsEnabled_.SetDefault(true); warningsProvider_.SetDefault(defaultWarningsProviderValue); @@ -161,6 +162,7 @@ public: SettingsVariable showMapCenter_ {"show_map_center"}; SettingsVariable showMapLogo_ {"show_map_logo"}; SettingsVariable theme_ {"theme"}; + SettingsVariable themeFile_ {"theme_file"}; SettingsVariable trackLocation_ {"track_location"}; SettingsVariable updateNotificationsEnabled_ {"update_notifications"}; SettingsVariable warningsProvider_ {"warnings_provider"}; @@ -193,6 +195,7 @@ GeneralSettings::GeneralSettings() : &p->showMapCenter_, &p->showMapLogo_, &p->theme_, + &p->themeFile_, &p->trackLocation_, &p->updateNotificationsEnabled_, &p->warningsProvider_}); @@ -325,6 +328,11 @@ SettingsVariable& GeneralSettings::theme() const return p->theme_; } +SettingsVariable& GeneralSettings::theme_file() const +{ + return p->themeFile_; +} + SettingsVariable& GeneralSettings::track_location() const { return p->trackLocation_; @@ -385,6 +393,7 @@ bool operator==(const GeneralSettings& lhs, const GeneralSettings& rhs) lhs.p->showMapCenter_ == rhs.p->showMapCenter_ && lhs.p->showMapLogo_ == rhs.p->showMapLogo_ && lhs.p->theme_ == rhs.p->theme_ && + lhs.p->themeFile_ == rhs.p->themeFile_ && lhs.p->trackLocation_ == rhs.p->trackLocation_ && lhs.p->updateNotificationsEnabled_ == rhs.p->updateNotificationsEnabled_ && diff --git a/scwx-qt/source/scwx/qt/settings/general_settings.hpp b/scwx-qt/source/scwx/qt/settings/general_settings.hpp index 2628aef1..3e527238 100644 --- a/scwx-qt/source/scwx/qt/settings/general_settings.hpp +++ b/scwx-qt/source/scwx/qt/settings/general_settings.hpp @@ -49,6 +49,7 @@ public: SettingsVariable& show_map_center() const; SettingsVariable& show_map_logo() const; SettingsVariable& theme() const; + SettingsVariable& theme_file() const; SettingsVariable& track_location() const; SettingsVariable& update_notifications_enabled() const; SettingsVariable& warnings_provider() const; diff --git a/scwx-qt/source/scwx/qt/types/qt_types.cpp b/scwx-qt/source/scwx/qt/types/qt_types.cpp index 5e5a96a7..0c10feb2 100644 --- a/scwx-qt/source/scwx/qt/types/qt_types.cpp +++ b/scwx-qt/source/scwx/qt/types/qt_types.cpp @@ -21,6 +21,7 @@ static const std::unordered_map qtStyleName_ { {UiStyle::FusionIaOra, "Fusion"}, {UiStyle::FusionSand, "Fusion"}, {UiStyle::FusionWaves, "Fusion"}, + {UiStyle::FusionCustom, "Fusion"}, {UiStyle::Unknown, "?"}}; static const std::unordered_map uiStyleName_ { @@ -34,6 +35,7 @@ static const std::unordered_map uiStyleName_ { {UiStyle::FusionIaOra, "Fusion IA Ora"}, {UiStyle::FusionSand, "Fusion Sand"}, {UiStyle::FusionWaves, "Fusion Waves"}, + {UiStyle::FusionCustom, "Fusion Custom"}, {UiStyle::Unknown, "?"}}; static const std::unordered_map qtColorSchemeMap_ { @@ -47,6 +49,7 @@ static const std::unordered_map qtColorSchemeMap_ { {UiStyle::FusionIaOra, Qt::ColorScheme::Unknown}, {UiStyle::FusionSand, Qt::ColorScheme::Unknown}, {UiStyle::FusionWaves, Qt::ColorScheme::Unknown}, + {UiStyle::FusionCustom, Qt::ColorScheme::Unknown}, {UiStyle::Unknown, Qt::ColorScheme::Unknown}}; static const std::unordered_map paletteFile_ { diff --git a/scwx-qt/source/scwx/qt/types/qt_types.hpp b/scwx-qt/source/scwx/qt/types/qt_types.hpp index 9bb7ed5d..b5779ff1 100644 --- a/scwx-qt/source/scwx/qt/types/qt_types.hpp +++ b/scwx-qt/source/scwx/qt/types/qt_types.hpp @@ -33,9 +33,10 @@ enum class UiStyle FusionIaOra, FusionSand, FusionWaves, + FusionCustom, Unknown }; -typedef scwx::util::Iterator +typedef scwx::util::Iterator UiStyleIterator; Qt::ColorScheme GetQtColorScheme(UiStyle uiStyle); diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp index d4f4f096..20616204 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.cpp @@ -121,6 +121,7 @@ public: &mapboxApiKey_, &mapTilerApiKey_, &theme_, + &themeFile_, &defaultAlertAction_, &clockFormat_, &customStyleDrawLayer_, @@ -242,6 +243,7 @@ public: settings::SettingsInterface nmeaBaudRate_ {}; settings::SettingsInterface nmeaSource_ {}; settings::SettingsInterface theme_ {}; + settings::SettingsInterface themeFile_ {}; settings::SettingsInterface warningsProvider_ {}; settings::SettingsInterface antiAliasingEnabled_ {}; settings::SettingsInterface showMapAttribution_ {}; @@ -526,6 +528,45 @@ void SettingsDialogImpl::SetupGeneralTab() types::GetUiStyleName); theme_.SetResetButton(self_->ui->resetThemeButton); + themeFile_.SetSettingsVariable(generalSettings.theme_file()); + themeFile_.SetEditWidget(self_->ui->themeFileLineEdit); + themeFile_.SetResetButton(self_->ui->resetThemeFileButton); + //themeFile_.EnableTrimming(); + + QObject::connect( + self_->ui->themeFileSelectButton, + &QAbstractButton::clicked, + self_, + [this]() + { + static const std::string themeFilter = "Qt6Ct Theme File (*.conf)"; + static const std::string allFilter = "All Files (*)"; + + QFileDialog* dialog = new QFileDialog(self_); + + dialog->setFileMode(QFileDialog::ExistingFile); + + dialog->setNameFilters( + {QObject::tr(themeFilter.c_str()), QObject::tr(allFilter.c_str())}); + dialog->setAttribute(Qt::WA_DeleteOnClose); + + QObject::connect( + dialog, + &QFileDialog::fileSelected, + self_, + [this](const QString& file) + { + QString path = QDir::toNativeSeparators(file); + logger_->info("Selected theme file: {}", path.toStdString()); + self_->ui->themeFileLineEdit->setText(path); + + // setText dows not emit the textEdited signal + Q_EMIT self_->ui->themeFileLineEdit->textEdited(path); + }); + + dialog->open(); + }); + auto radarSites = config::RadarSite::GetAll(); // Sort radar sites by ID diff --git a/scwx-qt/source/scwx/qt/ui/settings_dialog.ui b/scwx-qt/source/scwx/qt/ui/settings_dialog.ui index 444e6705..f66aba6c 100644 --- a/scwx-qt/source/scwx/qt/ui/settings_dialog.ui +++ b/scwx-qt/source/scwx/qt/ui/settings_dialog.ui @@ -135,9 +135,9 @@ 0 - 0 - 513 - 622 + -133 + 511 + 676 @@ -159,15 +159,39 @@ 0 - - + + - MapTiler API Key + ... - - + + + + Mapbox API Key + + + + + + + Custom Map Layer + + + + + + + + + + GPS Plugin + + + + + ... @@ -180,15 +204,18 @@ - - + + + + + - Default Time Zone + ... - - + + ... @@ -198,30 +225,34 @@ - - - - - - - ... - - - - :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg - - - - - - - Map Provider - - - + + + + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + + + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + + @@ -233,77 +264,9 @@ - - - - - - - - - - ... - - - - - - - QLineEdit::EchoMode::Password - - - - - - - GPS Plugin - - - - - - - GPS Baud Rate - - - - - - - - - - ... - - - - - - - ... - - - - :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg - - - - - - - Grid Width - - - - - - - - - @@ -311,9 +274,16 @@ - + + + + + Warnings Provider + + + @@ -339,8 +309,8 @@ - - + + ... @@ -350,45 +320,66 @@ - - - - Theme + + + + 1 + + + 999999999 - - - - ... - - - - :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg - - - - - - - Mapbox API Key - - - - - - - Clock Format - - - - - + + QLineEdit::EchoMode::Password + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + + + + + + + + + GPS Baud Rate + + + + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + + + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + + @@ -400,8 +391,8 @@ - - + + ... @@ -411,35 +402,56 @@ + + + + Map Provider + + + + + + + + + + Theme + + + + + + + MapTiler API Key + + + + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + + + + + + + + + Custom Map URL + + + - - - - Warnings Provider - - - - - - - 1 - - - 999999999 - - - - - - - Default Alert Action - - - - - + + ... @@ -449,6 +461,38 @@ + + + + Clock Format + + + + + + + ... + + + + :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg + + + + + + + Grid Width + + + + + + + QLineEdit::EchoMode::Password + + + @@ -460,61 +504,45 @@ - - + + + + Default Time Zone + + + + + + + Default Alert Action + + + + + + + + + + + + + Theme File + + + + + + + + ... - - - :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg - - - - - ... - - - - :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg - - - - - - - - - - - - - Custom Map URL - - - - - - - Custom Map Layer - - - - - - - ... - - - - :/res/icons/font-awesome-6/rotate-left-solid.svg:/res/icons/font-awesome-6/rotate-left-solid.svg - - - - - + + ... @@ -610,8 +638,8 @@ 0 0 - 506 - 383 + 98 + 28