diff --git a/cockatrice/src/interface/theme_manager.cpp b/cockatrice/src/interface/theme_manager.cpp index 19353b1e9..12952d70b 100644 --- a/cockatrice/src/interface/theme_manager.cpp +++ b/cockatrice/src/interface/theme_manager.cpp @@ -112,6 +112,39 @@ void ThemeManager::ensureThemeDirectoryExists() } } +bool ThemeManager::isDarkMode() +{ + auto themeName = SettingsCache::instance().getThemeName(); + // Explicit Dark Mode + if (themeName == FUSION_THEME_NAME_LIGHT || themeName.endsWith("(Light)")) { + return false; + } + // Explicit Light Mode + if (themeName == FUSION_THEME_NAME_DARK || themeName.endsWith("(Dark)")) { + return true; + } + + // Auto detection on compatible Qt versions +#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) + if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark && + (themeName == NONE_THEME_NAME || themeName == FUSION_THEME_NAME || themeName.endsWith("(System Default)"))) { + return true; + } else { + return false; + } +#endif + // Default to light mode + return false; +} + +bool ThemeManager::isBuiltInTheme() +{ + const auto themeName = SettingsCache::instance().getThemeName(); + + return themeName == NONE_THEME_NAME || themeName == FUSION_THEME_NAME || themeName == FUSION_THEME_NAME_LIGHT || + themeName == FUSION_THEME_NAME_DARK; +} + QStringMap &ThemeManager::getAvailableThemes() { QDir dir; diff --git a/cockatrice/src/interface/theme_manager.h b/cockatrice/src/interface/theme_manager.h index d942f0fef..416923128 100644 --- a/cockatrice/src/interface/theme_manager.h +++ b/cockatrice/src/interface/theme_manager.h @@ -54,6 +54,8 @@ protected: QBrush loadExtraBrush(QString fileName, QBrush &fallbackBrush); public: + bool isBuiltInTheme(); + bool isDarkMode(); QStringMap &getAvailableThemes(); QBrush &getBgBrush(Role zone); diff --git a/cockatrice/src/interface/widgets/general/home_widget.cpp b/cockatrice/src/interface/widgets/general/home_widget.cpp index ea20ef6a0..8c5d76dfc 100644 --- a/cockatrice/src/interface/widgets/general/home_widget.cpp +++ b/cockatrice/src/interface/widgets/general/home_widget.cpp @@ -2,6 +2,7 @@ #include "../../../client/settings/cache_settings.h" #include "../../../interface/widgets/tabs/tab_supervisor.h" +#include "../../theme_manager.h" #include "../../window_main.h" #include "background_sources.h" #include "home_styled_button.h" @@ -256,7 +257,7 @@ void HomeWidget::updateConnectButton(const ClientStatus status) QPair HomeWidget::extractDominantColors(const QPixmap &pixmap) { - if (SettingsCache::instance().getThemeName() == "Default" && + if (themeManager->isBuiltInTheme() && SettingsCache::instance().getHomeTabBackgroundSource() == BackgroundSources::toId(BackgroundSources::Theme)) { return QPair(QColor::fromRgb(20, 140, 60), QColor::fromRgb(120, 200, 80)); }