ScrollBar.qml 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.Controls.impl
  6. import QtQuick.Templates as T
  7. T.ScrollBar {
  8. id: control
  9. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  10. implicitContentWidth + leftPadding + rightPadding)
  11. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  12. implicitContentHeight + topPadding + bottomPadding)
  13. padding: 2
  14. visible: control.policy !== T.ScrollBar.AlwaysOff
  15. minimumSize: orientation === Qt.Horizontal ? height / width : width / height
  16. contentItem: Rectangle {
  17. implicitWidth: control.interactive ? 6 : 2
  18. implicitHeight: control.interactive ? 6 : 2
  19. radius: width / 2
  20. color: {
  21. if (Qt.styleHints.accessibility.contrastPreference !== Qt.HighContrast)
  22. return pressed ? control.palette.dark : control.palette.mid
  23. else
  24. return Color.blend(control.palette.text, control.palette.mid, pressed ? 0.0 : 0.3)
  25. }
  26. opacity: 0.0
  27. states: State {
  28. name: "active"
  29. when: control.policy === T.ScrollBar.AlwaysOn || (control.active && control.size < 1.0)
  30. PropertyChanges { control.contentItem.opacity: 0.75 }
  31. }
  32. transitions: Transition {
  33. from: "active"
  34. SequentialAnimation {
  35. PauseAnimation { duration: 450 }
  36. NumberAnimation { target: control.contentItem; duration: 200; property: "opacity"; to: 0.0 }
  37. }
  38. }
  39. }
  40. background: Rectangle {
  41. visible: Qt.styleHints.accessibility.contrastPreference === Qt.HighContrast
  42. opacity: control.contentItem.opacity
  43. color: control.palette.mid
  44. }
  45. }