diff --git a/cockatrice/src/interface/theme_manager.cpp b/cockatrice/src/interface/theme_manager.cpp index 7d6207cc8..b23f461aa 100644 --- a/cockatrice/src/interface/theme_manager.cpp +++ b/cockatrice/src/interface/theme_manager.cpp @@ -92,9 +92,12 @@ struct PaletteColorInfo ThemeManager::ThemeManager(QObject *parent) : QObject(parent) { defaultStyleName = qApp->style()->objectName(); - //! \todo Workaround for windows11 style being broken. - if (defaultStyleName == "windows11") { - defaultStyleName = "windowsvista"; + // On Windows, Qt may report the legacy "windowsvista" style as the default. + // Prefer the modern "windows11" style when it is available; "windowsvista" + // remains selectable through the per-theme style setting. + if (defaultStyleName.compare("windowsvista", Qt::CaseInsensitive) == 0 && + QStyleFactory::keys().contains("windows11", Qt::CaseInsensitive)) { + defaultStyleName = "windows11"; } ensureThemeDirectoryExists(); #if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) @@ -273,6 +276,17 @@ void ThemeManager::setColorScheme(const QString &scheme) reloadCurrentTheme(); } +void ThemeManager::setStyleName(const QString &styleName) +{ + const QString dirPath = getAvailableThemes().value(SettingsCache::instance().getThemeName()); + ThemeConfig cfg = ThemeConfig::fromThemeDir(dirPath); + + cfg.styleName = styleName; + + 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 f5158f4d0..32056f30e 100644 --- a/cockatrice/src/interface/theme_manager.h +++ b/cockatrice/src/interface/theme_manager.h @@ -81,6 +81,7 @@ public: static PaletteConfig loadDefaultPaletteConfig(const QString &themeDirPath, const QString &themeName, const QString &colorScheme); void setColorScheme(const QString &scheme); + void setStyleName(const QString &styleName); void reloadCurrentTheme(); void previewPalette(const PaletteConfig &cfg, const QString &scheme); 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 e00484ebf..17ca9380d 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() @@ -47,6 +48,19 @@ AppearanceSettingsPage::AppearanceSettingsPage() connect(&schemeCombo, &QComboBox::currentIndexChanged, this, [this] { themeManager->setColorScheme(schemeCombo.currentData().toString()); }); + // Qt widget style; "Default" lets the application decide + styleCombo.addItem(tr("Default"), QStringLiteral("Default")); + for (const QString &key : QStyleFactory::keys()) { + styleCombo.addItem(key, key); + } + + const QString currentStyle = cfg.styleName; + const int styleSeedIdx = currentStyle.isEmpty() ? 0 : styleCombo.findData(currentStyle); + styleCombo.setCurrentIndex(styleSeedIdx >= 0 ? styleSeedIdx : 0); + + connect(&styleCombo, &QComboBox::currentIndexChanged, this, + [this] { themeManager->setStyleName(styleCombo.currentData().toString()); }); + connect(themeManager, &ThemeManager::themeChanged, this, [this, dirPath] { const QString newDir = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName()); const ThemeConfig cfg = ThemeConfig::fromThemeDir(newDir); @@ -56,6 +70,12 @@ AppearanceSettingsPage::AppearanceSettingsPage() const int idx = schemeCombo.findData(current); schemeCombo.setCurrentIndex(idx >= 0 ? idx : 0); schemeCombo.blockSignals(false); + + styleCombo.blockSignals(true); + const QString currentStyle = cfg.styleName; + const int styleIdx = currentStyle.isEmpty() ? 0 : styleCombo.findData(currentStyle); + styleCombo.setCurrentIndex(styleIdx >= 0 ? styleIdx : 0); + styleCombo.blockSignals(false); }); connect(&editPaletteButton, &QPushButton::clicked, this, &AppearanceSettingsPage::editPalette); @@ -66,7 +86,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(&styleComboLabel, 3, 0); + themeGrid->addWidget(&styleCombo, 3, 1); + themeGrid->addWidget(&editPaletteButton, 4, 1); themeGroupBox = new QGroupBox; themeGroupBox->setLayout(themeGrid); @@ -400,6 +422,8 @@ void AppearanceSettingsPage::retranslateUi() themeLabel.setText(tr("Current theme:")); openThemeButton.setText(tr("Open themes folder")); schemeComboLabel.setText(tr("Active theme palette:")); + styleComboLabel.setText(tr("Active theme style:")); + styleCombo.setToolTip(tr("Qt widget style saved to this theme (\"Default\" lets the application decide)")); 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 e223d70f8..09b73ad04 100644 --- a/cockatrice/src/interface/widgets/settings_page/appearance_settings_page.h +++ b/cockatrice/src/interface/widgets/settings_page/appearance_settings_page.h @@ -31,6 +31,8 @@ private: QPushButton openThemeButton; QLabel schemeComboLabel; QComboBox schemeCombo; + QLabel styleComboLabel; + QComboBox styleCombo; QPushButton editPaletteButton; QLabel homeTabBackgroundSourceLabel; QComboBox homeTabBackgroundSourceBox;