FluentUI/src/controls/FluCalendarPicker.qml

112 lines
2.9 KiB
QML
Raw Normal View History

2023-03-30 21:52:55 +08:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Window
import FluentUI
2023-03-22 11:54:19 +08:00
Rectangle {
2023-03-28 21:37:10 +08:00
property color dividerColor: FluTheme.dark ? Qt.rgba(77/255,77/255,77/255,1) : Qt.rgba(239/255,239/255,239/255,1)
property color hoverColor: FluTheme.dark ? Qt.rgba(68/255,68/255,68/255,1) : Qt.rgba(251/255,251/255,251/255,1)
property color normalColor: FluTheme.dark ? Qt.rgba(61/255,61/255,61/255,1) : Qt.rgba(254/255,254/255,254/255,1)
2023-04-01 21:01:46 +08:00
property string text: "请选择日期"
2023-03-22 11:54:19 +08:00
property var window : Window.window
2023-04-01 21:01:46 +08:00
id:control
2023-03-22 11:54:19 +08:00
color: {
if(mouse_area.containsMouse){
return hoverColor
}
return normalColor
}
height: 30
width: 120
radius: 4
border.width: 1
border.color: dividerColor
MouseArea{
id:mouse_area
hoverEnabled: true
anchors.fill: parent
onClicked: {
popup.showPopup()
}
}
FluText{
id:text_date
anchors{
left: parent.left
right: parent.right
rightMargin: 30
top: parent.top
bottom: parent.bottom
}
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
2023-04-01 21:01:46 +08:00
text:control.text
2023-03-22 11:54:19 +08:00
}
FluIcon{
iconSource: FluentIcons.Calendar
iconSize: 14
2023-03-30 11:43:35 +08:00
iconColor: text_date.color
2023-03-22 11:54:19 +08:00
anchors{
verticalCenter: parent.verticalCenter
right: parent.right
rightMargin: 12
}
}
2023-03-30 21:52:55 +08:00
Menu{
2023-03-22 11:54:19 +08:00
id:popup
height: container.height
width: container.width
2023-03-28 17:53:46 +08:00
modal: true
dim:false
2023-03-28 18:14:14 +08:00
enter: Transition {
NumberAnimation {
property: "y"
from:0
to:popup.y
duration: 150
}
2023-03-29 15:43:23 +08:00
NumberAnimation {
property: "opacity"
from:0
to:1
duration: 150
}
2023-03-28 18:14:14 +08:00
}
2023-03-30 21:52:55 +08:00
contentItem: Item{
anchors.fill: parent
FluCalendarView{
id:container
onDateClicked:
(date)=>{
popup.close()
var year = date.getFullYear()
var month = date.getMonth()
var day = date.getDate()
text_date.text = year+"-"+(month+1)+"-"+day
}
}
2023-03-22 11:54:19 +08:00
}
2023-03-30 21:52:55 +08:00
background: Item{}
2023-03-22 11:54:19 +08:00
function showPopup() {
2023-04-01 21:01:46 +08:00
var pos = control.mapToItem(null, 0, 0)
if(window.height>pos.y+control.height+popup.height){
popup.y = control.height
2023-03-22 11:54:19 +08:00
} else if(pos.y>popup.height){
popup.y = -popup.height
} else {
popup.y = window.height-(pos.y+popup.height)
}
2023-04-01 21:01:46 +08:00
popup.x = -(popup.width-control.width)/2
2023-03-22 11:54:19 +08:00
popup.open()
}
}
}