RangeSlider.qml 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.RangeSlider {
  8. id: control
  9. readonly property color handleBorderColor: {
  10. if (activeFocus)
  11. return palette.highlight
  12. else if (Qt.styleHints.accessibility.contrastPreference !== Qt.HighContrast)
  13. return enabled ? palette.mid : palette.midlight
  14. else
  15. return enabled ? palette.windowText : palette.mid
  16. }
  17. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  18. first.implicitHandleWidth + leftPadding + rightPadding,
  19. second.implicitHandleWidth + leftPadding + rightPadding)
  20. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  21. first.implicitHandleHeight + topPadding + bottomPadding,
  22. second.implicitHandleHeight + topPadding + bottomPadding)
  23. padding: 6
  24. first.handle: Rectangle {
  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. implicitWidth: 28
  28. implicitHeight: 28
  29. radius: width / 2
  30. border.width: activeFocus ? 2 : 1
  31. border.color: control.handleBorderColor
  32. color: control.first.pressed ? control.palette.light : control.palette.window
  33. }
  34. second.handle: Rectangle {
  35. x: control.leftPadding + (control.horizontal ? control.second.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2)
  36. y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.second.visualPosition * (control.availableHeight - height))
  37. implicitWidth: 28
  38. implicitHeight: 28
  39. radius: width / 2
  40. border.width: activeFocus ? 2 : 1
  41. border.color: control.handleBorderColor
  42. color: control.second.pressed ? control.palette.light : control.palette.window
  43. }
  44. background: Rectangle {
  45. x: control.leftPadding + (control.horizontal ? 0 : (control.availableWidth - width) / 2)
  46. y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : 0)
  47. implicitWidth: control.horizontal ? 200 : 6
  48. implicitHeight: control.horizontal ? 6 : 200
  49. width: control.horizontal ? control.availableWidth : implicitWidth
  50. height: control.horizontal ? implicitHeight : control.availableHeight
  51. radius: 3
  52. color: control.palette.midlight
  53. scale: control.horizontal && control.mirrored ? -1 : 1
  54. border.width: Qt.styleHints.accessibility.contrastPreference === Qt.HighContrast ? 1 : 0
  55. border.color: enabled ? control.palette.dark : control.palette.mid
  56. Rectangle {
  57. x: control.horizontal ? control.first.position * parent.width + 3 : 0
  58. y: control.horizontal ? 0 : control.second.visualPosition * parent.height + 3
  59. width: control.horizontal ? control.second.position * parent.width - control.first.position * parent.width - 6 : 6
  60. height: control.horizontal ? 6 : control.second.position * parent.height - control.first.position * parent.height - 6
  61. color: control.palette.dark
  62. }
  63. }
  64. }