Skip to content

Commit 5014c82

Browse files
committed
fix(editor): fixed a few dark-theme-related bugs under windows
1 parent d258e2b commit 5014c82

3 files changed

Lines changed: 27 additions & 17 deletions

File tree

editor/editorcommon.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
#pragma once
1+
#pragma once
2+
3+
inline bool isDarkMode() {
4+
// https://stackoverflow.com/a/78854851/16255372
5+
#if defined(_WIN32)
6+
// Never read dark theme on Windows as the app currently renders with white color palette regardless
7+
return false;
8+
#elif QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
9+
const auto scheme = QGuiApplication::styleHints()->colorScheme();
10+
return scheme == Qt::ColorScheme::Dark;
11+
#else
12+
const QPalette defaultPalette;
13+
const auto text = defaultPalette.color(QPalette::WindowText);
14+
const auto window = defaultPalette.color(QPalette::Window);
15+
return text.lightness() > window.lightness();
16+
#endif // QT_VERSION
17+
}

editor/mainwindow.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ MainWindow::MainWindow(QWidget *parent)
7474
ui->actionRedo->setShortcuts({QKeySequence("Ctrl+Shift+Z"), QKeySequence("Ctrl+Y")});
7575

7676
QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() + QStringList { "./assets/icons" });
77+
78+
// Force theme under windows
79+
#ifdef _WIN32
80+
QIcon::setThemeName("editor");
81+
#else
7782
if (isDarkMode())
7883
QIcon::setFallbackThemeName("editor-dark");
7984
else
80-
QIcon::setThemeName("editor");
85+
QIcon::setFallbackThemeName("editor");
86+
#endif
8187

8288
// qApp->setStyle(QStyleFactory::create("fusion"));
8389
defaultMessageHandler = qInstallMessageHandler(logQtMessage);

editor/script/scriptdocument.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,15 @@
1414
#include <qglobal.h>
1515
#include <qlayout.h>
1616
#include <qtextformat.h>
17+
#include <QPalette>
18+
#include <QStyleHints>
1719
#include "mainwindow.h"
20+
#include "editorcommon.h"
1821
#include "objects/script.h"
1922
#include "datatypes/variant.h"
20-
#include <QPalette>
21-
#include <QStyleHints>
2223

2324
QsciAPIs* makeApis(QsciLexer*);
2425

25-
inline bool isDarkMode() {
26-
// https://stackoverflow.com/a/78854851/16255372
27-
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
28-
const auto scheme = QGuiApplication::styleHints()->colorScheme();
29-
return scheme == Qt::ColorScheme::Dark;
30-
#else
31-
const QPalette defaultPalette;
32-
const auto text = defaultPalette.color(QPalette::WindowText);
33-
const auto window = defaultPalette.color(QPalette::Window);
34-
return text.lightness() > window.lightness();
35-
#endif // QT_VERSION
36-
}
37-
3826
std::map<int, const QColor> DARK_MODE_COLOR_SCHEME = {{
3927
{QsciLexerLua::Comment, QColor("#808080")},
4028
{QsciLexerLua::LineComment, QColor("#808080")},

0 commit comments

Comments
 (0)