From 7ed0dadaf8929fe9d49037c2b6d59da848e3c37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sun, 17 May 2026 10:04:08 +0200 Subject: [PATCH] Add a combo box to quick switch settings. Took 19 minutes --- cockatrice/src/interface/theme_manager.cpp | 11 +++++ cockatrice/src/interface/theme_manager.h | 1 + .../widgets/dialogs/dlg_settings.cpp | 45 ++++++++++++++++--- .../interface/widgets/dialogs/dlg_settings.h | 2 + 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/cockatrice/src/interface/theme_manager.cpp b/cockatrice/src/interface/theme_manager.cpp index 1bfe5359f..abdc02eef 100644 --- a/cockatrice/src/interface/theme_manager.cpp +++ b/cockatrice/src/interface/theme_manager.cpp @@ -242,6 +242,17 @@ bool ThemeManager::savePaletteConfig(const QString &themeDirPath, const QString return true; } +void ThemeManager::setColorScheme(const QString &scheme) +{ + const QString dirPath = getAvailableThemes().value(SettingsCache::instance().getThemeName()); + ThemeConfig cfg = ThemeConfig::fromThemeDir(dirPath); + + cfg.colorScheme = scheme; + + cfg.save(dirPath); + reloadCurrentTheme(); +} + void ThemeManager::reloadCurrentTheme() { themeChangedSlot(); diff --git a/cockatrice/src/interface/theme_manager.h b/cockatrice/src/interface/theme_manager.h index 6067b7e62..4b1fd2026 100644 --- a/cockatrice/src/interface/theme_manager.h +++ b/cockatrice/src/interface/theme_manager.h @@ -76,6 +76,7 @@ public: // Load/save per-scheme palette colors static PaletteConfig loadPaletteConfig(const QString &themeDirPath, const QString &colorScheme); static bool savePaletteConfig(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg); + void setColorScheme(const QString &scheme); void reloadCurrentTheme(); void previewPalette(const PaletteConfig &cfg, const QString &scheme); diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp index 907ee43fe..4323ed724 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp @@ -433,6 +433,34 @@ AppearanceSettingsPage::AppearanceSettingsPage() connect(&themeBox, qOverload(&QComboBox::currentIndexChanged), this, &AppearanceSettingsPage::themeBoxChanged); connect(&openThemeButton, &QPushButton::clicked, this, &AppearanceSettingsPage::openThemeLocation); + + 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; + + schemeCombo.blockSignals(true); + const int idx = schemeCombo.findData(current); + schemeCombo.setCurrentIndex(idx >= 0 ? idx : 0); + schemeCombo.blockSignals(false); + }); + connect(&editPaletteButton, &QPushButton::clicked, this, &AppearanceSettingsPage::editPalette); for (const auto &entry : BackgroundSources::all()) { @@ -468,13 +496,15 @@ AppearanceSettingsPage::AppearanceSettingsPage() themeGrid->addWidget(&themeLabel, 0, 0); themeGrid->addWidget(&themeBox, 0, 1); themeGrid->addWidget(&openThemeButton, 1, 1); - themeGrid->addWidget(&editPaletteButton, 2, 1); - themeGrid->addWidget(&homeTabBackgroundSourceLabel, 3, 0); - themeGrid->addWidget(&homeTabBackgroundSourceBox, 3, 1); - themeGrid->addWidget(&homeTabBackgroundShuffleFrequencyLabel, 4, 0); - themeGrid->addWidget(&homeTabBackgroundShuffleFrequencySpinBox, 4, 1); - themeGrid->addWidget(&homeTabDisplayCardNameLabel, 5, 0); - themeGrid->addWidget(&homeTabDisplayCardNameCheckBox, 5, 1); + themeGrid->addWidget(&schemeComboLabel, 2, 0); + themeGrid->addWidget(&schemeCombo, 2, 1); + themeGrid->addWidget(&editPaletteButton, 3, 1); + themeGrid->addWidget(&homeTabBackgroundSourceLabel, 4, 0); + themeGrid->addWidget(&homeTabBackgroundSourceBox, 4, 1); + themeGrid->addWidget(&homeTabBackgroundShuffleFrequencyLabel, 5, 0); + themeGrid->addWidget(&homeTabBackgroundShuffleFrequencySpinBox, 5, 1); + themeGrid->addWidget(&homeTabDisplayCardNameLabel, 6, 0); + themeGrid->addWidget(&homeTabDisplayCardNameCheckBox, 6, 1); themeGroupBox = new QGroupBox; themeGroupBox->setLayout(themeGrid); @@ -743,6 +773,7 @@ void AppearanceSettingsPage::retranslateUi() themeGroupBox->setTitle(tr("Theme settings")); themeLabel.setText(tr("Current theme:")); openThemeButton.setText(tr("Open themes folder")); + schemeComboLabel.setText(tr("Active theme palette")); editPaletteButton.setText(tr("Edit theme palette")); homeTabBackgroundSourceLabel.setText(tr("Home tab background source:")); homeTabBackgroundShuffleFrequencyLabel.setText(tr("Home tab background shuffle frequency:")); diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_settings.h b/cockatrice/src/interface/widgets/dialogs/dlg_settings.h index 283aeb541..86266347f 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_settings.h +++ b/cockatrice/src/interface/widgets/dialogs/dlg_settings.h @@ -115,6 +115,8 @@ private: QLabel themeLabel; QComboBox themeBox; QPushButton openThemeButton; + QLabel schemeComboLabel; + QComboBox schemeCombo; QPushButton editPaletteButton; QLabel homeTabBackgroundSourceLabel; QComboBox homeTabBackgroundSourceBox;