diff --git a/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp b/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp index 7dd47d587..2e90f6668 100644 --- a/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp +++ b/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp @@ -176,8 +176,8 @@ void PaletteEditorDialog::retranslateUi() titleLabel->setText(tr("Palette Editor  ·  %1").arg(themeName)); // Revert button only makes sense when the theme ships default palette files - const bool hasDefault = PaletteConfig::fromDefault(themeDirPath, "Light").hasPalette() || - PaletteConfig::fromDefault(themeDirPath, "Dark").hasPalette(); + const bool hasDefault = ThemeManager::loadDefaultPaletteConfig(themeDirPath, themeName, "Light").hasPalette() || + ThemeManager::loadDefaultPaletteConfig(themeDirPath, themeName, "Dark").hasPalette(); revertButton->setEnabled(hasDefault); if (!hasDefault) { revertButton->setToolTip(tr("This theme ships no default palette files")); @@ -211,7 +211,7 @@ void PaletteEditorDialog::loadSchemes() PaletteConfig cfg = PaletteConfig::fromScheme(themeDirPath, scheme); if (!cfg.hasPalette()) { - cfg = PaletteConfig::fromDefault(themeDirPath, scheme); + cfg = ThemeManager::loadDefaultPaletteConfig(themeDirPath, themeName, scheme); } if (!cfg.hasPalette()) { @@ -309,7 +309,7 @@ void PaletteEditorDialog::onReset() void PaletteEditorDialog::onRevertToDefault() { - PaletteConfig def = PaletteConfig::fromDefault(themeDirPath, loadedScheme); + PaletteConfig def = ThemeManager::loadDefaultPaletteConfig(themeDirPath, themeName, loadedScheme); if (!def.hasPalette()) { QMessageBox::information(this, tr("No default found"), tr("No default palette file found for the \"%1\" scheme.").arg(loadedScheme)); diff --git a/cockatrice/src/interface/theme_manager.cpp b/cockatrice/src/interface/theme_manager.cpp index 7dc757062..7d6207cc8 100644 --- a/cockatrice/src/interface/theme_manager.cpp +++ b/cockatrice/src/interface/theme_manager.cpp @@ -137,6 +137,20 @@ bool ThemeManager::isBuiltInTheme() return themeName == NONE_THEME_NAME || themeName == FUSION_THEME_NAME; } +// System (read-only) themes location, relative to the application binary. +static QString systemThemesBasePath() +{ + QString base = qApp->applicationDirPath(); +#ifdef Q_OS_MAC + base += "/../Resources/themes"; +#elif defined(Q_OS_WIN) + base += "/themes"; +#else // linux + base += "/../share/cockatrice/themes"; +#endif + return base; +} + QStringMap &ThemeManager::getAvailableThemes() { QDir dir; @@ -157,15 +171,7 @@ QStringMap &ThemeManager::getAvailableThemes() } // load themes from cockatrice system dir - dir.setPath(qApp->applicationDirPath() + -#ifdef Q_OS_MAC - "/../Resources/themes" -#elif defined(Q_OS_WIN) - "/themes" -#else // linux - "/../share/cockatrice/themes" -#endif - ); + dir.setPath(systemThemesBasePath()); for (QString themeName : dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name)) { if (!availableThemes.contains(themeName)) { @@ -242,6 +248,20 @@ bool ThemeManager::savePaletteConfig(const QString &themeDirPath, const QString return true; } +PaletteConfig ThemeManager::loadDefaultPaletteConfig(const QString &themeDirPath, + const QString &themeName, + const QString &colorScheme) +{ + PaletteConfig cfg = PaletteConfig::fromDefault(themeDirPath, colorScheme); + if (!cfg.hasPalette()) { + // The shipped default may live in the system theme directory rather + // than the resolved (user) theme directory, so built-in themes still + // get their curated defaults. + cfg = PaletteConfig::fromDefault(QDir(systemThemesBasePath()).absoluteFilePath(themeName), colorScheme); + } + return cfg; +} + void ThemeManager::setColorScheme(const QString &scheme) { const QString dirPath = getAvailableThemes().value(SettingsCache::instance().getThemeName()); @@ -353,7 +373,7 @@ void ThemeManager::themeChangedSlot() // ── Load palette: custom first, then theme default ──────────────────── PaletteConfig palette = PaletteConfig::fromScheme(dirPath, activeScheme); if (!palette.hasPalette()) { - palette = PaletteConfig::fromDefault(dirPath, activeScheme); + palette = ThemeManager::loadDefaultPaletteConfig(dirPath, themeName, activeScheme); } applyStyleAndPalette(themeName, themeCfg, palette, activeScheme); diff --git a/cockatrice/src/interface/theme_manager.h b/cockatrice/src/interface/theme_manager.h index b9e764d08..f5158f4d0 100644 --- a/cockatrice/src/interface/theme_manager.h +++ b/cockatrice/src/interface/theme_manager.h @@ -76,6 +76,10 @@ 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); + // Load the theme's shipped default palette, falling back to the system + // theme directory when it is absent from the resolved (user) directory. + static PaletteConfig + loadDefaultPaletteConfig(const QString &themeDirPath, const QString &themeName, const QString &colorScheme); void setColorScheme(const QString &scheme); void reloadCurrentTheme();