Slider.qml 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.Slider {
  9. id: control
  10. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  11. implicitHandleWidth + leftPadding + rightPadding)
  12. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  13. implicitHandleHeight + topPadding + bottomPadding)
  14. topPadding: background ? background.topPadding : 0
  15. leftPadding: background ? background.leftPadding : 0
  16. rightPadding: background ? background.rightPadding : 0
  17. bottomPadding: background ? background.bottomPadding : 0
  18. topInset: background ? -background.topInset || 0 : 0
  19. leftInset: background ? -background.leftInset || 0 : 0
  20. rightInset: background ? -background.rightInset || 0 : 0
  21. bottomInset: background ? -background.bottomInset || 0 : 0
  22. handle: Image {
  23. x: Math.round(control.leftPadding + (control.horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2))
  24. y: Math.round(control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height)))
  25. source: control.Imagine.url + "slider-handle"
  26. ImageSelector on source {
  27. states: [
  28. {"vertical": control.vertical},
  29. {"horizontal": control.horizontal},
  30. {"disabled": !control.enabled},
  31. {"pressed": control.pressed},
  32. {"focused": control.visualFocus},
  33. {"mirrored": control.mirrored},
  34. {"hovered": control.enabled && control.hovered}
  35. ]
  36. }
  37. }
  38. background: NinePatchImage {
  39. scale: control.horizontal && control.mirrored ? -1 : 1
  40. source: control.Imagine.url + "slider-background"
  41. NinePatchImageSelector on source {
  42. states: [
  43. {"vertical": control.vertical},
  44. {"horizontal": control.horizontal},
  45. {"disabled": !control.enabled},
  46. {"pressed": control.down},
  47. {"focused": control.visualFocus},
  48. {"mirrored": control.mirrored},
  49. {"hovered": control.enabled && control.hovered}
  50. ]
  51. }
  52. NinePatchImage {
  53. readonly property real handleWidth: control.handle ? control.handle.width : 0
  54. readonly property real handleHeight: control.handle ? control.handle.height : 0
  55. x: control.horizontal ? 0 : (parent.width - width) / 2
  56. y: control.horizontal
  57. ? (parent.height - height) / 2
  58. : handleHeight / 2 + control.visualPosition * (parent.height - handleHeight)
  59. width: control.horizontal
  60. ? handleWidth / 2 + control.position * (parent.width - handleWidth)
  61. : parent.width
  62. height: control.vertical
  63. ? handleHeight / 2 + control.position * (parent.height - handleHeight)
  64. : parent.height
  65. source: control.Imagine.url + "slider-progress"
  66. NinePatchImageSelector on source {
  67. states: [
  68. {"vertical": control.vertical},
  69. {"horizontal": control.horizontal},
  70. {"disabled": !control.enabled},
  71. {"pressed": control.down},
  72. {"focused": control.visualFocus},
  73. {"mirrored": control.mirrored},
  74. {"hovered": control.enabled && control.hovered}
  75. ]
  76. }
  77. }
  78. }
  79. }