RadioButton.qml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) 2019 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: radioButton
  13. font: UM.Theme.getFont("default")
  14. states: [
  15. State {
  16. name: "checked"
  17. when: radioButton.checked
  18. PropertyChanges
  19. {
  20. target: indicator
  21. color: UM.Theme.getColor("accent_1")
  22. border.width: 0
  23. }
  24. },
  25. State
  26. {
  27. name: "disabled"
  28. when: !radioButton.enabled
  29. PropertyChanges { target: indicator; color: UM.Theme.getColor("background_1")}
  30. },
  31. State
  32. {
  33. name: "highlighted"
  34. when: radioButton.hovered || radioButton.activeFocus
  35. PropertyChanges { target: indicator; border.color: UM.Theme.getColor("accent_1")}
  36. }
  37. ]
  38. background: Item
  39. {
  40. anchors.fill: parent
  41. }
  42. indicator: Rectangle
  43. {
  44. implicitWidth: UM.Theme.getSize("radio_button").width
  45. implicitHeight: UM.Theme.getSize("radio_button").height
  46. anchors.verticalCenter: parent.verticalCenter
  47. anchors.alignWhenCentered: false
  48. radius: width / 2
  49. color: UM.Theme.getColor("background_2")
  50. border.width: UM.Theme.getSize("default_lining").width
  51. border.color: UM.Theme.getColor("text_disabled")
  52. Rectangle
  53. {
  54. width: (parent.width / 2) | 0
  55. height: width
  56. anchors.centerIn: parent
  57. radius: width / 2
  58. color: radioButton.enabled ? UM.Theme.getColor("background_2") : UM.Theme.getColor("background_1")
  59. visible: radioButton.checked
  60. }
  61. }
  62. contentItem: UM.Label
  63. {
  64. leftPadding: radioButton.indicator.width + radioButton.spacing
  65. text: radioButton.text
  66. font: radioButton.font
  67. }
  68. }