From 2047ed6d653e1161cb8c09c56a3a9dc011a0ea93 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Fri, 11 Jul 2025 00:34:02 +0200 Subject: [PATCH] fix(editor): fixed a few dark-theme-related bugs under windows --- editor/editorcommon.h | 18 +++++++++++++++++- editor/mainwindow.cpp | 8 +++++++- editor/script/scriptdocument.cpp | 20 ++++---------------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/editor/editorcommon.h b/editor/editorcommon.h index 7b9637e..98eb8d2 100644 --- a/editor/editorcommon.h +++ b/editor/editorcommon.h @@ -1 +1,17 @@ -#pragma once \ No newline at end of file +#pragma once + +inline bool isDarkMode() { + // https://stackoverflow.com/a/78854851/16255372 + #if defined(_WIN32) + // Never read dark theme on Windows as the app currently renders with white color palette regardless + return false; + #elif QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + const auto scheme = QGuiApplication::styleHints()->colorScheme(); + return scheme == Qt::ColorScheme::Dark; + #else + const QPalette defaultPalette; + const auto text = defaultPalette.color(QPalette::WindowText); + const auto window = defaultPalette.color(QPalette::Window); + return text.lightness() > window.lightness(); + #endif // QT_VERSION +} diff --git a/editor/mainwindow.cpp b/editor/mainwindow.cpp index d571929..5260d2a 100644 --- a/editor/mainwindow.cpp +++ b/editor/mainwindow.cpp @@ -74,10 +74,16 @@ MainWindow::MainWindow(QWidget *parent) ui->actionRedo->setShortcuts({QKeySequence("Ctrl+Shift+Z"), QKeySequence("Ctrl+Y")}); QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() + QStringList { "./assets/icons" }); + + // Force theme under windows + #ifdef _WIN32 + QIcon::setThemeName("editor"); + #else if (isDarkMode()) QIcon::setFallbackThemeName("editor-dark"); else - QIcon::setThemeName("editor"); + QIcon::setFallbackThemeName("editor"); + #endif // qApp->setStyle(QStyleFactory::create("fusion")); defaultMessageHandler = qInstallMessageHandler(logQtMessage); diff --git a/editor/script/scriptdocument.cpp b/editor/script/scriptdocument.cpp index d02e66a..71a4735 100644 --- a/editor/script/scriptdocument.cpp +++ b/editor/script/scriptdocument.cpp @@ -14,27 +14,15 @@ #include #include #include -#include "mainwindow.h" -#include "objects/script.h" -#include "datatypes/variant.h" #include #include +#include "mainwindow.h" +#include "editorcommon.h" +#include "objects/script.h" +#include "datatypes/variant.h" QsciAPIs* makeApis(QsciLexer*); -inline bool isDarkMode() { - // https://stackoverflow.com/a/78854851/16255372 - #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) - const auto scheme = QGuiApplication::styleHints()->colorScheme(); - return scheme == Qt::ColorScheme::Dark; - #else - const QPalette defaultPalette; - const auto text = defaultPalette.color(QPalette::WindowText); - const auto window = defaultPalette.color(QPalette::Window); - return text.lightness() > window.lightness(); - #endif // QT_VERSION -} - std::map DARK_MODE_COLOR_SCHEME = {{ {QsciLexerLua::Comment, QColor("#808080")}, {QsciLexerLua::LineComment, QColor("#808080")},