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

View File

@ -15,20 +15,16 @@ FRAMELESSHELPER_USE_NAMESPACE
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
FramelessHelper::Quick::initialize(); FramelessHelper::Quick::initialize();
qputenv("QT_QUICK_CONTROLS_STYLE","Basic");
//6.4及以下监听系统深色模式变化
#ifdef Q_OS_WIN
qputenv("QT_QPA_PLATFORM","windows:darkmode=2");
#endif
//将样式设置为Basic不然会导致组件显示异常 //将样式设置为Basic不然会导致组件显示异常
qputenv("QT_QUICK_CONTROLS_STYLE","Basic");
QGuiApplication::setOrganizationName("ZhuZiChu"); QGuiApplication::setOrganizationName("ZhuZiChu");
QGuiApplication::setOrganizationDomain("https://zhuzichu520.github.io"); QGuiApplication::setOrganizationDomain("https://zhuzichu520.github.io");
QGuiApplication::setApplicationName("FluentUI"); QGuiApplication::setApplicationName("FluentUI");
// QQuickWindow::setGraphicsApi(QSGRendererInterface::Software); // QQuickWindow::setGraphicsApi(QSGRendererInterface::Software);
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
FramelessHelper::Core::setApplicationOSThemeAware(); // FramelessHelper::Core::setApplicationOSThemeAware();
FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); // FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial); // FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial);
AppInfo* appInfo = new AppInfo(); AppInfo* appInfo = new AppInfo();
IPC ipc(0); IPC ipc(0);
QString activeWindowEvent = "activeWindow"; QString activeWindowEvent = "activeWindow";

View File

@ -61,9 +61,9 @@ qt_add_qml_module(fluentuiplugin
# #
target_link_libraries(fluentuiplugin PUBLIC target_link_libraries(fluentuiplugin PUBLIC
Qt::Core Qt::CorePrivate
Qt::Quick Qt::QuickPrivate
Qt::Qml Qt::QmlPrivate
) )
# win32 mingw # win32 mingw

View File

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

View File

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