FluScrollBar.qml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import QtQuick
  2. import QtQuick.Controls
  3. import FluentUI
  4. ScrollBar {
  5. property color handleNormalColor: Qt.rgba(134/255,134/255,134/255,1)
  6. property color handleHoverColor: Qt.lighter(handleNormalColor)
  7. property color handlePressColor: Qt.darker(handleNormalColor)
  8. property bool expand: false
  9. id: control
  10. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  11. implicitContentWidth + leftPadding + rightPadding)
  12. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  13. implicitContentHeight + topPadding + bottomPadding)
  14. visible: control.policy !== ScrollBar.AlwaysOff
  15. minimumSize: 0.3
  16. topPadding:{
  17. if(vertical){
  18. if(expand)
  19. return 15
  20. return 2
  21. }else{
  22. if(expand){
  23. return 2
  24. }
  25. return 4
  26. }
  27. }
  28. bottomPadding:{
  29. if(vertical){
  30. if(expand)
  31. return 15
  32. return 2
  33. }else{
  34. if(expand){
  35. return 2
  36. }
  37. return 4
  38. }
  39. }
  40. leftPadding:{
  41. if(vertical){
  42. if(expand){
  43. return 2
  44. }
  45. return 4
  46. }else{
  47. if(expand)
  48. return 15
  49. return 2
  50. }
  51. }
  52. rightPadding:{
  53. if(vertical){
  54. if(expand){
  55. return 2
  56. }
  57. return 4
  58. }else{
  59. if(expand)
  60. return 15
  61. return 2
  62. }
  63. }
  64. Behavior on topPadding {
  65. NumberAnimation{
  66. duration: 150
  67. }
  68. }
  69. Behavior on bottomPadding {
  70. NumberAnimation{
  71. duration: 150
  72. }
  73. }
  74. Behavior on leftPadding {
  75. NumberAnimation{
  76. duration: 150
  77. }
  78. }
  79. Behavior on rightPadding {
  80. NumberAnimation{
  81. duration: 150
  82. }
  83. }
  84. contentItem: Rectangle {
  85. id:item_react
  86. implicitWidth: expand ? 8 : 2
  87. implicitHeight: expand ? 8 : 2
  88. radius: width / 2
  89. color: control.pressed?handlePressColor:control.hovered?handleHoverColor:handleNormalColor
  90. opacity:(control.policy === ScrollBar.AlwaysOn || control.size < 1.0)?1.0:0.0
  91. }
  92. background: Rectangle{
  93. radius: 5
  94. color: {
  95. if(expand && item_react.opacity){
  96. if(FluTheme.dark){
  97. return Qt.rgba(0,0,0,1)
  98. }
  99. return Qt.rgba(1,1,1,1)
  100. }
  101. return Qt.rgba(0,0,0,0)
  102. }
  103. MouseArea{
  104. id:mouse_item
  105. hoverEnabled: true
  106. anchors.fill: parent
  107. onEntered: {
  108. timer.restart()
  109. }
  110. onExited: {
  111. timer.restart()
  112. }
  113. }
  114. }
  115. Timer{
  116. id:timer
  117. interval: 800
  118. onTriggered: {
  119. expand = mouse_item.containsMouse || btn_top.hovered || btn_bottom.hovered || btn_left.hovered || btn_right.hovered
  120. }
  121. }
  122. Behavior on implicitWidth {
  123. NumberAnimation{
  124. duration: 150
  125. }
  126. }
  127. FluIconButton{
  128. id:btn_top
  129. iconSource: FluentIcons.CaretSolidUp
  130. anchors.horizontalCenter: parent.horizontalCenter
  131. width:10
  132. height:10
  133. z:100
  134. iconColor: hovered ? FluColors.Black : FluColors.Grey120
  135. iconSize: 8
  136. anchors.top: parent.top
  137. anchors.topMargin: 4
  138. visible:vertical && expand && item_react.opacity
  139. onClicked:{
  140. decrease()
  141. }
  142. }
  143. FluIconButton{
  144. id:btn_bottom
  145. iconSource: FluentIcons.CaretSolidDown
  146. visible:vertical && expand && item_react.opacity
  147. width:10
  148. height:10
  149. iconSize: 8
  150. iconColor: hovered ? FluColors.Black : FluColors.Grey120
  151. anchors.horizontalCenter: parent.horizontalCenter
  152. anchors.bottom: parent.bottom
  153. anchors.bottomMargin: 4
  154. onClicked:{
  155. increase()
  156. }
  157. }
  158. FluIconButton{
  159. id:btn_left
  160. iconSource: FluentIcons.CaretSolidLeft
  161. visible:!vertical && expand && item_react.opacity
  162. width:10
  163. height:10
  164. iconSize: 8
  165. iconColor: hovered ? FluColors.Black : FluColors.Grey120
  166. anchors.leftMargin: 4
  167. anchors.verticalCenter: parent.verticalCenter
  168. anchors.left: parent.left
  169. onClicked:{
  170. decrease()
  171. }
  172. }
  173. FluIconButton{
  174. id:btn_right
  175. iconSource: FluentIcons.CaretSolidRight
  176. visible:!vertical && expand && item_react.opacity
  177. width:10
  178. height:10
  179. iconSize: 8
  180. iconColor: hovered ? FluColors.Black : FluColors.Grey120
  181. anchors.rightMargin: 4
  182. anchors.verticalCenter: parent.verticalCenter
  183. anchors.right: parent.right
  184. onClicked:{
  185. increase()
  186. }
  187. }
  188. }