mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-19 10:43:33 +00:00
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user