From 15f90471dcb1637a96dd975bed7909451665e37e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Fri, 19 May 2023 07:57:23 +0800 Subject: [PATCH] update --- example/CMakeLists.txt | 10 +-- example/qml/component/CustomWindow.qml | 60 ++++++++++++++++++ example/qml/window/AboutWindow.qml | 3 +- example/qml/window/LoginWindow.qml | 3 +- example/qml/window/MainWindow.qml | 5 +- example/qml/window/MediaWindow.qml | 3 +- example/qml/window/SingleInstanceWindow.qml | 3 +- example/qml/window/SingleTaskWindow.qml | 3 +- example/qml/window/StandardWindow.qml | 3 +- example/src/main.cpp | 13 ++-- src/CMakeLists.txt | 6 +- src/FluGlobal.cpp | 29 --------- src/FluGlobal.h | 13 ---- src/FluTheme.cpp | 45 ++----------- src/FluTools.cpp | 1 + .../FluentUI/Controls/FluNavigationView.qml | 10 ++- src/imports/FluentUI/Controls/FluWindow.qml | 63 +++---------------- 17 files changed, 108 insertions(+), 165 deletions(-) create mode 100644 example/qml/component/CustomWindow.qml delete mode 100644 src/FluGlobal.cpp delete mode 100644 src/FluGlobal.h diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 000ccdbc..2d992d38 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -90,18 +90,12 @@ set_target_properties(example PROPERTIES WIN32_EXECUTABLE TRUE ) - #链接库 target_link_libraries(example PRIVATE Qt6::Quick fluentuiplugin -) - -#导入头文件 -set(QML_PLUGIN_DIRECTORY ${CMAKE_PREFIX_PATH}/qml/FluentUI) -target_include_directories( - example PRIVATE - ${QML_PLUGIN_DIRECTORY} + FramelessHelper::Core + FramelessHelper::Quick ) #安装 diff --git a/example/qml/component/CustomWindow.qml b/example/qml/component/CustomWindow.qml new file mode 100644 index 00000000..8eb2114c --- /dev/null +++ b/example/qml/component/CustomWindow.qml @@ -0,0 +1,60 @@ +import QtQuick +import QtQuick.Layouts +import FluentUI +import org.wangwenx190.FramelessHelper + +FluWindow { + + id:window + + property bool fixSize + property alias titleVisible: title_bar.titleVisible + property bool appBarVisible: true + default property alias content: container.data + + FluAppBar { + id: title_bar + title: window.title + visible: window.appBarVisible + anchors { + top: parent.top + left: parent.left + right: parent.right + } + darkText: lang.dark_mode + } + + Item{ + id:container + anchors{ + top: title_bar.bottom + left: parent.left + right: parent.right + bottom: parent.bottom + } + clip: true + } + + FramelessHelper{ + id:framless_helper + onReady: { + setTitleBarItem(title_bar) + framless_helper.moveWindowToDesktopCenter() + setHitTestVisible(title_bar.minimizeButton()) + setHitTestVisible(title_bar.maximizeButton()) + setHitTestVisible(title_bar.closeButton()) + framless_helper.setWindowFixedSize(fixSize) + title_bar.maximizeButton.visible = !fixSize + window.visible = true + } + } + + function setHitTestVisible(com){ + framless_helper.setHitTestVisible(com) + } + + function setTitleBarItem(com){ + framless_helper.setTitleBarItem(com) + } + +} diff --git a/example/qml/window/AboutWindow.qml b/example/qml/window/AboutWindow.qml index 818b3428..475333c3 100644 --- a/example/qml/window/AboutWindow.qml +++ b/example/qml/window/AboutWindow.qml @@ -2,8 +2,9 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI +import "../component" -FluWindow { +CustomWindow { id:window title:"关于" diff --git a/example/qml/window/LoginWindow.qml b/example/qml/window/LoginWindow.qml index 103ab444..25d8bada 100644 --- a/example/qml/window/LoginWindow.qml +++ b/example/qml/window/LoginWindow.qml @@ -2,8 +2,9 @@ import QtQuick.Layouts import QtQuick.Controls import FluentUI +import "../component" -FluWindow { +CustomWindow { id:window title:"登录" diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index 8e7b7636..d6dc7dd5 100644 --- a/example/qml/window/MainWindow.qml +++ b/example/qml/window/MainWindow.qml @@ -4,9 +4,10 @@ import QtQuick.Controls import QtQuick.Layouts import Qt.labs.platform import FluentUI +import "../component" import "qrc:///example/qml/global/" -FluWindow { +CustomWindow { id:window title: "FluentUI" @@ -97,7 +98,7 @@ FluWindow { z:999 items: ItemsOriginal footerItems:ItemsFooter - topPadding:FluTools.isMacos() ? 20 : 5 + topPadding:Qt.platform.os === FluTools.isMacos() ? 20 : 5 displayMode:MainEvent.displayMode logo: "qrc:/example/res/image/favicon.ico" title:"FluentUI" diff --git a/example/qml/window/MediaWindow.qml b/example/qml/window/MediaWindow.qml index d16956ad..1f2d9942 100644 --- a/example/qml/window/MediaWindow.qml +++ b/example/qml/window/MediaWindow.qml @@ -2,8 +2,9 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI +import "../component" -FluWindow { +CustomWindow { title:"视频播放器" width: 640 diff --git a/example/qml/window/SingleInstanceWindow.qml b/example/qml/window/SingleInstanceWindow.qml index 940db2ca..f5d13873 100644 --- a/example/qml/window/SingleInstanceWindow.qml +++ b/example/qml/window/SingleInstanceWindow.qml @@ -2,8 +2,9 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI +import "../component" -FluWindow { +CustomWindow { id:window title:"SingleInstance" diff --git a/example/qml/window/SingleTaskWindow.qml b/example/qml/window/SingleTaskWindow.qml index 33195aa9..1e6f69ea 100644 --- a/example/qml/window/SingleTaskWindow.qml +++ b/example/qml/window/SingleTaskWindow.qml @@ -2,8 +2,9 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI +import "../component" -FluWindow { +CustomWindow { id:window title:"SingleTask" diff --git a/example/qml/window/StandardWindow.qml b/example/qml/window/StandardWindow.qml index 40347bca..6724753d 100644 --- a/example/qml/window/StandardWindow.qml +++ b/example/qml/window/StandardWindow.qml @@ -2,8 +2,9 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI +import "../component" -FluWindow { +CustomWindow { id:window title:"Standard" diff --git a/example/src/main.cpp b/example/src/main.cpp index cd749298..cdabd68a 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -4,20 +4,23 @@ #include #include #include -#include +#include +#include #include "lang/Lang.h" #include "AppInfo.h" #include "tool/IPC.h" +FRAMELESSHELPER_USE_NAMESPACE + int main(int argc, char *argv[]) { - FluentUI::preInit(); + //将样式设置为Basic,不然会导致组件显示异常 + qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); + FramelessHelper::Quick::initialize(); QGuiApplication::setOrganizationName("ZhuZiChu"); QGuiApplication::setOrganizationDomain("https://zhuzichu520.github.io"); QGuiApplication::setApplicationName("FluentUI"); - // QQuickWindow::setGraphicsApi(QSGRendererInterface::Software); QGuiApplication app(argc, argv); - FluentUI::postInit(); AppInfo* appInfo = new AppInfo(); IPC ipc(0); QString activeWindowEvent = "activeWindow"; @@ -34,7 +37,7 @@ int main(int argc, char *argv[]) } app.setQuitOnLastWindowClosed(false); QQmlApplicationEngine engine; - FluentUI::initEngine(&engine); + FramelessHelper::Quick::registerTypes(&engine); QQmlContext * context = engine.rootContext(); Lang* lang = appInfo->lang(); context->setContextProperty("lang",lang); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8b4b7e5d..140db143 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,11 +54,9 @@ qt_add_qml_module(fluentuiplugin URI "FluentUI" SOURCES ${sources_files} fluentui.rc QML_FILES ${qml_files} - RESOURCES ${resource_files} FluGlobal.h + RESOURCES ${resource_files} #支持designer DESIGNER_SUPPORTED - DEPENDENCIES - org.wangwenx190.FramelessHelper/auto ) #链接库 @@ -66,8 +64,6 @@ target_link_libraries(fluentuiplugin PUBLIC Qt::CorePrivate Qt::QuickPrivate Qt::QmlPrivate - FramelessHelper::Core - FramelessHelper::Quick ) #链接库 win32库 不然mingw会编译错误 diff --git a/src/FluGlobal.cpp b/src/FluGlobal.cpp deleted file mode 100644 index 94de6b2c..00000000 --- a/src/FluGlobal.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "FluGlobal.h" - -#include -#include -#include - -FRAMELESSHELPER_USE_NAMESPACE; - -namespace FluentUI { - -void preInit(){ - qDebug()<<"preInit"; - FramelessHelper::Quick::initialize(); - //将样式设置为Basic,不然会导致组件显示异常 - qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); -} -void postInit(){ - qDebug()<<"postInit"; - FramelessHelper::Core::setApplicationOSThemeAware(); -// FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); -// FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial); -} -void initEngine(QQmlApplicationEngine* engine){ - qDebug()<<"initEngine"; - FramelessHelper::Quick::registerTypes(engine); - qDebug()<<"FramelessHelper::Quick::registerTypes(engine)"; -} - -} diff --git a/src/FluGlobal.h b/src/FluGlobal.h deleted file mode 100644 index 3285597f..00000000 --- a/src/FluGlobal.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef FLUGLOBAL_H -#define FLUGLOBAL_H - -#include -#include - -namespace FluentUI { - Q_DECL_EXPORT void preInit(); - Q_DECL_EXPORT void postInit(); - Q_DECL_EXPORT void initEngine(QQmlApplicationEngine* engine); -} - -#endif // FLUGLOBAL_H diff --git a/src/FluTheme.cpp b/src/FluTheme.cpp index c2b4e1bd..e59ec16e 100644 --- a/src/FluTheme.cpp +++ b/src/FluTheme.cpp @@ -1,37 +1,3 @@ -//#include "FluTheme.h" - -//#include "Def.h" -//#include "FluColors.h" -//#include -//#include -//#include -//#include -//#include -//#include - -//FRAMELESSHELPER_USE_NAMESPACE; - -//FluTheme* FluTheme::m_instance = nullptr; - -//FluTheme *FluTheme::getInstance() -//{ -// if(FluTheme::m_instance == nullptr){ -// FluTheme::m_instance = new FluTheme; -// } -// return FluTheme::m_instance; -//} - -//FluTheme::FluTheme(QObject *parent) -// : QObject{parent} -//{ -// primaryColor(FluColors::getInstance()->Blue()); -// nativeText(false); -// dark(FramelessManager::instance()->systemTheme() == Global::SystemTheme::Dark); -// connect(FramelessManager::instance(), &FramelessManager::systemThemeChanged, this, [this](){ -// dark(Utils::getSystemTheme()==Global::SystemTheme::Dark); -// }); -//} - #include "FluTheme.h" #include "Def.h" @@ -40,11 +6,6 @@ #include #include #include -#include -#include - -FRAMELESSHELPER_USE_NAMESPACE; - FluTheme* FluTheme::m_instance = nullptr; @@ -82,10 +43,12 @@ bool FluTheme::eventFilter(QObject *obj, QEvent *event) return false; } - bool FluTheme::systemDark() { - return Utils::getSystemTheme()==Global::SystemTheme::Dark; + if (const QPlatformTheme * const theme = QGuiApplicationPrivate::platformTheme()) { + return (theme->appearance() == QPlatformTheme::Appearance::Dark); + } + return false; } bool FluTheme::dark(){ diff --git a/src/FluTools.cpp b/src/FluTools.cpp index 7c93eb20..580afe3a 100644 --- a/src/FluTools.cpp +++ b/src/FluTools.cpp @@ -63,3 +63,4 @@ bool FluTools::isWin(){ #endif } + diff --git a/src/imports/FluentUI/Controls/FluNavigationView.qml b/src/imports/FluentUI/Controls/FluNavigationView.qml index c268692f..d897101d 100644 --- a/src/imports/FluentUI/Controls/FluNavigationView.qml +++ b/src/imports/FluentUI/Controls/FluNavigationView.qml @@ -623,7 +623,15 @@ Item { if(d.isMinimal || d.isCompactAndPanel){ return FluTheme.dark ? Qt.rgba(61/255,61/255,61/255,1) : Qt.rgba(243/255,243/255,243/255,1) } - return "transparent" + if(Window.window.active){ + return FluTheme.dark ? Qt.rgba(26/255,34/255,41/255,1) : Qt.rgba(238/255,244/255,249/255,1) + } + return FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1) + } + Behavior on color{ + ColorAnimation { + duration: 300 + } } x: { if(d.displayMode !== FluNavigationView.Minimal) diff --git a/src/imports/FluentUI/Controls/FluWindow.qml b/src/imports/FluentUI/Controls/FluWindow.qml index 426d28dc..2c468ef4 100644 --- a/src/imports/FluentUI/Controls/FluWindow.qml +++ b/src/imports/FluentUI/Controls/FluWindow.qml @@ -1,10 +1,8 @@ import QtQuick import QtQuick.Window import QtQuick.Controls -import QtQuick.Controls.Basic import QtQuick.Layouts import FluentUI -import org.wangwenx190.FramelessHelper Window { enum LaunchMode { @@ -13,9 +11,6 @@ Window { SingleInstance } default property alias content: container.data - property bool fixSize - property alias titleVisible: title_bar.titleVisible - property bool appBarVisible: true property bool closeDestory: true property int launchMode: FluWindow.Standard property string route @@ -29,15 +24,15 @@ Window { event.accepted = false } } + property color backgroundColor: { + if(active){ + return FluTheme.dark ? Qt.rgba(26/255,34/255,40/255,1) : Qt.rgba(238/255,244/255,249/255,1) + } + return FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1) + } signal initArgument(var argument) id:window - property color backgroundColor: { - if(active){ - return FluTheme.dark ? Qt.rgba(26/255,34/255,40/255,1) : Qt.rgba(238/255,244/255,249/255,1) - } - return FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1) - } - color: "transparent" + color:"transparent" onClosing:(event)=>closeFunc(event) Component.onCompleted: { helper.initWindow(window) @@ -46,57 +41,21 @@ Window { Rectangle{ anchors.fill: parent color: backgroundColor - visible: { - if(!FramelessHelper.blurBehindWindowEnabled) - return true - return FluTheme.darkMode !== FluDarkMode.System && !FramelessHelper.blurBehindWindowEnabled - } Behavior on color{ ColorAnimation { duration: 300 } } } - FluAppBar { - id: title_bar - title: window.title - visible: window.appBarVisible - anchors { - top: parent.top - left: parent.left - right: parent.right - } - } Item{ id:container - anchors{ - top: title_bar.bottom - left: parent.left - right: parent.right - bottom: parent.bottom - } + anchors.fill: parent clip: true } FluInfoBar{ id:infoBar root: window } - FramelessHelper{ - id:framless_helper - onReady: { - setTitleBarItem(title_bar) - title_bar.maximizeButton.visible = false - title_bar.minimizeButton.visible = false - title_bar.closeButton.visible = false - framless_helper.moveWindowToDesktopCenter() - setHitTestVisible(title_bar.minimizeButton()) - setHitTestVisible(title_bar.maximizeButton()) - setHitTestVisible(title_bar.closeButton()) - framless_helper.setWindowFixedSize(fixSize) - title_bar.maximizeButton.visible = !fixSize - window.visible = true - } - } WindowHelper{ id:helper } @@ -118,12 +77,6 @@ Window { function deleteWindow(){ helper.deleteWindow() } - function setHitTestVisible(com){ - framless_helper.setHitTestVisible(com) - } - function setTitleBarItem(com){ - framless_helper.setTitleBarItem(com) - } function onResult(data){ if(pageRegister){ pageRegister.onResult(data)