RangeSlider.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright (C) 2023 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. pragma ComponentBehavior: Bound
  5. import QtQuick
  6. import QtQuick.Templates as T
  7. T.RangeSlider {
  8. id: control
  9. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  10. Math.max(first.implicitHandleWidth, second.implicitHandleWidth) + leftPadding + rightPadding)
  11. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  12. Math.max(first.implicitHandleHeight, second.implicitHandleHeight) + topPadding + bottomPadding)
  13. readonly property bool __notCustomizable: true
  14. readonly property Item __focusFrameTarget: control
  15. component SliderHandle: Rectangle {
  16. implicitWidth: control.horizontal ? 11 : 21
  17. implicitHeight: control.horizontal ? 21 : 11
  18. color: control.palette.highlight
  19. required property bool pressed
  20. }
  21. first.handle: SliderHandle {
  22. x: control.leftPadding + Math.round(control.horizontal
  23. ? control.first.visualPosition * (control.availableWidth - width)
  24. : (control.availableWidth - width) / 2)
  25. y: control.topPadding + Math.round(control.horizontal
  26. ? (control.availableHeight - height) / 2
  27. : control.first.visualPosition * (control.availableHeight - height))
  28. palette: control.palette
  29. pressed: control.first.pressed
  30. // We are the ones that get focus, but we want the control to
  31. // be used for the visual focus frame.
  32. readonly property Item __focusFrameControl: control
  33. readonly property bool __ignoreNotCustomizable: true
  34. }
  35. second.handle: SliderHandle {
  36. x: control.leftPadding + Math.round(control.horizontal
  37. ? control.second.visualPosition * (control.availableWidth - width)
  38. : (control.availableWidth - width) / 2)
  39. y: control.topPadding + Math.round(control.horizontal
  40. ? (control.availableHeight - height) / 2
  41. : control.second.visualPosition * (control.availableHeight - height))
  42. palette: control.palette
  43. pressed: control.second.pressed
  44. readonly property Item __focusFrameControl: control
  45. readonly property bool __ignoreNotCustomizable: true
  46. }
  47. background: Item {
  48. implicitWidth: control.horizontal ? 90 : 21
  49. implicitHeight: control.horizontal ? 21 : 90
  50. readonly property real __focusFrameRadius: 1
  51. readonly property bool __ignoreNotCustomizable: true
  52. readonly property int barThickness: 4
  53. // Groove background.
  54. Rectangle {
  55. x: control.leftPadding + (control.horizontal ? 0 : (control.availableWidth - width) / 2)
  56. y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : 0)
  57. width: control.horizontal ? control.availableWidth : parent.barThickness
  58. height: control.horizontal ? parent.barThickness : control.availableHeight
  59. color: control.palette.window
  60. Rectangle {
  61. width: parent.width
  62. height: parent.height
  63. radius: parent.radius
  64. // No border in dark mode, instead we fill.
  65. color: Application.styleHints.colorScheme === Qt.Light
  66. ? "transparent" : Qt.lighter(control.palette.window, 1.6)
  67. border.color: Application.styleHints.colorScheme === Qt.Light
  68. ? Qt.darker(control.palette.window, 1.1)
  69. : "transparent"
  70. }
  71. }
  72. // Progress bar.
  73. Rectangle {
  74. x: control.leftPadding + (control.horizontal
  75. ? control.first.position * control.availableWidth
  76. : (control.availableWidth - width) / 2)
  77. y: control.topPadding + (control.horizontal
  78. ? (control.availableHeight - height) / 2
  79. : control.second.visualPosition * control.availableHeight)
  80. width: control.horizontal
  81. ? control.second.position * control.availableWidth - control.first.position * control.availableWidth
  82. : parent.barThickness
  83. height: control.horizontal
  84. ? parent.barThickness
  85. : control.second.position * control.availableHeight - control.first.position * control.availableHeight
  86. color: Qt.rgba(control.palette.highlight.r, control.palette.highlight.g, control.palette.highlight.b, 0.3)
  87. }
  88. }
  89. }