fix(editor): fixed a few dark-theme-related bugs under windows
This commit is contained in:
parent
74b8bca10a
commit
2047ed6d65
3 changed files with 28 additions and 18 deletions
|
@ -1 +1,17 @@
|
|||
#pragma once
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -14,27 +14,15 @@
|
|||
#include <qglobal.h>
|
||||
#include <qlayout.h>
|
||||
#include <qtextformat.h>
|
||||
#include "mainwindow.h"
|
||||
#include "objects/script.h"
|
||||
#include "datatypes/variant.h"
|
||||
#include <QPalette>
|
||||
#include <QStyleHints>
|
||||
#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<int, const QColor> DARK_MODE_COLOR_SCHEME = {{
|
||||
{QsciLexerLua::Comment, QColor("#808080")},
|
||||
{QsciLexerLua::LineComment, QColor("#808080")},
|
||||
|
|
Loading…
Add table
Reference in a new issue