From 5ee872935351045ca8d07b0c8b4092ff802ed44e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Thu, 2 Mar 2023 23:58:50 +0800 Subject: [PATCH] update --- example/AboutPage.qml | 3 +- example/MainPage.qml | 34 ++++++++++++--------- example/SettingPage.qml | 3 +- src/FluApp.cpp | 3 +- src/FramelessView_unix.cpp | 1 - src/FramelessView_win.cpp | 3 -- src/controls/FluDropShadow.qml | 2 +- src/controls/FluMenu.qml | 53 ++++++++++++-------------------- src/controls/FluMenuItem.qml | 55 ++++++++++++++++++++-------------- src/controls/FluRectangle.qml | 2 +- src/controls/FluWindow.qml | 4 ++- 11 files changed, 82 insertions(+), 81 deletions(-) diff --git a/example/AboutPage.qml b/example/AboutPage.qml index 92388a94..3039e751 100644 --- a/example/AboutPage.qml +++ b/example/AboutPage.qml @@ -4,11 +4,12 @@ import FluentUI 1.0 FluWindow { width: 500 - height: 500 + height: 600 title:"关于" FluAppBar{ id:appbar + title:"关于" } FluText{ diff --git a/example/MainPage.qml b/example/MainPage.qml index 5274d190..c68ce18e 100644 --- a/example/MainPage.qml +++ b/example/MainPage.qml @@ -9,10 +9,10 @@ import FluentUI 1.0 FluWindow { id:rootwindow width: 800 - height: 600 + height: 700 title: "FluentUI" minimumWidth: 600 - minimumHeight: 400 + minimumHeight: 500 FluAppBar{ id:appbar @@ -61,17 +61,6 @@ FluWindow { page:"qrc:/T_Typography.qml" } } - - FluMenu{ - id:menu - FluMenuItem{ - text:"123" - } - FluMenuItem{ - text:"456" - } - } - } FluIconButton{ @@ -82,8 +71,25 @@ FluWindow { leftMargin: 12 bottomMargin: 12 } + FluMenu{ + id:menu + x:40 + margins:4 + FluMenuItem{ + text:"关于" + onClicked:{ + FluApp.navigate("/About") + } + } + FluMenuItem{ + text:"设置" + onClicked:{ + FluApp.navigate("/Setting") + } + } + } onClicked:{ - menu.popup() + menu.open() } } diff --git a/example/SettingPage.qml b/example/SettingPage.qml index 8514536d..ad986c71 100644 --- a/example/SettingPage.qml +++ b/example/SettingPage.qml @@ -4,11 +4,12 @@ import FluentUI 1.0 FluWindow { width: 500 - height: 500 + height: 600 title:"设置" FluAppBar{ id:appbar + title:"设置" } FluText{ diff --git a/src/FluApp.cpp b/src/FluApp.cpp index 81507457..2a4a8006 100644 --- a/src/FluApp.cpp +++ b/src/FluApp.cpp @@ -41,11 +41,10 @@ void FluApp::navigate(const QString& route){ } bool isAppWindow = route==initialRoute(); FramelessView *view = new FramelessView(); - view->setColor(QColor(0,0,0,0)); + view->setColor(QColor(Qt::transparent)); QObject::connect(view, &QQuickView::statusChanged, view, [&](QQuickView::Status status) { if (status == QQuickView::Status::Ready) { Q_EMIT windowReady(view); - view->moveToScreenCenter(); view->show(); } diff --git a/src/FramelessView_unix.cpp b/src/FramelessView_unix.cpp index 895d2708..a129a10f 100644 --- a/src/FramelessView_unix.cpp +++ b/src/FramelessView_unix.cpp @@ -16,7 +16,6 @@ FramelessView::FramelessView(QWindow *parent) : Super(parent), d(new FramelessVi { setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint); setResizeMode(SizeRootObjectToView); - setIsMax(windowState() == Qt::WindowMaximized); setIsFull(windowState() == Qt::WindowFullScreen); connect(this, &QWindow::windowStateChanged, this, [&](Qt::WindowState state) { diff --git a/src/FramelessView_win.cpp b/src/FramelessView_win.cpp index 07107359..48b7a162 100644 --- a/src/FramelessView_win.cpp +++ b/src/FramelessView_win.cpp @@ -21,13 +21,10 @@ static bool isFullWin(QQuickView* win) { return win->windowState() == Qt::WindowFullScreen; } - - FramelessView::FramelessView(QWindow *parent) : Super(parent), d(new FramelessViewPrivate) { setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint); setResizeMode(SizeRootObjectToView); - setIsMax(windowState() == Qt::WindowMaximized); setIsFull(windowState() == Qt::WindowFullScreen); connect(this, &QWindow::windowStateChanged, this, [&](Qt::WindowState state) { diff --git a/src/controls/FluDropShadow.qml b/src/controls/FluDropShadow.qml index 58e55668..4438a97c 100644 --- a/src/controls/FluDropShadow.qml +++ b/src/controls/FluDropShadow.qml @@ -4,5 +4,5 @@ import QtGraphicalEffects 1.15 DropShadow { radius: 5 samples: 4 - color: FluApp.isDark ? "#80FFFFFF" : "#80000000" + color: FluApp.isDark ? "#80FFFFFF" : "#40000000" } diff --git a/src/controls/FluMenu.qml b/src/controls/FluMenu.qml index 0966788a..c6ec5684 100644 --- a/src/controls/FluMenu.qml +++ b/src/controls/FluMenu.qml @@ -1,41 +1,26 @@ import QtQuick 2.15 +import QtQuick.Layouts 1.15 import QtQuick.Controls 2.15 -import QtQuick.Controls.impl 2.15 -import QtQuick.Templates 2.15 as T -import QtQuick.Window 2.15 -import QtGraphicalEffects 1.15 -T.Menu { - id: control +Popup { + id: popup + default property alias content: container.children - implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, - contentWidth + leftPadding + rightPadding) - implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, - contentHeight + topPadding + bottomPadding) - margins: 0 - delegate: FluMenuItem { } - - contentItem: ListView { - implicitHeight: contentHeight - model: control.contentModel - interactive: Window.window ? contentHeight > Window.window.height : false - clip: true - currentIndex: control.currentIndex - ScrollIndicator.vertical: ScrollIndicator {} - } - - background: Item { - implicitWidth: 122 - implicitHeight: 30 - Rectangle{ - anchors.fill: parent - color: "#FFFFFF" - layer.effect: FluDropShadow{} - layer.enabled: true + background: FluRectangle { + implicitWidth: 140 + implicitHeight: container.height + color:FluApp.isDark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(237/255,237/255,237/255,1) + radius: [5,5,5,5] + layer.effect: FluDropShadow{} + layer.enabled: true + Column{ + spacing: 5 + topPadding: 5 + bottomPadding: 5 + id:container + function closePopup(){ + popup.close() + } } - - } - - } diff --git a/src/controls/FluMenuItem.qml b/src/controls/FluMenuItem.qml index e5b3b0ed..4d92e52a 100644 --- a/src/controls/FluMenuItem.qml +++ b/src/controls/FluMenuItem.qml @@ -1,29 +1,40 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 -import QtQuick.Controls.impl 2.15 -import QtQuick.Templates 2.15 as T -import QtQuick.Shapes 1.15 -T.MenuItem { - id: control +Item { - implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, - implicitContentWidth + leftPadding + rightPadding) - implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, - implicitContentHeight + topPadding + bottomPadding, - implicitIndicatorHeight + topPadding + bottomPadding) - padding: 0 - spacing: 6 + id:root + width: 140 + height: 32 - contentItem: FluText { - text: control.text + property string text: "MenuItem" + signal clicked + + Rectangle{ + anchors.centerIn: parent + width: 100 + height: 32 + radius: 4 + color:{ + if(mouse_area.containsMouse){ + return FluApp.isDark ? Qt.rgba(56/255,56/255,56/255,1) : Qt.rgba(230/255,230/255,230/255,1) + } + return FluApp.isDark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(237/255,237/255,237/255,1) + } + + FluText{ + text: root.text + anchors.centerIn: parent + } + + MouseArea{ + id:mouse_area + hoverEnabled: true + anchors.fill: parent + onClicked: { + root.clicked() + root.parent.closePopup() + } + } } - - background: Rectangle { - implicitWidth: 120 - implicitHeight: 30 - width: control.width - height: control.height - } - } diff --git a/src/controls/FluRectangle.qml b/src/controls/FluRectangle.qml index 5991a030..f373dacf 100644 --- a/src/controls/FluRectangle.qml +++ b/src/controls/FluRectangle.qml @@ -14,7 +14,7 @@ Item{ id:container width: root.width height: root.height - visible: false + opacity: 0 color:root.color } diff --git a/src/controls/FluWindow.qml b/src/controls/FluWindow.qml index f4426681..35dff104 100644 --- a/src/controls/FluWindow.qml +++ b/src/controls/FluWindow.qml @@ -46,7 +46,9 @@ Item { layer.enabled: true layer.effect: DropShadow { radius: 5 - samples: 4 + samples: 5 + horizontalOffset: 0 + verticalOffset: 0 color: "#40000000" } }