fix/themes

Signed-off-by: Collecting <collecting@noreply.localhost>
This commit is contained in:
Collecting
2025-11-02 02:05:39 +00:00
parent 3f3956ed8a
commit 755286cbbc

View File

@@ -49,15 +49,29 @@ 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 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 QPalette palette = qApp->palette();
const QColor text_color = palette.color(QPalette::WindowText); const QColor text_color = palette.color(QPalette::WindowText);
const QColor base_color = palette.color(QPalette::Window); 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(); 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_,
InputCommon::InputSubsystem* input_subsystem, InputCommon::InputSubsystem* input_subsystem,
std::vector<VkDeviceInfo::Record>& vk_device_records, std::vector<VkDeviceInfo::Record>& vk_device_records,
@@ -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);
} }