mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-19 10:43:33 +00:00
Merge pull request 'fix(ui): Make configuration dialogs respect in-app theme choice' (#15) from fix/themes into main
Reviewed-on: https://git.citron-emu.org/Citron/Emulator/pulls/15
This commit is contained in:
@@ -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 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);
|
||||
// A common heuristic for dark mode is that the text color is brighter than the background
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <QColor>
|
||||
#include <QDialog>
|
||||
#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::ConfigureDialog> ui;
|
||||
HotkeyRegistry& registry;
|
||||
|
||||
@@ -66,11 +66,25 @@
|
||||
|
||||
// Helper function to detect if the application is using a dark theme
|
||||
static bool IsDarkMode() {
|
||||
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);
|
||||
// A common heuristic for dark mode is that the text color is brighter than the background
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <QColor>
|
||||
#include <QDialog>
|
||||
#include <QList>
|
||||
#include <QPixmap>
|
||||
@@ -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<QtConfig> game_config;
|
||||
|
||||
QColor last_palette_text_color;
|
||||
|
||||
Core::System& system;
|
||||
std::unique_ptr<ConfigurationShared::Builder> builder;
|
||||
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> tab_group;
|
||||
|
||||
Reference in New Issue
Block a user