RangeSlider.qml 4.9 KB

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