From 79bb8a957221a343f99135515bf57ae64338e2f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Fri, 19 Jun 2026 13:25:57 +0200 Subject: [PATCH] Add style comboBox Took 12 minutes Took 3 seconds Took 2 minutes --- cockatrice/src/interface/theme_manager.cpp | 35 +++++++++++++ cockatrice/src/interface/theme_manager.h | 2 + .../appearance_settings_page.cpp | 52 +++++++++++++------ .../settings_page/appearance_settings_page.h | 3 ++ 4 files changed, 75 insertions(+), 17 deletions(-) diff --git a/cockatrice/src/interface/theme_manager.cpp b/cockatrice/src/interface/theme_manager.cpp index 95623276b..7d841c3be 100644 --- a/cockatrice/src/interface/theme_manager.cpp +++ b/cockatrice/src/interface/theme_manager.cpp @@ -188,6 +188,41 @@ QStringMap &ThemeManager::getAvailableThemes() return availableThemes; } +ThemeConfig ThemeManager::effectiveThemeConfig(const QString &themeName) +{ + const QString dirPath = ThemeManager().getAvailableThemes().value(themeName); + const QString userDirPath = userThemeDirFor(themeName); + + ThemeConfig userCfg = ThemeConfig::fromThemeDir(userDirPath); + ThemeConfig systemCfg = ThemeConfig::fromThemeDir(dirPath); + + ThemeConfig result = systemCfg; + + // User values override system values on a per-field basis + if (!userCfg.colorScheme.isEmpty()) { + result.colorScheme = userCfg.colorScheme; + } + + if (!userCfg.styleName.isEmpty()) { + result.styleName = userCfg.styleName; + } + + return result; +} + +void ThemeManager::setStyleName(const QString &styleName) +{ + const QString themeName = SettingsCache::instance().getThemeName(); + const QString dirPath = getAvailableThemes().value(themeName); + const QString userDirPath = userThemeDirFor(themeName); + + ThemeConfig cfg = ThemeConfig::fromThemeDir(dirPath); + cfg.styleName = styleName; + cfg.save(userDirPath); + + reloadCurrentTheme(); +} + QBrush ThemeManager::loadBrush(QString fileName, QColor fallbackColor) { QBrush brush; diff --git a/cockatrice/src/interface/theme_manager.h b/cockatrice/src/interface/theme_manager.h index 7091a26e5..64a021bfc 100644 --- a/cockatrice/src/interface/theme_manager.h +++ b/cockatrice/src/interface/theme_manager.h @@ -66,6 +66,8 @@ public: static bool isDarkMode(const QString &themeDirPath, const QString &userDirPath = {}); static QString userThemeDirFor(const QString &themeName); QStringMap &getAvailableThemes(); + ThemeConfig effectiveThemeConfig(const QString &themeName); + void setStyleName(const QString &styleName); // Returns the path to the currently active theme directory (empty = default) QString getCurrentThemePath() const { diff --git a/cockatrice/src/interface/widgets/settings_page/appearance_settings_page.cpp b/cockatrice/src/interface/widgets/settings_page/appearance_settings_page.cpp index 2d32f3ce1..78a171c0b 100644 --- a/cockatrice/src/interface/widgets/settings_page/appearance_settings_page.cpp +++ b/cockatrice/src/interface/widgets/settings_page/appearance_settings_page.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include AppearanceSettingsPage::AppearanceSettingsPage() @@ -31,32 +32,33 @@ AppearanceSettingsPage::AppearanceSettingsPage() connect(&themeBox, qOverload(&QComboBox::currentIndexChanged), this, &AppearanceSettingsPage::themeBoxChanged); connect(&openThemeButton, &QPushButton::clicked, this, &AppearanceSettingsPage::openThemeLocation); + // Populate Scheme + schemeCombo.addItem(tr("Light"), QStringLiteral("Light")); schemeCombo.addItem(tr("Dark"), QStringLiteral("Dark")); #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) schemeCombo.addItem(tr("System"), QStringLiteral("System")); #endif - // Seed from whatever the current theme already has saved - const QString dirPath = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName()); - const ThemeConfig cfg = ThemeConfig::fromThemeDir(dirPath); - const QString current = cfg.colorScheme; - const int seedIdx = schemeCombo.findData(current); - schemeCombo.setCurrentIndex(seedIdx >= 0 ? seedIdx : 0); - connect(&schemeCombo, &QComboBox::currentIndexChanged, this, [this] { themeManager->setColorScheme(schemeCombo.currentData().toString()); }); - connect(themeManager, &ThemeManager::themeChanged, this, [this, dirPath] { - const QString newDir = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName()); - const ThemeConfig cfg = ThemeConfig::fromThemeDir(newDir); - const QString current = cfg.colorScheme; + // Populate Style - schemeCombo.blockSignals(true); - const int idx = schemeCombo.findData(current); - schemeCombo.setCurrentIndex(idx >= 0 ? idx : 0); - schemeCombo.blockSignals(false); - }); + styleComboBox.addItem(tr("Default"), QString()); + + for (const QString &style : QStyleFactory::keys()) { + styleComboBox.addItem(style, style); + } + + connect(&styleComboBox, &QComboBox::currentIndexChanged, this, + [this] { themeManager->setStyleName(styleComboBox.currentData().toString()); }); + + // Refresh theme and style + + reloadThemeSettings(); + + connect(themeManager, &ThemeManager::themeChanged, this, &AppearanceSettingsPage::reloadThemeSettings); connect(&editPaletteButton, &QPushButton::clicked, this, &AppearanceSettingsPage::editPalette); @@ -66,7 +68,9 @@ AppearanceSettingsPage::AppearanceSettingsPage() themeGrid->addWidget(&openThemeButton, 1, 1); themeGrid->addWidget(&schemeComboLabel, 2, 0); themeGrid->addWidget(&schemeCombo, 2, 1); - themeGrid->addWidget(&editPaletteButton, 3, 1); + themeGrid->addWidget(&styleLabel, 3, 0); + themeGrid->addWidget(&styleComboBox, 3, 1); + themeGrid->addWidget(&editPaletteButton, 4, 1); themeGroupBox = new QGroupBox; themeGroupBox->setLayout(themeGrid); @@ -320,6 +324,19 @@ void AppearanceSettingsPage::openThemeLocation() } } +void AppearanceSettingsPage::reloadThemeSettings() +{ + const ThemeConfig cfg = themeManager->effectiveThemeConfig(SettingsCache::instance().getThemeName()); + + schemeCombo.blockSignals(true); + schemeCombo.setCurrentIndex(std::max(0, schemeCombo.findData(cfg.colorScheme))); + schemeCombo.blockSignals(false); + + styleComboBox.blockSignals(true); + styleComboBox.setCurrentIndex(qMax(0, styleComboBox.findData(cfg.styleName))); + styleComboBox.blockSignals(false); +} + void AppearanceSettingsPage::editPalette() { PaletteEditorDialog dlg(themeManager->getCurrentThemePath(), SettingsCache::instance().getThemeName(), this); @@ -390,6 +407,7 @@ void AppearanceSettingsPage::retranslateUi() themeLabel.setText(tr("Current theme:")); openThemeButton.setText(tr("Open themes folder")); schemeComboLabel.setText(tr("Active theme palette:")); + styleLabel.setText(tr("Active theme style:")); editPaletteButton.setText(tr("Edit theme palette")); homeTabGroupBox->setTitle(tr("Home tab settings")); diff --git a/cockatrice/src/interface/widgets/settings_page/appearance_settings_page.h b/cockatrice/src/interface/widgets/settings_page/appearance_settings_page.h index 9ed27be4d..be2b3da42 100644 --- a/cockatrice/src/interface/widgets/settings_page/appearance_settings_page.h +++ b/cockatrice/src/interface/widgets/settings_page/appearance_settings_page.h @@ -17,6 +17,7 @@ class AppearanceSettingsPage : public AbstractSettingsPage private slots: void themeBoxChanged(int index); void openThemeLocation(); + void reloadThemeSettings(); void editPalette(); void updateHomeTabSettingsVisibility(); void showShortcutsChanged(QT_STATE_CHANGED_T enabled); @@ -31,6 +32,8 @@ private: QPushButton openThemeButton; QLabel schemeComboLabel; QComboBox schemeCombo; + QLabel styleLabel; + QComboBox styleComboBox; QPushButton editPaletteButton; QLabel homeTabBackgroundSourceLabel; QComboBox homeTabBackgroundSourceBox;