From edeee77c443075ffb80a7e981a822718b47c2c7f Mon Sep 17 00:00:00 2001 From: Mentalflow <312902918@qq.com> Date: Fri, 5 Apr 2024 01:43:28 +0800 Subject: [PATCH] RibbonWindow: Add window manager. --- example/CMakeLists.txt | 2 +- example/about.qml | 44 +++++++++++++++++++++++++++++++++ example/example.qml | 12 +++++++++ lib_source/qml/RibbonWindow.qml | 41 ++++++++++++++++++++++++------ 4 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 example/about.qml diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 204cf3e..83e482c 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -85,7 +85,7 @@ qt_add_qml_module(${PROJECT_NAME} URI ${PROJECT_NAME} VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} RESOURCE_PREFIX "/qt/qml/" - QML_FILES example.qml components/RibbonMessageListViewExample.qml + QML_FILES example.qml about.qml components/RibbonMessageListViewExample.qml RESOURCES resources/imgs/heart.png resources/imgs/search.png ) diff --git a/example/about.qml b/example/about.qml new file mode 100644 index 0000000..ea47a57 --- /dev/null +++ b/example/about.qml @@ -0,0 +1,44 @@ +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls +import RibbonUI + +RibbonWindow { + id: window + width: Math.max(content.width, content.height + title_bar.height) + content.anchors.margins * 2 + height: width + title: qsTr("About") + title_bar.show_darkmode_btn: false + title_bar.show_style_switch: false + + ColumnLayout{ + id: content + anchors{ + centerIn: parent + margins: 10 + } + spacing: 5 + Image { + source: "qrc:/qt/qml/RibbonUI/resources/imgs/icon.png" + fillMode:Image.PreserveAspectFit + Layout.preferredHeight: 120 + Layout.preferredWidth: height + Layout.alignment: Qt.AlignHCenter + layer.enabled: true + layer.effect: RibbonShadow{} + } + RibbonText{ + Layout.alignment: Qt.AlignHCenter + text: "RibbonUI" + font.pixelSize: 16 + } + RibbonText{ + Layout.alignment: Qt.AlignHCenter + text: `©${new Date().getFullYear()} mentalfl0w` + } + RibbonText{ + Layout.alignment: Qt.AlignHCenter + text: `Version: V${RibbonUI.version}` + } + } +} diff --git a/example/example.qml b/example/example.qml index fb2eb8d..98277e3 100644 --- a/example/example.qml +++ b/example/example.qml @@ -8,6 +8,7 @@ RibbonWindow { width: 1200 height: 800 title: qsTr("RibbonUI APP") + comfirmed_quit: true property bool modern_style: RibbonTheme.modern_style RibbonTabBar { @@ -693,6 +694,17 @@ RibbonWindow { title_bar.right_content:RowLayout{ spacing: 1 layoutDirection: Qt.RightToLeft + RibbonButton{ + show_bg:false + icon_source: RibbonIcons.Info + icon_source_filled: RibbonIcons_Filled.Info + tip_text: qsTr("About") + hover_color: Qt.rgba(0,0,0, 0.3) + pressed_color: Qt.rgba(0,0,0, 0.4) + text_color: title_bar.title_text_color + text_color_reverse: false + onClicked: root.show_window(Qt.resolvedUrl("about.qml")) + } RibbonButton{ show_bg:false icon_source: RibbonIcons.CalendarStar diff --git a/lib_source/qml/RibbonWindow.qml b/lib_source/qml/RibbonWindow.qml index 1dda534..36038fa 100644 --- a/lib_source/qml/RibbonWindow.qml +++ b/lib_source/qml/RibbonWindow.qml @@ -85,28 +85,55 @@ Window { target_rect: Qt.rect(window_items.x + x, window_items.y + y, width, height) blur_enabled: true } + RibbonPopupDialog{ - id: dialog + id: close_dialog target: window_items blur_enabled: true target_rect: Qt.rect(window_items.x + x, window_items.y + y, width, height) positiveText: qsTr("Quit") neutralText: qsTr("Minimize") negativeText: qsTr("Cancel") - message: "Do you want to quit the APP?" - title: "Please note" + message: qsTr("Do you want to close this window?") + title: qsTr("Please note") buttonFlags: RibbonPopupDialogType.NegativeButton | RibbonPopupDialogType.PositiveButton | RibbonPopupDialogType.NeutralButton onNeutralClicked: window.visibility = Window.Minimized onPositiveClicked: { - comfirmed_quit = true + comfirmed_quit = false Qt.quit() } } + onClosing:function(event){ window.raise() - event.accepted = comfirmed_quit - if (!comfirmed_quit) - dialog.open() + event.accepted = !comfirmed_quit + if (comfirmed_quit) + close_dialog.open() + } + + Loader{ + id: window_loader + property var args + onLoaded: { + item.onClosing.connect(function(){ + window_loader.source = "" + }) + if (!window_loader.args) + return + else if(Object.keys(window_loader.args).length){ + for (let arg in window_loader.args){ + item[arg] = window_loader.args[arg] + } + } + else{ + console.error("RibbonWindow: Arguments error, please check.") + } + } + } + + function show_window(window_url, args){ + window_loader.args = args + window_loader.source = window_url } function show_popup(content_url, arguments)