RadioButton.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. //
  8. // Cura-style RadioButton.
  9. //
  10. RadioButton
  11. {
  12. id: control
  13. font: UM.Theme.getFont("default")
  14. states: [
  15. State {
  16. name: "selected-hover"
  17. when: control.enabled && control.checked && control.hovered
  18. PropertyChanges
  19. {
  20. target: indicator_background
  21. color: UM.Theme.getColor("radio_selected")
  22. border.color: UM.Theme.getColor("radio_border_hover")
  23. }
  24. },
  25. State {
  26. name: "selected"
  27. when: control.enabled && control.checked
  28. PropertyChanges
  29. {
  30. target: indicator_background
  31. color: UM.Theme.getColor("radio_selected")
  32. }
  33. },
  34. State {
  35. name: "hovered"
  36. when: control.enabled && control.hovered
  37. PropertyChanges
  38. {
  39. target: indicator_background
  40. border.color: UM.Theme.getColor("radio_border_hover")
  41. }
  42. },
  43. State {
  44. name: "selected_disabled"
  45. when: !control.enabled && control.checked
  46. PropertyChanges
  47. {
  48. target: indicator_background
  49. color: UM.Theme.getColor("radio_selected_disabled")
  50. border.color: UM.Theme.getColor("radio_border_disabled")
  51. }
  52. },
  53. State {
  54. name: "disabled"
  55. when: !control.enabled
  56. PropertyChanges
  57. {
  58. target: indicator_background
  59. color: UM.Theme.getColor("radio_disabled")
  60. border.color: UM.Theme.getColor("radio_border_disabled")
  61. }
  62. }
  63. ]
  64. background: Item
  65. {
  66. anchors.fill: parent
  67. }
  68. indicator: Rectangle
  69. {
  70. id: indicator_background
  71. implicitWidth: UM.Theme.getSize("radio_button").width
  72. implicitHeight: UM.Theme.getSize("radio_button").height
  73. anchors.verticalCenter: parent.verticalCenter
  74. anchors.alignWhenCentered: false
  75. radius: width / 2
  76. color: UM.Theme.getColor("radio")
  77. border.width: UM.Theme.getSize("default_lining").width
  78. border.color: UM.Theme.getColor("radio_border")
  79. Rectangle
  80. {
  81. id: indicator_dot
  82. width: (parent.width / 2) | 0
  83. height: width
  84. anchors.centerIn: parent
  85. radius: width / 2
  86. color: control.enabled ? UM.Theme.getColor("radio_dot") : UM.Theme.getColor("radio_dot_disabled")
  87. visible: control.checked
  88. }
  89. }
  90. contentItem: UM.Label
  91. {
  92. leftPadding: control.indicator.width + control.spacing
  93. text: control.text
  94. font: control.font
  95. color: control.enabled ? UM.Theme.getColor("radio_text"): UM.Theme.getColor("radio_text_disabled")
  96. }
  97. }