FComboBox.qml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Controls.Basic
  4. import FluentUI
  5. import QtQuick.Templates as T
  6. ComboBox {
  7. id: control
  8. property bool disabled: false
  9. property color normalColor: FluTheme.dark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(254/255,254/255,254/255,1)
  10. property color hoverColor: FluTheme.dark ? Qt.rgba(68/255,68/255,68/255,1) : Qt.rgba(251/255,251/255,251/255,1)
  11. property color disableColor: FluTheme.dark ? Qt.rgba(59/255,59/255,59/255,1) : Qt.rgba(252/255,252/255,252/255,1)
  12. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  13. implicitContentWidth + leftPadding + rightPadding)
  14. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  15. implicitContentHeight + topPadding + bottomPadding,
  16. implicitIndicatorHeight + topPadding + bottomPadding)
  17. leftPadding: padding + (!control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
  18. rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
  19. enabled: !disabled
  20. delegate: FItemDelegate{
  21. width: ListView.view.width
  22. text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
  23. palette.text: control.palette.text
  24. palette.highlightedText: control.palette.highlightedText
  25. font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal
  26. highlighted: control.highlightedIndex === index
  27. hoverEnabled: control.hoverEnabled
  28. }
  29. indicator: FluIcon {
  30. x: control.mirrored ? control.padding : control.width - width - control.padding
  31. y: control.topPadding + (control.availableHeight - height) / 2
  32. width: 28
  33. iconSource:FluentIcons.ChevronDown
  34. iconSize: 15
  35. opacity: enabled ? 1 : 0.3
  36. }
  37. contentItem: T.TextField {
  38. property bool disabled: !control.editable
  39. leftPadding: !control.mirrored ? 12 : control.editable && activeFocus ? 3 : 1
  40. rightPadding: control.mirrored ? 12 : control.editable && activeFocus ? 3 : 1
  41. topPadding: 6 - control.padding
  42. bottomPadding: 6 - control.padding
  43. renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering
  44. selectionColor: FluTheme.primaryColor.lightest
  45. text: control.editable ? control.editText : control.displayText
  46. enabled: control.editable
  47. autoScroll: control.editable
  48. font:FluTextStyle.Body
  49. readOnly: control.down
  50. color: FluTheme.dark ? Qt.rgba(255/255,255/255,255/255,1) : Qt.rgba(27/255,27/255,27/255,1)
  51. inputMethodHints: control.inputMethodHints
  52. validator: control.validator
  53. selectByMouse: true
  54. verticalAlignment: Text.AlignVCenter
  55. leftInset:1
  56. topInset:1
  57. bottomInset:1
  58. rightInset:1
  59. background: FluTextBoxBackground{
  60. border.width: 0
  61. inputItem: contentItem
  62. }
  63. }
  64. background: Rectangle {
  65. implicitWidth: 140
  66. implicitHeight: 28
  67. border.color: FluTheme.dark ? "#505050" : "#DFDFDF"
  68. border.width: 1
  69. visible: !control.flat || control.down
  70. radius: 4
  71. FluFocusRectangle{
  72. visible: control.visualFocus
  73. radius:8
  74. }
  75. color:{
  76. if(disabled){
  77. return disableColor
  78. }
  79. return hovered ? hoverColor :normalColor
  80. }
  81. }
  82. popup: T.Popup {
  83. y: control.height
  84. width: control.width
  85. height: Math.min(contentItem.implicitHeight, control.Window.height - topMargin - bottomMargin)
  86. topMargin: 6
  87. bottomMargin: 6
  88. contentItem: ListView {
  89. clip: true
  90. implicitHeight: contentHeight
  91. model: control.delegateModel
  92. currentIndex: control.highlightedIndex
  93. highlightMoveDuration: 0
  94. T.ScrollIndicator.vertical: ScrollIndicator { }
  95. }
  96. enter: Transition {
  97. NumberAnimation {
  98. property: "opacity"
  99. from:0
  100. to:1
  101. duration: 83
  102. }
  103. }
  104. exit:Transition {
  105. NumberAnimation {
  106. property: "opacity"
  107. from:1
  108. to:0
  109. duration: 83
  110. }
  111. }
  112. background:Rectangle{
  113. color:FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(249/255,249/255,249/255,1)
  114. border.color: FluTheme.dark ? Window.active ? Qt.rgba(55/255,55/255,55/255,1):Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,229/255,234/255,1)
  115. border.width: 1
  116. radius: 5
  117. FluShadow{
  118. radius: 5
  119. }
  120. }
  121. }
  122. // show your selectd value
  123. function show(name){
  124. currentIndex = find(name)
  125. }
  126. }