mirror of
https://git.citron-emu.org/citron/emulator
synced 2026-01-04 09:13:45 +00:00
fix/properties-light-dark
Signed-off-by: Collecting <collecting@noreply.localhost>
This commit is contained in:
@@ -64,6 +64,15 @@
|
||||
#include "common/string_util.h"
|
||||
#include "common/xci_trimmer.h"
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::string& file_name_,
|
||||
std::vector<VkDeviceInfo::Record>& vk_device_records,
|
||||
Core::System& system_)
|
||||
@@ -228,18 +237,41 @@ void ConfigurePerGame::UpdateTheme() {
|
||||
const QString accent_color_hover = accent_color.lighter(115).name(QColor::HexRgb);
|
||||
const QString accent_color_pressed = accent_color.darker(120).name(QColor::HexRgb);
|
||||
|
||||
const bool is_dark = IsDarkMode();
|
||||
const QString bg_color = is_dark ? QStringLiteral("#2b2b2b") : QStringLiteral("#ffffff");
|
||||
const QString text_color = is_dark ? QStringLiteral("#ffffff") : QStringLiteral("#000000");
|
||||
const QString secondary_bg_color = is_dark ? QStringLiteral("#3d3d3d") : QStringLiteral("#f0f0f0");
|
||||
const QString tertiary_bg_color = is_dark ? QStringLiteral("#5d5d5d") : QStringLiteral("#d3d3d3");
|
||||
const QString button_bg_color = is_dark ? QStringLiteral("#383838") : QStringLiteral("#e1e1e1");
|
||||
const QString hover_bg_color = is_dark ? QStringLiteral("#4d4d4d") : QStringLiteral("#e8f0fe");
|
||||
const QString focus_bg_color = is_dark ? QStringLiteral("#404040") : QStringLiteral("#e8f0fe");
|
||||
const QString disabled_text_color = is_dark ? QStringLiteral("#8d8d8d") : QStringLiteral("#a0a0a0");
|
||||
|
||||
static QString cached_template_style_sheet;
|
||||
if (cached_template_style_sheet.isEmpty()) {
|
||||
cached_template_style_sheet = property("templateStyleSheet").toString();
|
||||
}
|
||||
|
||||
QString style_sheet = cached_template_style_sheet;
|
||||
|
||||
// Replace accent colors (existing logic)
|
||||
style_sheet.replace(QStringLiteral("%%ACCENT_COLOR%%"), accent_color_str);
|
||||
style_sheet.replace(QStringLiteral("%%ACCENT_COLOR_HOVER%%"), accent_color_hover);
|
||||
style_sheet.replace(QStringLiteral("%%ACCENT_COLOR_PRESSED%%"), accent_color_pressed);
|
||||
|
||||
// Replace base theme colors (new logic)
|
||||
style_sheet.replace(QStringLiteral("%%BACKGROUND_COLOR%%"), bg_color);
|
||||
style_sheet.replace(QStringLiteral("%%TEXT_COLOR%%"), text_color);
|
||||
style_sheet.replace(QStringLiteral("%%SECONDARY_BG_COLOR%%"), secondary_bg_color);
|
||||
style_sheet.replace(QStringLiteral("%%TERTIARY_BG_COLOR%%"), tertiary_bg_color);
|
||||
style_sheet.replace(QStringLiteral("%%BUTTON_BG_COLOR%%"), button_bg_color);
|
||||
style_sheet.replace(QStringLiteral("%%HOVER_BG_COLOR%%"), hover_bg_color);
|
||||
style_sheet.replace(QStringLiteral("%%FOCUS_BG_COLOR%%"), focus_bg_color);
|
||||
style_sheet.replace(QStringLiteral("%%DISABLED_TEXT_COLOR%%"), disabled_text_color);
|
||||
|
||||
setStyleSheet(style_sheet);
|
||||
|
||||
// This is the crucial part that passes the theme to the child tabs
|
||||
// This part is crucial to pass the theme to child tabs
|
||||
graphics_tab->SetTemplateStyleSheet(style_sheet);
|
||||
system_tab->SetTemplateStyleSheet(style_sheet);
|
||||
audio_tab->SetTemplateStyleSheet(style_sheet);
|
||||
|
||||
Reference in New Issue
Block a user