DwSwitch.qml 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import "." as Components
  4. // Toggle styled to the token system: ember when on, quiet when off.
  5. Switch {
  6. id: control
  7. implicitWidth: 56
  8. implicitHeight: 32
  9. indicator: Rectangle {
  10. anchors.verticalCenter: parent.verticalCenter
  11. width: 56
  12. height: 32
  13. radius: 16
  14. color: control.checked ? Components.ThemeManager.accent
  15. : Components.ThemeManager.pressedColor
  16. border.width: 1
  17. border.color: control.checked ? Components.ThemeManager.accentPressed
  18. : Components.ThemeManager.borderColor
  19. Behavior on color {
  20. ColorAnimation { duration: 150 }
  21. }
  22. Rectangle {
  23. x: control.checked ? parent.width - width - 3 : 3
  24. anchors.verticalCenter: parent.verticalCenter
  25. width: 26
  26. height: 26
  27. radius: 13
  28. color: control.checked ? Components.ThemeManager.onAccent : Components.ThemeManager.textSecondary
  29. Behavior on x {
  30. NumberAnimation { duration: 150; easing.type: Easing.OutQuad }
  31. }
  32. }
  33. }
  34. }