From a89d36fd143379454a31800124a4b195e634862b Mon Sep 17 00:00:00 2001 From: zhuzihcu Date: Wed, 17 May 2023 18:15:15 +0800 Subject: [PATCH] update --- example/CMakeLists.txt | 2 + example/qml/component/CustomWindow.qml | 62 +++++++++++++++++++++ example/qml/window/AboutWindow.qml | 8 +-- example/qml/window/LoginWindow.qml | 8 +-- example/qml/window/MainWindow.qml | 49 ++++++++-------- example/qml/window/MediaWindow.qml | 3 +- example/qml/window/SingleInstanceWindow.qml | 13 +++-- example/qml/window/SingleTaskWindow.qml | 8 +-- example/qml/window/StandardWindow.qml | 8 +-- example/src/main.cpp | 18 ++++-- src/CMakeLists.txt | 6 +- src/FluentUI.cpp | 25 --------- src/FluentUI.h | 17 ------ src/imports/FluentUI/Controls/FluAppBar.qml | 35 ++++++++---- src/imports/FluentUI/Controls/FluWindow.qml | 32 +---------- 15 files changed, 150 insertions(+), 144 deletions(-) create mode 100644 example/qml/component/CustomWindow.qml delete mode 100644 src/FluentUI.cpp delete mode 100644 src/FluentUI.h diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 8b479661..5ca53825 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -94,6 +94,8 @@ set_target_properties(example PROPERTIES target_link_libraries(example PRIVATE Qt6::Quick fluentuiplugin + FramelessHelper::Core + FramelessHelper::Quick ) #安装 diff --git a/example/qml/component/CustomWindow.qml b/example/qml/component/CustomWindow.qml new file mode 100644 index 00000000..6d991109 --- /dev/null +++ b/example/qml/component/CustomWindow.qml @@ -0,0 +1,62 @@ +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 + + onFixSizeChanged: { + framless_helper.setWindowFixedSize(fixSize) + title_bar.maximizeButton.visible = !fixSize + } + + 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 + } + 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()) + 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 74266343..475333c3 100644 --- a/example/qml/window/AboutWindow.qml +++ b/example/qml/window/AboutWindow.qml @@ -2,17 +2,15 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI +import "../component" -FluWindow { +CustomWindow { id:window title:"关于" width: 600 height: 600 - minimumWidth: 600 - minimumHeight: 600 - maximumWidth: 600 - maximumHeight: 600 + fixSize: true launchMode: FluWindow.SingleTask ColumnLayout{ diff --git a/example/qml/window/LoginWindow.qml b/example/qml/window/LoginWindow.qml index 41dbc9f7..25d8bada 100644 --- a/example/qml/window/LoginWindow.qml +++ b/example/qml/window/LoginWindow.qml @@ -2,17 +2,15 @@ import QtQuick.Layouts import QtQuick.Controls import FluentUI +import "../component" -FluWindow { +CustomWindow { id:window title:"登录" width: 400 height: 400 - minimumWidth: 400 - minimumHeight: 400 - maximumWidth: 400 - maximumHeight: 400 + fixSize: true onInitArgument: (argument)=>{ diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index 4904cee5..b7e3615d 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" @@ -15,6 +16,7 @@ FluWindow { closeDestory:false minimumWidth: 520 minimumHeight: 460 + appBarVisible: false launchMode: FluWindow.SingleTask closeFunc:function(event){ @@ -71,12 +73,33 @@ FluWindow { window.deleteWindow() FluApp.closeApp() } + } + FluAppBar { + id: title_bar + anchors { + top: parent.top + left: parent.left + right: parent.right + } + showDark: true + Component.onCompleted: { + setTitleBarItem(title_bar) + setHitTestVisible(title_bar.minimizeButton()) + setHitTestVisible(title_bar.maximizeButton()) + setHitTestVisible(title_bar.closeButton()) + } } FluNavigationView{ id:nav_view - anchors.fill: parent + anchors{ + top: title_bar.bottom + topMargin: -20 + left: parent.left + right: parent.right + bottom: parent.bottom + } items: ItemsOriginal footerItems:ItemsFooter z:11 @@ -94,32 +117,10 @@ FluWindow { ItemsOriginal.startPageByItem(data) } } - actionItem:Item{ - height: 40 - width: 148 - RowLayout{ - anchors.centerIn: parent - spacing: 5 - FluText{ - text:lang.dark_mode - } - FluToggleSwitch{ - selected: FluTheme.dark - clickFunc:function(){ - if(FluTheme.dark){ - FluTheme.darkMode = FluDarkMode.Light - }else{ - FluTheme.darkMode = FluDarkMode.Dark - } - } - } - } - } Component.onCompleted: { ItemsOriginal.navigationView = nav_view ItemsFooter.navigationView = nav_view nav_view.setCurrentIndex(0) } } - } 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 4fad5527..0da4951d 100644 --- a/example/qml/window/SingleInstanceWindow.qml +++ b/example/qml/window/SingleInstanceWindow.qml @@ -2,17 +2,15 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI +import "../component" -FluWindow { +CustomWindow { id:window title:"SingleInstance" width: 500 height: 600 - minimumWidth: 500 - minimumHeight: 600 - maximumWidth: 500 - maximumHeight: 600 + fixSize: true launchMode: FluWindow.SingleInstance FluTextBox{ @@ -35,4 +33,9 @@ FluWindow { text:"我是一个SingleInstance模式的窗口,如果我存在,我会销毁之前的窗口,并创建一个新窗口" } + FluAppBar{ + id:appbar + width: parent.width + height: 30 + } } diff --git a/example/qml/window/SingleTaskWindow.qml b/example/qml/window/SingleTaskWindow.qml index 510195b2..1e6f69ea 100644 --- a/example/qml/window/SingleTaskWindow.qml +++ b/example/qml/window/SingleTaskWindow.qml @@ -2,17 +2,15 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI +import "../component" -FluWindow { +CustomWindow { id:window title:"SingleTask" width: 500 height: 600 - minimumWidth: 500 - minimumHeight: 600 - maximumWidth: 500 - maximumHeight: 600 + fixSize: true launchMode: FluWindow.SingleTask FluText{ diff --git a/example/qml/window/StandardWindow.qml b/example/qml/window/StandardWindow.qml index 5fe6f795..6724753d 100644 --- a/example/qml/window/StandardWindow.qml +++ b/example/qml/window/StandardWindow.qml @@ -2,17 +2,15 @@ import QtQuick.Controls import QtQuick.Layouts import FluentUI +import "../component" -FluWindow { +CustomWindow { id:window title:"Standard" width: 500 height: 600 - minimumWidth: 500 - minimumHeight: 600 - maximumWidth: 500 - maximumHeight: 600 + fixSize: true launchMode: FluWindow.Standard FluText{ diff --git a/example/src/main.cpp b/example/src/main.cpp index 01533cd0..0846374e 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -4,21 +4,31 @@ #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[]) { + FramelessHelper::Quick::initialize(); + qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); + //6.4及以下监听系统深色模式变化 +#ifdef Q_OS_WIN + qputenv("QT_QPA_PLATFORM","windows:darkmode=2"); +#endif //将样式设置为Basic,不然会导致组件显示异常 - FluentUI::preInit(); 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"; @@ -35,7 +45,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 674787db..45a40648 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,8 +44,6 @@ foreach(filepath IN LISTS qml_files resource_files) set_source_files_properties(${filepath} PROPERTIES QT_RESOURCE_ALIAS ${filename}) endforeach() -set_source_files_properties(FluentUI.h PROPERTIES QT_RESOURCE_ALIAS "../../include/FluentUI/FluentUI.h") - #添加qml模块 qt_add_library(fluentuiplugin SHARED) qt_add_qml_module(fluentuiplugin @@ -56,7 +54,7 @@ qt_add_qml_module(fluentuiplugin URI "FluentUI" SOURCES ${sources_files} fluentui.rc QML_FILES ${qml_files} - RESOURCES ${resource_files} FluentUI.h + RESOURCES ${resource_files} #支持designer DESIGNER_SUPPORTED ) @@ -66,8 +64,6 @@ target_link_libraries(fluentuiplugin PUBLIC Qt::Core Qt::Quick Qt::Qml - FramelessHelper::Core - FramelessHelper::Quick ) #链接库 win32库 不然mingw会编译错误 diff --git a/src/FluentUI.cpp b/src/FluentUI.cpp deleted file mode 100644 index 258aec84..00000000 --- a/src/FluentUI.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "FluentUI.h" -#include -#include - -FRAMELESSHELPER_USE_NAMESPACE; - -void FluentUI::preInit(){ - qDebug()<<"FluentUI init"; - FramelessHelper::Quick::initialize(); - qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); - //6.4及以下监听系统深色模式变化 -#ifdef Q_OS_WIN - qputenv("QT_QPA_PLATFORM","windows:darkmode=2"); -#endif -} - -void FluentUI::postInit(){ - FramelessHelper::Core::setApplicationOSThemeAware(); - FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); - FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial); -} - -void FluentUI::initEngine(QQmlApplicationEngine *engine){ - FramelessHelper::Quick::registerTypes(engine); -} diff --git a/src/FluentUI.h b/src/FluentUI.h deleted file mode 100644 index d11b7f62..00000000 --- a/src/FluentUI.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef FLUENTUI_H -#define FLUENTUI_H - -#include -#include -#include - -class Q_DECL_EXPORT FluentUI -{ - -public: - static void preInit(); - static void postInit(); - static void initEngine(QQmlApplicationEngine *engine); -}; - -#endif // FLUENTUI_H diff --git a/src/imports/FluentUI/Controls/FluAppBar.qml b/src/imports/FluentUI/Controls/FluAppBar.qml index 41643340..a8ff779a 100644 --- a/src/imports/FluentUI/Controls/FluAppBar.qml +++ b/src/imports/FluentUI/Controls/FluAppBar.qml @@ -19,10 +19,10 @@ Rectangle{ property color closeNormalColor: Qt.rgba(0,0,0,0) property color closeHoverColor: Qt.rgba(251/255,115/255,115/255,1) property bool showDark: false + property bool titleVisible: true property color borerlessColor : FluTheme.dark ? FluTheme.primaryColor.lighter : FluTheme.primaryColor.dark id:root color: Qt.rgba(0,0,0,0) - visible: false height: visible ? 30 : 0 opacity: visible z: 65535 @@ -33,7 +33,7 @@ Rectangle{ property bool resizable: win && !(win.minimumHeight === win.maximumHeight && win.maximumWidth === win.minimumWidth) } TapHandler { - onTapped: if (tapCount === 2) toggleMaximized() + onTapped: if (tapCount === 2) btn_maximize.clicked() gesturePolicy: TapHandler.DragThreshold } DragHandler { @@ -48,6 +48,7 @@ Rectangle{ left: parent.left leftMargin: 10 } + visible: root.titleVisible color:root.textColor } RowLayout{ @@ -75,6 +76,7 @@ Rectangle{ } } FluIconButton{ + id:btn_minimize width: 40 height: 30 iconSource : FluentIcons.ChromeMinimize @@ -85,10 +87,11 @@ Rectangle{ iconColor: root.textColor color: hovered ? minimizeHoverColor : minimizeNormalColor onClicked: { - d.win.showMinimized() + d.win.visibility = Window.Minimized } } FluIconButton{ + id:btn_maximize width: 40 height: 30 iconSource : d.isRestore ? FluentIcons.ChromeRestore : FluentIcons.ChromeMaximize @@ -100,10 +103,14 @@ Rectangle{ text:d.isRestore?restoreText:maximizeText iconSize: 11 onClicked: { - toggleMaximized() + if (d.win.visibility === Window.Maximized) + d.win.visibility = Window.Windowed + else + d.win.visibility = Window.Maximized } } FluIconButton{ + id:btn_close iconSource : FluentIcons.ChromeClose Layout.alignment: Qt.AlignVCenter text:closeText @@ -118,13 +125,17 @@ Rectangle{ } } } - function toggleMaximized() { - if(!d.resizable) - return - if (d.win.visibility === Window.Maximized) { - d.win.showNormal(); - } else { - d.win.showMaximized(); - } + + function minimizeButton(){ + return btn_minimize } + + function maximizeButton(){ + return btn_maximize + } + + function closeButton(){ + return btn_close + } + } diff --git a/src/imports/FluentUI/Controls/FluWindow.qml b/src/imports/FluentUI/Controls/FluWindow.qml index 76acf3a4..2c468ef4 100644 --- a/src/imports/FluentUI/Controls/FluWindow.qml +++ b/src/imports/FluentUI/Controls/FluWindow.qml @@ -3,7 +3,6 @@ import QtQuick.Window import QtQuick.Controls import QtQuick.Layouts import FluentUI -import org.wangwenx190.FramelessHelper Window { enum LaunchMode { @@ -25,7 +24,6 @@ Window { event.accepted = false } } - visible: true 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) @@ -49,26 +47,9 @@ Window { } } } -// StandardTitleBar { -// id: title_bar -// z:999 -// anchors { -// top: parent.top -// topMargin: window.visibility === Window.Windowed ? 1 : 0 -// left: parent.left -// right: parent.right -// } -// // windowIcon: "qrc:///images/microsoft.svg" -// windowIconVisible: false -// } Item{ id:container - anchors{ - top: parent.top - left: parent.left - right: parent.right - bottom: parent.bottom - } + anchors.fill: parent clip: true } FluInfoBar{ @@ -78,16 +59,6 @@ Window { WindowHelper{ id:helper } -// FramelessHelper.onReady: { -// FramelessHelper.titleBarItem = title_bar -// FramelessHelper.moveWindowToDesktopCenter() -// if (Qt.platform.os !== "macos") { -// FramelessHelper.setSystemButton(title_bar.minimizeButton, FramelessHelperConstants.Minimize); -// FramelessHelper.setSystemButton(title_bar.maximizeButton, FramelessHelperConstants.Maximize); -// FramelessHelper.setSystemButton(title_bar.closeButton, FramelessHelperConstants.Close); -// } -// window.visible = true -// } function showSuccess(text,duration,moremsg){ infoBar.showSuccess(text,duration,moremsg) } @@ -111,5 +82,4 @@ Window { pageRegister.onResult(data) } } - }