SettingCheckBox.qml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Uranium is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Layouts 1.1
  5. import QtQuick.Controls 1.1
  6. import QtQuick.Controls.Styles 1.1
  7. import UM 1.2 as UM
  8. SettingItem
  9. {
  10. id: base
  11. contents: MouseArea
  12. {
  13. id: control
  14. anchors.fill: parent
  15. property bool checked:
  16. {
  17. switch(propertyProvider.properties.value)
  18. {
  19. case "True":
  20. return true
  21. case "False":
  22. return false
  23. default:
  24. return propertyProvider.properties.value
  25. }
  26. }
  27. onClicked: propertyProvider.setPropertyValue("value", !checked)
  28. Rectangle
  29. {
  30. anchors
  31. {
  32. top: parent.top
  33. bottom: parent.bottom
  34. left: parent.left
  35. }
  36. width: height
  37. color:
  38. {
  39. if (!enabled)
  40. {
  41. return UM.Theme.getColor("setting_control_disabled")
  42. }
  43. if(control.containsMouse || control.activeFocus)
  44. {
  45. return UM.Theme.getColor("setting_control_highlight")
  46. }
  47. else
  48. {
  49. return UM.Theme.getColor("setting_control")
  50. }
  51. }
  52. border.width: UM.Theme.getSize("default_lining").width
  53. border.color: !enabled ? UM.Theme.getColor("setting_control_disabled_border") : control.containsMouse ? UM.Theme.getColor("setting_control_border_highlight") : UM.Theme.getColor("setting_control_border")
  54. UM.RecolorImage {
  55. anchors.verticalCenter: parent.verticalCenter
  56. anchors.horizontalCenter: parent.horizontalCenter
  57. width: parent.width/2.5
  58. height: parent.height/2.5
  59. sourceSize.width: width
  60. sourceSize.height: width
  61. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text");
  62. source: UM.Theme.getIcon("check")
  63. opacity: control.checked ? 1 : 0
  64. Behavior on opacity { NumberAnimation { duration: 100; } }
  65. }
  66. }
  67. }
  68. }