From 155960c15b8f8b8bf77e85740156e8aeabdc54d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Wed, 17 May 2023 22:02:09 +0800 Subject: [PATCH] update --- example/src/main.cpp | 12 ++++-------- src/CMakeLists.txt | 6 +++--- src/FluTheme.cpp | 14 +++++++++----- src/FluTheme.h | 1 + 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/example/src/main.cpp b/example/src/main.cpp index e80408f..c320861 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -15,20 +15,16 @@ FRAMELESSHELPER_USE_NAMESPACE int main(int argc, char *argv[]) { FramelessHelper::Quick::initialize(); - qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); - //6.4及以下监听系统深色模式变化 -#ifdef Q_OS_WIN - qputenv("QT_QPA_PLATFORM","windows:darkmode=2"); -#endif //将样式设置为Basic,不然会导致组件显示异常 + qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); QGuiApplication::setOrganizationName("ZhuZiChu"); QGuiApplication::setOrganizationDomain("https://zhuzichu520.github.io"); QGuiApplication::setApplicationName("FluentUI"); // QQuickWindow::setGraphicsApi(QSGRendererInterface::Software); QGuiApplication app(argc, argv); - FramelessHelper::Core::setApplicationOSThemeAware(); - FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); - FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial); +// FramelessHelper::Core::setApplicationOSThemeAware(); +// FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); +// FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial); AppInfo* appInfo = new AppInfo(); IPC ipc(0); QString activeWindowEvent = "activeWindow"; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 45a4064..3f22988 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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会编译错误 diff --git a/src/FluTheme.cpp b/src/FluTheme.cpp index 41b4d92..823fb2d 100644 --- a/src/FluTheme.cpp +++ b/src/FluTheme.cpp @@ -3,6 +3,8 @@ #include "Def.h" #include "FluColors.h" #include +#include +#include #include 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; } diff --git a/src/FluTheme.h b/src/FluTheme.h index 1c60291..2f9092c 100644 --- a/src/FluTheme.h +++ b/src/FluTheme.h @@ -47,6 +47,7 @@ public: Q_SIGNAL void darkChanged(); private: bool _dark; + bool _systemDark; bool eventFilter(QObject *obj, QEvent *event); bool systemDark(); };