ScrollBar.qml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2020 The Qt Company Ltd.
  4. ** Contact: http://www.qt.io/licensing/
  5. **
  6. ** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL3$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see http://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at http://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPLv3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or later as published by the Free
  28. ** Software Foundation and appearing in the file LICENSE.GPL included in
  29. ** the packaging of this file. Please review the following information to
  30. ** ensure the GNU General Public License version 2.0 requirements will be
  31. ** met: http://www.gnu.org/licenses/gpl-2.0.html.
  32. **
  33. ** $QT_END_LICENSE$
  34. **
  35. ****************************************************************************/
  36. import QtQuick
  37. import QtQuick.NativeStyle as NativeStyle
  38. NativeStyle.DefaultScrollBar {
  39. id: controlRoot
  40. topPadding: orientation === Qt.Vertical ? controlRoot.__decreaseVisual.indicator.height : 0
  41. bottomPadding: orientation === Qt.Vertical ? controlRoot.__increaseVisual.indicator.height : 0
  42. leftPadding: orientation === Qt.Horizontal ? controlRoot.__decreaseVisual.indicator.width : 0
  43. rightPadding: orientation === Qt.Horizontal ? controlRoot.__increaseVisual.indicator.width : 0
  44. contentItem: NativeStyle.ScrollBar {
  45. control: controlRoot
  46. subControl: NativeStyle.ScrollBar.Handle
  47. }
  48. NativeStyle.ScrollBar {
  49. // Fade a hovered-looking version of the handle
  50. // on top of the default handle when hovering it
  51. x: contentItem.x
  52. y: contentItem.y
  53. z: 1
  54. width: contentItem.width
  55. height: contentItem.height
  56. control: controlRoot
  57. subControl: NativeStyle.ScrollBar.Handle
  58. overrideState: NativeStyle.StyleItem.AlwaysHovered
  59. opacity: controlRoot.hovered || control.pressed ? 1 : 0
  60. visible: contentItem instanceof NativeStyle.StyleItem
  61. Behavior on opacity { NumberAnimation { duration: contentItem.transitionDuration } }
  62. }
  63. // The groove background should have window color
  64. Rectangle {
  65. x: background.x
  66. y: background.y
  67. z: -1
  68. width: background.width
  69. height: background.height
  70. color: controlRoot.palette.window
  71. }
  72. background: NativeStyle.ScrollBar {
  73. control: controlRoot
  74. subControl: NativeStyle.ScrollBar.Groove
  75. overrideState: NativeStyle.ScrollBar.NeverHovered
  76. }
  77. __decreaseVisual.indicator: NativeStyle.ScrollBar {
  78. control: controlRoot
  79. subControl: NativeStyle.ScrollBar.SubLine
  80. overrideState: NativeStyle.ScrollBar.AlwaysHovered
  81. opacity: controlRoot.__decreaseVisual.hovered ? 1 : 0
  82. visible: contentItem instanceof NativeStyle.StyleItem
  83. Behavior on opacity { NumberAnimation { duration: contentItem.transitionDuration } }
  84. useNinePatchImage: false
  85. }
  86. NativeStyle.ScrollBar {
  87. control: controlRoot
  88. subControl: NativeStyle.ScrollBar.SubLine
  89. overrideState: NativeStyle.ScrollBar.AlwaysSunken
  90. opacity: controlRoot.__decreaseVisual.pressed ? 1 : 0
  91. visible: contentItem instanceof NativeStyle.StyleItem
  92. useNinePatchImage: false
  93. z: 1
  94. }
  95. __increaseVisual.indicator: NativeStyle.ScrollBar {
  96. control: controlRoot
  97. subControl: NativeStyle.ScrollBar.AddLine
  98. x: orientation === Qt.Horizontal ? controlRoot.width - width : 0
  99. y: orientation === Qt.Vertical ? controlRoot.height - height : 0
  100. overrideState: NativeStyle.ScrollBar.AlwaysHovered
  101. opacity: controlRoot.__increaseVisual.hovered ? 1 : 0
  102. visible: contentItem instanceof NativeStyle.StyleItem
  103. Behavior on opacity { NumberAnimation { duration: contentItem.transitionDuration } }
  104. useNinePatchImage: false
  105. }
  106. NativeStyle.ScrollBar {
  107. control: controlRoot
  108. subControl: NativeStyle.ScrollBar.AddLine
  109. x: __increaseVisual.indicator.x
  110. y: __increaseVisual.indicator.y
  111. z: 1
  112. overrideState: NativeStyle.ScrollBar.AlwaysSunken
  113. opacity: controlRoot.__increaseVisual.pressed ? 1 : 0
  114. visible: contentItem instanceof NativeStyle.StyleItem
  115. useNinePatchImage: false
  116. }
  117. }