mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-19 18:53:32 +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;
|
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() {
|
static bool IsDarkMode() {
|
||||||
const QPalette palette = qApp->palette();
|
const std::string& theme_name = UISettings::values.theme;
|
||||||
const QColor text_color = palette.color(QPalette::WindowText);
|
|
||||||
const QColor base_color = palette.color(QPalette::Window);
|
// Priority 1: Check for explicitly chosen dark themes.
|
||||||
// A common heuristic for dark mode is that the text color is brighter than the background
|
if (theme_name == "qdarkstyle" || theme_name == "colorful_dark" ||
|
||||||
return text_color.value() > base_color.value();
|
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_,
|
ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_,
|
||||||
@@ -99,6 +113,8 @@ rainbow_timer{new QTimer(this)} {
|
|||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
last_palette_text_color = qApp->palette().color(QPalette::WindowText);
|
||||||
|
|
||||||
if (!UISettings::values.configure_dialog_geometry.isEmpty()) {
|
if (!UISettings::values.configure_dialog_geometry.isEmpty()) {
|
||||||
restoreGeometry(UISettings::values.configure_dialog_geometry);
|
restoreGeometry(UISettings::values.configure_dialog_geometry);
|
||||||
}
|
}
|
||||||
@@ -272,6 +288,14 @@ void ConfigureDialog::changeEvent(QEvent* event) {
|
|||||||
RetranslateUI();
|
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);
|
QDialog::changeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <QColor>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "common/settings_enums.h"
|
#include "common/settings_enums.h"
|
||||||
#include "citron/configuration/shared_widget.h" // <-- Correct header for Builder
|
#include "citron/configuration/shared_widget.h" // <-- Correct header for Builder
|
||||||
@@ -70,6 +71,8 @@ private:
|
|||||||
|
|
||||||
void OnLanguageChanged(const QString& locale);
|
void OnLanguageChanged(const QString& locale);
|
||||||
|
|
||||||
|
QColor last_palette_text_color;
|
||||||
|
|
||||||
// All members are now in the EXACT correct order to match the constructor
|
// All members are now in the EXACT correct order to match the constructor
|
||||||
std::unique_ptr<Ui::ConfigureDialog> ui;
|
std::unique_ptr<Ui::ConfigureDialog> ui;
|
||||||
HotkeyRegistry& registry;
|
HotkeyRegistry& registry;
|
||||||
|
|||||||
@@ -66,11 +66,25 @@
|
|||||||
|
|
||||||
// Helper function to detect if the application is using a dark theme
|
// Helper function to detect if the application is using a dark theme
|
||||||
static bool IsDarkMode() {
|
static bool IsDarkMode() {
|
||||||
const QPalette palette = qApp->palette();
|
const std::string& theme_name = UISettings::values.theme;
|
||||||
const QColor text_color = palette.color(QPalette::WindowText);
|
|
||||||
const QColor base_color = palette.color(QPalette::Window);
|
// Priority 1: Check for explicitly chosen dark themes.
|
||||||
// A common heuristic for dark mode is that the text color is brighter than the background
|
if (theme_name == "qdarkstyle" || theme_name == "colorful_dark" ||
|
||||||
return text_color.value() > base_color.value();
|
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_,
|
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);
|
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 file_path = std::filesystem::path(Common::FS::ToU8String(file_name));
|
||||||
const auto config_file_name = title_id == 0 ? Common::FS::PathToUTF8String(file_path.filename())
|
const auto config_file_name = title_id == 0 ? Common::FS::PathToUTF8String(file_path.filename())
|
||||||
: fmt::format("{:016X}", title_id);
|
: fmt::format("{:016X}", title_id);
|
||||||
@@ -197,6 +213,15 @@ void ConfigurePerGame::changeEvent(QEvent* event) {
|
|||||||
if (event->type() == QEvent::LanguageChange) {
|
if (event->type() == QEvent::LanguageChange) {
|
||||||
RetranslateUI();
|
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);
|
QDialog::changeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
@@ -62,10 +63,10 @@ public slots:
|
|||||||
void OnTrimXCI();
|
void OnTrimXCI();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void changeEvent(QEvent* event) override;
|
||||||
void resizeEvent(QResizeEvent* event) override;
|
void resizeEvent(QResizeEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void changeEvent(QEvent* event) override;
|
|
||||||
void RetranslateUI();
|
void RetranslateUI();
|
||||||
void HandleApplyButtonClicked();
|
void HandleApplyButtonClicked();
|
||||||
void LoadConfiguration();
|
void LoadConfiguration();
|
||||||
@@ -80,6 +81,8 @@ private:
|
|||||||
QGraphicsScene* scene;
|
QGraphicsScene* scene;
|
||||||
std::unique_ptr<QtConfig> game_config;
|
std::unique_ptr<QtConfig> game_config;
|
||||||
|
|
||||||
|
QColor last_palette_text_color;
|
||||||
|
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
std::unique_ptr<ConfigurationShared::Builder> builder;
|
std::unique_ptr<ConfigurationShared::Builder> builder;
|
||||||
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> tab_group;
|
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> tab_group;
|
||||||
|
|||||||
Reference in New Issue
Block a user