From 1491abc614923b26196c70e190e565f897a1433a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Thu, 18 May 2023 20:32:53 +0800 Subject: [PATCH] update --- example/CMakeLists.txt | 2 - example/qml/component/CustomWindow.qml | 60 --------------------- example/qml/window/AboutWindow.qml | 3 +- example/qml/window/LoginWindow.qml | 3 +- example/qml/window/MainWindow.qml | 3 +- 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 | 4 ++ src/FluGlobal.cpp | 12 +++++ src/imports/FluentUI/Controls/FluWindow.qml | 40 +++++++++++++- 13 files changed, 63 insertions(+), 89 deletions(-) delete mode 100644 example/qml/component/CustomWindow.qml diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 35a8f55a..000ccdbc 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -94,8 +94,6 @@ set_target_properties(example PROPERTIES #链接库 target_link_libraries(example PRIVATE Qt6::Quick - FramelessHelper::Core - FramelessHelper::Quick fluentuiplugin ) diff --git a/example/qml/component/CustomWindow.qml b/example/qml/component/CustomWindow.qml deleted file mode 100644 index 8eb2114c..00000000 --- a/example/qml/component/CustomWindow.qml +++ /dev/null @@ -1,60 +0,0 @@ -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 475333c3..818b3428 100644 --- a/example/qml/window/AboutWindow.qml +++ b/example/qml/window/AboutWindow.qml @@ -2,9 +2,8 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI -import "../component" -CustomWindow { +FluWindow { id:window title:"关于" diff --git a/example/qml/window/LoginWindow.qml b/example/qml/window/LoginWindow.qml index 25d8bada..103ab444 100644 --- a/example/qml/window/LoginWindow.qml +++ b/example/qml/window/LoginWindow.qml @@ -2,9 +2,8 @@ import QtQuick.Layouts import QtQuick.Controls import FluentUI -import "../component" -CustomWindow { +FluWindow { id:window title:"登录" diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index 73ac84cf..4c395bbb 100644 --- a/example/qml/window/MainWindow.qml +++ b/example/qml/window/MainWindow.qml @@ -4,10 +4,9 @@ import QtQuick.Controls import QtQuick.Layouts import Qt.labs.platform import FluentUI -import "../component" import "qrc:///example/qml/global/" -CustomWindow { +FluWindow { id:window title: "FluentUI" diff --git a/example/qml/window/MediaWindow.qml b/example/qml/window/MediaWindow.qml index 1f2d9942..d16956ad 100644 --- a/example/qml/window/MediaWindow.qml +++ b/example/qml/window/MediaWindow.qml @@ -2,9 +2,8 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI -import "../component" -CustomWindow { +FluWindow { title:"视频播放器" width: 640 diff --git a/example/qml/window/SingleInstanceWindow.qml b/example/qml/window/SingleInstanceWindow.qml index f5d13873..940db2ca 100644 --- a/example/qml/window/SingleInstanceWindow.qml +++ b/example/qml/window/SingleInstanceWindow.qml @@ -2,9 +2,8 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI -import "../component" -CustomWindow { +FluWindow { id:window title:"SingleInstance" diff --git a/example/qml/window/SingleTaskWindow.qml b/example/qml/window/SingleTaskWindow.qml index 1e6f69ea..33195aa9 100644 --- a/example/qml/window/SingleTaskWindow.qml +++ b/example/qml/window/SingleTaskWindow.qml @@ -2,9 +2,8 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI -import "../component" -CustomWindow { +FluWindow { id:window title:"SingleTask" diff --git a/example/qml/window/StandardWindow.qml b/example/qml/window/StandardWindow.qml index 6724753d..40347bca 100644 --- a/example/qml/window/StandardWindow.qml +++ b/example/qml/window/StandardWindow.qml @@ -2,9 +2,8 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI -import "../component" -CustomWindow { +FluWindow { id:window title:"Standard" diff --git a/example/src/main.cpp b/example/src/main.cpp index d4b07bd9..cd749298 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -4,30 +4,20 @@ #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[]) +int main(int argc, char *argv[]) { FluentUI::preInit(); - FramelessHelper::Quick::initialize(); - //将样式设置为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); FluentUI::postInit(); - // 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"; @@ -45,7 +35,6 @@ FRAMELESSHELPER_USE_NAMESPACE 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 c5e0fa8b..8b4b7e5d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,6 +57,8 @@ qt_add_qml_module(fluentuiplugin RESOURCES ${resource_files} FluGlobal.h #支持designer DESIGNER_SUPPORTED + DEPENDENCIES + org.wangwenx190.FramelessHelper/auto ) #链接库 @@ -64,6 +66,8 @@ 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 index b92411ea..52d31b11 100644 --- a/src/FluGlobal.cpp +++ b/src/FluGlobal.cpp @@ -1,17 +1,29 @@ #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/imports/FluentUI/Controls/FluWindow.qml b/src/imports/FluentUI/Controls/FluWindow.qml index 2c468ef4..6970098f 100644 --- a/src/imports/FluentUI/Controls/FluWindow.qml +++ b/src/imports/FluentUI/Controls/FluWindow.qml @@ -3,6 +3,7 @@ import QtQuick.Window import QtQuick.Controls import QtQuick.Layouts import FluentUI +import org.wangwenx190.FramelessHelper Window { enum LaunchMode { @@ -11,6 +12,9 @@ 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 @@ -47,15 +51,43 @@ Window { } } } + FluAppBar { + id: title_bar + title: window.title + visible: window.appBarVisible + anchors { + top: parent.top + left: parent.left + right: parent.right + } + } Item{ id:container - anchors.fill: parent + anchors{ + top: title_bar.bottom + left: parent.left + right: parent.right + bottom: parent.bottom + } clip: true } FluInfoBar{ id:infoBar root: window } + 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 + } + } WindowHelper{ id:helper } @@ -77,6 +109,12 @@ 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)