This commit is contained in:
朱子楚\zhuzi
2023-05-17 22:02:09 +08:00
parent 1601b64883
commit 155960c15b
4 changed files with 17 additions and 16 deletions

View File

@ -61,9 +61,9 @@ qt_add_qml_module(fluentuiplugin
#链接库
target_link_libraries(fluentuiplugin PUBLIC
Qt::Core
Qt::Quick
Qt::Qml
Qt::CorePrivate
Qt::QuickPrivate
Qt::QmlPrivate
)
#链接库 win32库 不然mingw会编译错误

View File

@ -3,6 +3,8 @@
#include "Def.h"
#include "FluColors.h"
#include <QPalette>
#include <QtGui/qpa/qplatformtheme.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QGuiApplication>
FluTheme* FluTheme::m_instance = nullptr;
@ -30,8 +32,9 @@ FluTheme::FluTheme(QObject *parent)
bool FluTheme::eventFilter(QObject *obj, QEvent *event)
{
Q_UNUSED(obj);
if (event->type() == QEvent::ApplicationPaletteChange)
if (event->type() == QEvent::ApplicationPaletteChange || event->type() == QEvent::ThemeChange)
{
_systemDark = systemDark();
Q_EMIT darkChanged();
event->accept();
return true;
@ -41,9 +44,10 @@ bool FluTheme::eventFilter(QObject *obj, QEvent *event)
bool FluTheme::systemDark()
{
QPalette palette = qApp->palette();
QColor color = palette.color(QPalette::Window).rgb();
return !(color.red() * 0.2126 + color.green() * 0.7152 + color.blue() * 0.0722 > 255 / 2);
if (const QPlatformTheme * const theme = QGuiApplicationPrivate::platformTheme()) {
return (theme->appearance() == QPlatformTheme::Appearance::Dark);
}
return false;
}
bool FluTheme::dark(){
@ -52,7 +56,7 @@ bool FluTheme::dark(){
}else if(_darkMode == Fluent_DarkMode::Fluent_DarkModeType::Light){
return false;
}else if(_darkMode == Fluent_DarkMode::Fluent_DarkModeType::System){
return systemDark();
return _systemDark;
}else{
return false;
}

View File

@ -47,6 +47,7 @@ public:
Q_SIGNAL void darkChanged();
private:
bool _dark;
bool _systemDark;
bool eventFilter(QObject *obj, QEvent *event);
bool systemDark();
};