diff --git a/src/citron/configuration/configure_dialog.cpp b/src/citron/configuration/configure_dialog.cpp index 65e812f75..2819ffe33 100644 --- a/src/citron/configuration/configure_dialog.cpp +++ b/src/citron/configuration/configure_dialog.cpp @@ -49,13 +49,27 @@ static QScrollArea* CreateScrollArea(QWidget* widget) { return scroll_area; } -// Helper function to detect if the application is using a dark theme +// Helper function to detect if the application should be in a dark theme state static bool IsDarkMode() { - const QPalette palette = qApp->palette(); - const QColor text_color = palette.color(QPalette::WindowText); - const QColor base_color = palette.color(QPalette::Window); - // A common heuristic for dark mode is that the text color is brighter than the background - return text_color.value() > base_color.value(); + const std::string& theme_name = UISettings::values.theme; + + // Priority 1: Check for explicitly chosen dark themes. + if (theme_name == "qdarkstyle" || theme_name == "colorful_dark" || + theme_name == "qdarkstyle_midnight_blue" || theme_name == "colorful_midnight_blue") { + return true; + } + + // Priority 2: Check for adaptive themes ("default" and "colorful"). + // For these, we fall back to checking the OS palette. + if (theme_name == "default" || theme_name == "colorful") { + const QPalette palette = qApp->palette(); + const QColor text_color = palette.color(QPalette::WindowText); + const QColor base_color = palette.color(QPalette::Window); + return text_color.value() > base_color.value(); + } + + // Fallback for any other unknown theme (assumed light). + return false; } ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, @@ -99,6 +113,8 @@ rainbow_timer{new QTimer(this)} { ui->setupUi(this); + last_palette_text_color = qApp->palette().color(QPalette::WindowText); + if (!UISettings::values.configure_dialog_geometry.isEmpty()) { restoreGeometry(UISettings::values.configure_dialog_geometry); } @@ -272,6 +288,14 @@ void ConfigureDialog::changeEvent(QEvent* event) { RetranslateUI(); } + if (event->type() == QEvent::PaletteChange) { + const QColor current_color = qApp->palette().color(QPalette::WindowText); + if (current_color != last_palette_text_color) { + last_palette_text_color = current_color; + UpdateTheme(); + } + } + QDialog::changeEvent(event); } diff --git a/src/citron/configuration/configure_dialog.h b/src/citron/configuration/configure_dialog.h index 9ad6ea1f1..409dab386 100644 --- a/src/citron/configuration/configure_dialog.h +++ b/src/citron/configuration/configure_dialog.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "common/settings_enums.h" #include "citron/configuration/shared_widget.h" // <-- Correct header for Builder @@ -70,6 +71,8 @@ private: void OnLanguageChanged(const QString& locale); + QColor last_palette_text_color; + // All members are now in the EXACT correct order to match the constructor std::unique_ptr ui; HotkeyRegistry& registry; diff --git a/src/citron/configuration/configure_per_game.cpp b/src/citron/configuration/configure_per_game.cpp index 1647cec03..5c8f5b68d 100644 --- a/src/citron/configuration/configure_per_game.cpp +++ b/src/citron/configuration/configure_per_game.cpp @@ -66,11 +66,25 @@ // Helper function to detect if the application is using a dark theme static bool IsDarkMode() { - const QPalette palette = qApp->palette(); - const QColor text_color = palette.color(QPalette::WindowText); - const QColor base_color = palette.color(QPalette::Window); - // A common heuristic for dark mode is that the text color is brighter than the background - return text_color.value() > base_color.value(); + const std::string& theme_name = UISettings::values.theme; + + // Priority 1: Check for explicitly chosen dark themes. + if (theme_name == "qdarkstyle" || theme_name == "colorful_dark" || + theme_name == "qdarkstyle_midnight_blue" || theme_name == "colorful_midnight_blue") { + return true; // These themes are always dark. + } + + // Priority 2: Check for adaptive themes ("default" and "colorful"). + // For these, we fall back to checking the OS palette. + if (theme_name == "default" || theme_name == "colorful") { + const QPalette palette = qApp->palette(); + const QColor text_color = palette.color(QPalette::WindowText); + const QColor base_color = palette.color(QPalette::Window); + return text_color.value() > base_color.value(); + } + + // Fallback for any other unknown theme (assumed light). + return false; } ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::string& file_name_, @@ -84,6 +98,8 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st ui->setupUi(this); + last_palette_text_color = qApp->palette().color(QPalette::WindowText); + const auto file_path = std::filesystem::path(Common::FS::ToU8String(file_name)); const auto config_file_name = title_id == 0 ? Common::FS::PathToUTF8String(file_path.filename()) : fmt::format("{:016X}", title_id); @@ -197,6 +213,15 @@ void ConfigurePerGame::changeEvent(QEvent* event) { if (event->type() == QEvent::LanguageChange) { RetranslateUI(); } + + if (event->type() == QEvent::PaletteChange) { + const QColor current_color = qApp->palette().color(QPalette::WindowText); + if (current_color != last_palette_text_color) { + last_palette_text_color = current_color; + UpdateTheme(); + } + } + QDialog::changeEvent(event); } diff --git a/src/citron/configuration/configure_per_game.h b/src/citron/configuration/configure_per_game.h index 68d6af024..0412f247b 100644 --- a/src/citron/configuration/configure_per_game.h +++ b/src/citron/configuration/configure_per_game.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -62,10 +63,10 @@ public slots: void OnTrimXCI(); protected: + void changeEvent(QEvent* event) override; void resizeEvent(QResizeEvent* event) override; private: - void changeEvent(QEvent* event) override; void RetranslateUI(); void HandleApplyButtonClicked(); void LoadConfiguration(); @@ -80,6 +81,8 @@ private: QGraphicsScene* scene; std::unique_ptr game_config; + QColor last_palette_text_color; + Core::System& system; std::unique_ptr builder; std::shared_ptr> tab_group;