From 2de9d78f41bb1c6aa6d69a8e2b538b2d62a5d7af Mon Sep 17 00:00:00 2001 From: zhuzihcu Date: Thu, 16 Mar 2023 18:11:03 +0800 Subject: [PATCH] update --- example/T_Buttons.qml | 77 +++++++++++++++++------------- src/controls/FluDatePicker.qml | 32 ++++++------- src/controls/FluDropDownButton.qml | 14 +++++- src/controls/FluTimePicker.qml | 28 ++++++----- 4 files changed, 85 insertions(+), 66 deletions(-) diff --git a/example/T_Buttons.qml b/example/T_Buttons.qml index 52e540c..8204d11 100644 --- a/example/T_Buttons.qml +++ b/example/T_Buttons.qml @@ -115,6 +115,49 @@ FluScrollablePage{ } } + FluArea{ + width: parent.width + height: 68 + paddings: 10 + + FluDropDownButton{ + disabled:drop_down_button_switch.selected + text:"DropDownButton" + anchors{ + verticalCenter: parent.verticalCenter + left: parent.left + } + items:[ + FluMenuItem{ + text:"Menu_1" + }, + FluMenuItem{ + text:"Menu_2" + }, + FluMenuItem{ + text:"Menu_3" + }, + FluMenuItem{ + text:"Menu_4" + } + ] + } + Row{ + spacing: 5 + anchors{ + verticalCenter: parent.verticalCenter + right: parent.right + } + FluToggleSwitch{ + id:drop_down_button_switch + Layout.alignment: Qt.AlignRight + } + FluText{ + text:"Disabled" + } + } + } + FluArea{ width: parent.width height: 100 @@ -190,39 +233,5 @@ FluScrollablePage{ } } - FluArea{ - width: parent.width - height: 68 - paddings: 10 - FluDropDownButton{ - disabled:drop_down_button_switch.selected - text:"DropDownButton" - anchors{ - verticalCenter: parent.verticalCenter - left: parent.left - } - items:[ - FluMenuItem{ - text:"asdf" - } - ] - } - - - Row{ - spacing: 5 - anchors{ - verticalCenter: parent.verticalCenter - right: parent.right - } - FluToggleSwitch{ - id:drop_down_button_switch - Layout.alignment: Qt.AlignRight - } - FluText{ - text:"Disabled" - } - } - } } diff --git a/src/controls/FluDatePicker.qml b/src/controls/FluDatePicker.qml index b08aa44..ba9a9c8 100644 --- a/src/controls/FluDatePicker.qml +++ b/src/controls/FluDatePicker.qml @@ -205,6 +205,9 @@ Rectangle { ScrollBar.vertical: FluScrollBar {} model: generateYearArray(1924,2048) clip: true + preferredHighlightBegin: 0 + preferredHighlightEnd: 0 + highlightMoveDuration: 0 visible: showYear delegate: Loader{ property var model: modelData @@ -212,11 +215,6 @@ Rectangle { property int position:index sourceComponent: list_delegate } - onCurrentIndexChanged: { - if(currentIndex!==-1){ - list_view_1.positionViewAtIndex(currentIndex, ListView.NoPosition) - } - } } Rectangle{ width: 1 @@ -229,6 +227,9 @@ Rectangle { height: parent.height clip: true ScrollBar.vertical: FluScrollBar {} + preferredHighlightBegin: 0 + preferredHighlightEnd: 0 + highlightMoveDuration: 0 boundsBehavior:Flickable.StopAtBounds delegate: Loader{ property var model: modelData @@ -236,11 +237,6 @@ Rectangle { property int position:index sourceComponent: list_delegate } - onCurrentIndexChanged: { - if(currentIndex!==-1){ - list_view_2.positionViewAtIndex(currentIndex, ListView.NoPosition) - } - } } Rectangle{ width: 1 @@ -252,6 +248,9 @@ Rectangle { width: showYear ? 100 : 150 height: parent.height clip: true + preferredHighlightBegin: 0 + preferredHighlightEnd: 0 + highlightMoveDuration: 0 ScrollBar.vertical: FluScrollBar {} Layout.alignment: Qt.AlignVCenter boundsBehavior:Flickable.StopAtBounds @@ -261,9 +260,6 @@ Rectangle { property int position:index sourceComponent: list_delegate } - onCurrentIndexChanged: { - list_view_3.positionViewAtIndex(currentIndex, ListView.NoPosition) - } } } @@ -348,10 +344,12 @@ Rectangle { text_day.text = day var pos = root.mapToItem(null, 0, 0) - if(window.height>pos.y+35+340){ - popup.y = 35 - }else{ - popup.y = window.height-(pos.y+340) + if(window.height>pos.y+root.height+popup.height){ + popup.y = root.height + } else if(pos.y>popup.height){ + popup.y = -popup.height + } else { + popup.y = window.height-(pos.y+popup.height) } popup.open() } diff --git a/src/controls/FluDropDownButton.qml b/src/controls/FluDropDownButton.qml index fb668bc..29d24b0 100644 --- a/src/controls/FluDropDownButton.qml +++ b/src/controls/FluDropDownButton.qml @@ -1,5 +1,6 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 +import QtQuick.Window 2.15 import FluentUI 1.0 Button { @@ -16,6 +17,7 @@ Button { rightPadding:35 enabled: !disabled focusPolicy:Qt.TabFocus + property var window : Window.window property alias items: menu.content @@ -68,12 +70,20 @@ Button { } onClicked: { + var pos = control.mapToItem(null, 0, 0) + if(window.height>pos.y+control.height+menu.height){ + menu.y = control.height + }else if(pos.y>menu.height){ + menu.y = -menu.height + }else{ + popup.y = window.height-(pos.y+menu.height) + } menu.open() } FluMenu{ - id:menu - width: control.width + id:menu + width: control.width } } diff --git a/src/controls/FluTimePicker.qml b/src/controls/FluTimePicker.qml index cba7053..e4c2def 100644 --- a/src/controls/FluTimePicker.qml +++ b/src/controls/FluTimePicker.qml @@ -202,6 +202,9 @@ Rectangle { height: parent.height boundsBehavior:Flickable.StopAtBounds ScrollBar.vertical: FluScrollBar {} + preferredHighlightBegin: 0 + preferredHighlightEnd: 0 + highlightMoveDuration: 0 model: isH ? generateArray(1,12) : generateArray(0,23) clip: true delegate: Loader{ @@ -210,9 +213,6 @@ Rectangle { property int position:index sourceComponent: list_delegate } - onCurrentIndexChanged: { - list_view_1.positionViewAtIndex(currentIndex, ListView.NoPosition) - } } Rectangle{ width: 1 @@ -225,6 +225,9 @@ Rectangle { height: parent.height model: generateArray(0,59) clip: true + preferredHighlightBegin: 0 + preferredHighlightEnd: 0 + highlightMoveDuration: 0 ScrollBar.vertical: FluScrollBar {} boundsBehavior:Flickable.StopAtBounds delegate: Loader{ @@ -233,9 +236,6 @@ Rectangle { property int position:index sourceComponent: list_delegate } - onCurrentIndexChanged: { - list_view_2.positionViewAtIndex(currentIndex, ListView.NoPosition) - } } Rectangle{ width: 1 @@ -250,6 +250,9 @@ Rectangle { model: ["上午","下午"] clip: true visible: isH + preferredHighlightBegin: 0 + preferredHighlightEnd: 0 + highlightMoveDuration: 0 ScrollBar.vertical: FluScrollBar {} Layout.alignment: Qt.AlignVCenter boundsBehavior:Flickable.StopAtBounds @@ -259,9 +262,6 @@ Rectangle { property int position:index sourceComponent: list_delegate } - onCurrentIndexChanged: { - list_view_3.positionViewAtIndex(currentIndex, ListView.NoPosition) - } } } @@ -358,10 +358,12 @@ Rectangle { } var pos = root.mapToItem(null, 0, 0) - if(window.height>pos.y+35+340){ - popup.y = 35 - }else{ - popup.y = window.height-(pos.y+340) + if(window.height>pos.y+root.height+popup.height){ + popup.y = root.height + } else if(pos.y>popup.height){ + popup.y = -popup.height + } else { + popup.y = window.height-(pos.y+popup.height) } popup.open() }