Switch.qml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.Material
  6. import QtQuick.Controls.Material.impl
  7. import QtQuick.Templates as T
  8. T.Switch {
  9. id: control
  10. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  11. implicitContentWidth + leftPadding + rightPadding)
  12. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  13. implicitContentHeight + topPadding + bottomPadding,
  14. implicitIndicatorHeight + topPadding + bottomPadding)
  15. padding: 8
  16. spacing: 8
  17. icon.width: 16
  18. icon.height: 16
  19. icon.color: checked
  20. ? (Material.theme === Material.Light
  21. ? enabled ? Qt.darker(Material.switchCheckedTrackColor, 1.8) : Material.switchDisabledCheckedIconColor
  22. : enabled ? Material.primaryTextColor : Material.switchDisabledCheckedIconColor)
  23. : enabled ? Material.switchUncheckedTrackColor : Material.switchDisabledUncheckedIconColor
  24. indicator: SwitchIndicator {
  25. x: control.text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2
  26. y: control.topPadding + (control.availableHeight - height) / 2
  27. control: control
  28. Ripple {
  29. x: parent.handle.x + parent.handle.width / 2 - width / 2
  30. y: parent.handle.y + parent.handle.height / 2 - height / 2
  31. width: 28
  32. height: 28
  33. pressed: control.pressed
  34. active: enabled && (control.down || control.visualFocus || control.hovered)
  35. color: control.checked ? control.Material.highlightedRippleColor : control.Material.rippleColor
  36. }
  37. }
  38. contentItem: Text {
  39. leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0
  40. rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0
  41. text: control.text
  42. font: control.font
  43. color: control.enabled ? control.Material.foreground : control.Material.hintTextColor
  44. elide: Text.ElideRight
  45. verticalAlignment: Text.AlignVCenter
  46. }
  47. }