FluDropDownButton.qml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Controls.Basic
  4. import QtQuick.Window
  5. import FluentUI
  6. Button {
  7. property bool disabled: false
  8. property color normalColor: FluTheme.dark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(254/255,254/255,254/255,1)
  9. property color hoverColor: FluTheme.dark ? Qt.rgba(68/255,68/255,68/255,1) : Qt.rgba(251/255,251/255,251/255,1)
  10. property color disableColor: FluTheme.dark ? Qt.rgba(59/255,59/255,59/255,1) : Qt.rgba(252/255,252/255,252/255,1)
  11. property var window : Window.window
  12. property alias items: menu.content
  13. id: control
  14. topPadding:5
  15. bottomPadding:5
  16. leftPadding:15
  17. rightPadding:35
  18. enabled: !disabled
  19. focusPolicy:Qt.TabFocus
  20. Keys.onSpacePressed: control.visualFocus&&clicked()
  21. background: Rectangle{
  22. border.color: FluTheme.dark ? "#505050" : "#DFDFDF"
  23. border.width: 1
  24. radius: 4
  25. FluFocusRectangle{
  26. visible: control.visualFocus
  27. radius:8
  28. }
  29. color:{
  30. if(disabled){
  31. return disableColor
  32. }
  33. return hovered ? hoverColor :normalColor
  34. }
  35. FluIcon{
  36. iconSource:FluentIcons.ChevronDown
  37. iconSize: 15
  38. anchors{
  39. right: parent.right
  40. rightMargin: 10
  41. verticalCenter: parent.verticalCenter
  42. }
  43. iconColor:title.color
  44. }
  45. }
  46. contentItem: FluText {
  47. id:title
  48. text: control.text
  49. horizontalAlignment: Text.AlignHCenter
  50. verticalAlignment: Text.AlignVCenter
  51. color: {
  52. if(FluTheme.dark){
  53. if(disabled){
  54. return Qt.rgba(131/255,131/255,131/255,1)
  55. }
  56. if(pressed){
  57. return Qt.rgba(162/255,162/255,162/255,1)
  58. }
  59. return Qt.rgba(1,1,1,1)
  60. }else{
  61. if(disabled){
  62. return Qt.rgba(160/255,160/255,160/255,1)
  63. }
  64. if(pressed){
  65. return Qt.rgba(96/255,96/255,96/255,1)
  66. }
  67. return Qt.rgba(0,0,0,1)
  68. }
  69. }
  70. }
  71. onClicked: {
  72. var pos = control.mapToItem(null, 0, 0)
  73. var containerHeight = menu.getContainerHeight()
  74. if(window.height>pos.y+control.height+containerHeight){
  75. menu.y = control.height
  76. }else if(pos.y>containerHeight){
  77. menu.y = -containerHeight
  78. }else{
  79. menu.y = window.height-(pos.y+containerHeight)
  80. }
  81. menu.open()
  82. }
  83. FluMenu{
  84. id:menu
  85. width: control.width
  86. }
  87. }