FluCalendarPicker.qml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. import QtQuick.Window
  5. import FluentUI
  6. Rectangle {
  7. property color dividerColor: FluTheme.dark ? Qt.rgba(77/255,77/255,77/255,1) : Qt.rgba(239/255,239/255,239/255,1)
  8. property color hoverColor: FluTheme.dark ? Qt.rgba(68/255,68/255,68/255,1) : Qt.rgba(251/255,251/255,251/255,1)
  9. property color normalColor: FluTheme.dark ? Qt.rgba(61/255,61/255,61/255,1) : Qt.rgba(254/255,254/255,254/255,1)
  10. property string text: "请选择日期"
  11. property var window : Window.window
  12. id:control
  13. color: {
  14. if(mouse_area.containsMouse){
  15. return hoverColor
  16. }
  17. return normalColor
  18. }
  19. height: 30
  20. width: 120
  21. radius: 4
  22. border.width: 1
  23. border.color: dividerColor
  24. MouseArea{
  25. id:mouse_area
  26. hoverEnabled: true
  27. anchors.fill: parent
  28. onClicked: {
  29. popup.showPopup()
  30. }
  31. }
  32. FluText{
  33. id:text_date
  34. anchors{
  35. left: parent.left
  36. right: parent.right
  37. rightMargin: 30
  38. top: parent.top
  39. bottom: parent.bottom
  40. }
  41. verticalAlignment: Text.AlignVCenter
  42. horizontalAlignment: Text.AlignHCenter
  43. text:control.text
  44. }
  45. FluIcon{
  46. iconSource: FluentIcons.Calendar
  47. iconSize: 14
  48. iconColor: text_date.color
  49. anchors{
  50. verticalCenter: parent.verticalCenter
  51. right: parent.right
  52. rightMargin: 12
  53. }
  54. }
  55. Menu{
  56. id:popup
  57. height: container.height
  58. width: container.width
  59. modal: true
  60. dim:false
  61. enter: Transition {
  62. reversible: true
  63. NumberAnimation {
  64. property: "opacity"
  65. from:0
  66. to:1
  67. duration: 83
  68. }
  69. }
  70. exit:Transition {
  71. NumberAnimation {
  72. property: "opacity"
  73. from:1
  74. to:0
  75. duration: 83
  76. }
  77. }
  78. contentItem: Item{
  79. clip: true
  80. FluCalendarView{
  81. id:container
  82. onDateClicked:
  83. (date)=>{
  84. popup.close()
  85. var year = date.getFullYear()
  86. var month = date.getMonth()
  87. var day = date.getDate()
  88. text_date.text = year+"-"+(month+1)+"-"+day
  89. }
  90. }
  91. }
  92. background: Item{
  93. FluShadow{
  94. radius: 5
  95. }
  96. }
  97. function showPopup() {
  98. var pos = control.mapToItem(null, 0, 0)
  99. if(window.height>pos.y+control.height+container.height){
  100. popup.y = control.height
  101. } else if(pos.y>container.height){
  102. popup.y = -container.height
  103. } else {
  104. popup.y = window.height-(pos.y+container.height)
  105. }
  106. popup.x = -(popup.width-control.width)/2
  107. popup.open()
  108. }
  109. }
  110. }