From fd0ddbf5aa7d8606f2fe8a8b7dfe62a10cb650fa Mon Sep 17 00:00:00 2001 From: zhuzihcu Date: Tue, 13 Jun 2023 11:48:29 +0800 Subject: [PATCH] update --- example/qml/global/ItemsOriginal.qml | 15 ++++---- example/qml/page/T_Badge.qml | 14 +++++++ src/imports/FluentUI/Controls/FluBadge.qml | 37 +++++++++++-------- .../FluentUI/Controls/FluNavigationView.qml | 19 ++++++++++ src/imports/FluentUI/Controls/FluPaneItem.qml | 1 + 5 files changed, 64 insertions(+), 22 deletions(-) diff --git a/example/qml/global/ItemsOriginal.qml b/example/qml/global/ItemsOriginal.qml index ed071a89..73d4b23e 100644 --- a/example/qml/global/ItemsOriginal.qml +++ b/example/qml/global/ItemsOriginal.qml @@ -8,16 +8,17 @@ FluObject{ property var navigationView FluPaneItem{ + id:item_home + property int count: 8 title:lang.home + infoBadge:FluBadge{ + count: item_home.count + } icon:FluentIcons.Home - // cusIcon: Image{ - // anchors.centerIn: parent - // source: FluTheme.dark ? "qrc:/example/res/svg/home_dark.svg" : "qrc:/example/res/svg/home.svg" - // sourceSize: Qt.size(30,30) - // width: 18 - // height: 18 - // } onTap:{ + if(navigationView.getCurrentUrl()){ + item_home.count = 0 + } navigationView.push("qrc:/example/qml/page/T_Home.qml") } } diff --git a/example/qml/page/T_Badge.qml b/example/qml/page/T_Badge.qml index 159aa1d9..baccc3d7 100644 --- a/example/qml/page/T_Badge.qml +++ b/example/qml/page/T_Badge.qml @@ -33,6 +33,8 @@ FluScrollablePage{ radius: 8 color: Qt.rgba(191/255,191/255,191/255,1) FluBadge{ + topRight: true + showZero: true count:0 } } @@ -43,6 +45,8 @@ FluScrollablePage{ radius: 8 color: Qt.rgba(191/255,191/255,191/255,1) FluBadge{ + topRight: true + showZero: true count:5 } } @@ -52,6 +56,8 @@ FluScrollablePage{ radius: 8 color: Qt.rgba(191/255,191/255,191/255,1) FluBadge{ + topRight: true + showZero: true count:50 } } @@ -61,6 +67,8 @@ FluScrollablePage{ radius: 8 color: Qt.rgba(191/255,191/255,191/255,1) FluBadge{ + topRight: true + showZero: true count:100 } } @@ -70,6 +78,8 @@ FluScrollablePage{ radius: 8 color: Qt.rgba(191/255,191/255,191/255,1) FluBadge{ + topRight: true + showZero: true isDot:true } } @@ -79,6 +89,8 @@ FluScrollablePage{ radius: 8 color: Qt.rgba(191/255,191/255,191/255,1) FluBadge{ + topRight: true + showZero: true count:99 color: Qt.rgba(250/255,173/255,20/255,1) } @@ -89,6 +101,8 @@ FluScrollablePage{ radius: 8 color: Qt.rgba(191/255,191/255,191/255,1) FluBadge{ + topRight: true + showZero: true count:99 color: Qt.rgba(82/255,196/255,26/255,1) } diff --git a/src/imports/FluentUI/Controls/FluBadge.qml b/src/imports/FluentUI/Controls/FluBadge.qml index ee466967..6b57c28b 100644 --- a/src/imports/FluentUI/Controls/FluBadge.qml +++ b/src/imports/FluentUI/Controls/FluBadge.qml @@ -4,8 +4,9 @@ import FluentUI Rectangle{ property bool isDot: false - property bool showZero: true + property bool showZero: false property int count: 0 + property bool topRight: false id:control color:Qt.rgba(255/255,77/255,79/255,1) width: { @@ -14,7 +15,7 @@ Rectangle{ if(count<10){ return 20 }else if(count<100){ - return 30 + return 30 } return 40 } @@ -30,35 +31,41 @@ Rectangle{ } border.width: 1 border.color: Qt.rgba(1,1,1,1) - visible: { - if(showZero) - return true - return count!==0 - } anchors{ right: { - if(parent) + if(parent && topRight) return parent.right return undefined } top: { - if(parent) + if(parent && topRight) return parent.top return undefined } rightMargin: { - if(isDot){ - return -2.5 + if(parent && topRight){ + if(isDot){ + return -2.5 + } + return -(control.width/2) } - return -(control.width/2) + return 0 } topMargin: { - if(isDot){ - return -2.5 + if(parent && topRight){ + if(isDot){ + return -2.5 + } + return -10 } - return -10 + return 0 } } + visible: { + if(showZero) + return true + return count!==0 + } Text{ anchors.centerIn: parent color: Qt.rgba(1,1,1,1) diff --git a/src/imports/FluentUI/Controls/FluNavigationView.qml b/src/imports/FluentUI/Controls/FluNavigationView.qml index 379c7f1c..506245ba 100644 --- a/src/imports/FluentUI/Controls/FluNavigationView.qml +++ b/src/imports/FluentUI/Controls/FluNavigationView.qml @@ -440,6 +440,19 @@ Item { left:item_icon.right } } + Loader{ + anchors{ + right: parent.right + rightMargin: 10 + verticalCenter: parent.verticalCenter + } + sourceComponent: { + if(model.infoBadge){ + return model.infoBadge + } + return undefined + } + } } } } @@ -922,6 +935,12 @@ Item { function getCurrentIndex(){ return nav_list.currentIndex } + function getCurrentUrl(){ + if(nav_swipe.currentItem){ + return nav_swipe.currentItem.url + } + return undefined + } function startPageByItem(data){ var items = getItems() for(var i=0;i