ScrollBar.qml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (C) 2017 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // Qt-Security score:significant reason:default
  4. import QtQuick
  5. import QtQuick.Templates as T
  6. import QtQuick.Controls.Imagine
  7. import QtQuick.Controls.Imagine.impl
  8. T.ScrollBar {
  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 !== T.ScrollBar.AlwaysOff
  15. minimumSize: orientation === Qt.Horizontal ? height / width : width / height
  16. topPadding: background ? background.topPadding : 0
  17. leftPadding: background ? background.leftPadding : 0
  18. rightPadding: background ? background.rightPadding : 0
  19. bottomPadding: background ? background.bottomPadding : 0
  20. topInset: background ? -background.topInset || 0 : 0
  21. leftInset: background ? -background.leftInset || 0 : 0
  22. rightInset: background ? -background.rightInset || 0 : 0
  23. bottomInset: background ? -background.bottomInset || 0 : 0
  24. contentItem: NinePatchImage {
  25. width: control.availableWidth
  26. height: control.availableHeight
  27. source: Imagine.url + "scrollbar-handle"
  28. NinePatchImageSelector on source {
  29. states: [
  30. {"vertical": control.vertical},
  31. {"horizontal": control.horizontal},
  32. {"disabled": !control.enabled},
  33. {"interactive": control.interactive},
  34. {"pressed": control.pressed},
  35. {"mirrored": control.mirrored},
  36. {"hovered": control.enabled && control.hovered}
  37. ]
  38. }
  39. opacity: 0.0
  40. }
  41. background: NinePatchImage {
  42. source: Imagine.url + "scrollbar-background"
  43. NinePatchImageSelector on source {
  44. states: [
  45. {"vertical": control.vertical},
  46. {"horizontal": control.horizontal},
  47. {"disabled": !control.enabled},
  48. {"interactive": control.interactive},
  49. {"pressed": control.pressed},
  50. {"mirrored": control.mirrored},
  51. {"hovered": control.enabled && control.hovered}
  52. ]
  53. }
  54. opacity: 0.0
  55. }
  56. states: [
  57. State {
  58. name: "active"
  59. when: control.policy === T.ScrollBar.AlwaysOn || (control.active && control.size < 1.0)
  60. }
  61. ]
  62. transitions: [
  63. Transition {
  64. to: "active"
  65. NumberAnimation { targets: [control.contentItem, control.background]; property: "opacity"; to: 1.0 }
  66. },
  67. Transition {
  68. from: "active"
  69. SequentialAnimation {
  70. PropertyAction{ targets: [control.contentItem, control.background]; property: "opacity"; value: 1.0 }
  71. PauseAnimation { duration: 3000 }
  72. NumberAnimation { targets: [control.contentItem, control.background]; property: "opacity"; to: 0.0 }
  73. }
  74. }
  75. ]
  76. }