SettingCheckBox.qml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. hoverEnabled: true
  16. property bool checked:
  17. {
  18. // FIXME this needs to go away once 'resolve' is combined with 'value' in our data model.
  19. // Stacklevels
  20. // 0: user -> unsaved change
  21. // 1: quality changes -> saved change
  22. // 2: quality
  23. // 3: material -> user changed material in materials page
  24. // 4: variant
  25. // 5: machine
  26. var value;
  27. if ((base.resolve != "None") && (stackLevel != 0) && (stackLevel != 1)) {
  28. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  29. // we have to choose between the resolved value (default) and the global value
  30. // (if user has explicitly set this).
  31. value = base.resolve;
  32. } else {
  33. value = propertyProvider.properties.value;
  34. }
  35. switch(value)
  36. {
  37. case "True":
  38. return true;
  39. case "False":
  40. return false;
  41. default:
  42. return value;
  43. }
  44. }
  45. onClicked:
  46. {
  47. forceActiveFocus();
  48. propertyProvider.setPropertyValue("value", !checked);
  49. }
  50. Rectangle
  51. {
  52. anchors
  53. {
  54. top: parent.top
  55. bottom: parent.bottom
  56. left: parent.left
  57. }
  58. width: height
  59. color:
  60. {
  61. if (!enabled)
  62. {
  63. return UM.Theme.getColor("setting_control_disabled")
  64. }
  65. if(control.containsMouse || control.activeFocus)
  66. {
  67. return UM.Theme.getColor("setting_control_highlight")
  68. }
  69. else
  70. {
  71. return UM.Theme.getColor("setting_control")
  72. }
  73. }
  74. border.width: UM.Theme.getSize("default_lining").width
  75. 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")
  76. UM.RecolorImage {
  77. anchors.verticalCenter: parent.verticalCenter
  78. anchors.horizontalCenter: parent.horizontalCenter
  79. width: parent.width/2.5
  80. height: parent.height/2.5
  81. sourceSize.width: width
  82. sourceSize.height: width
  83. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text");
  84. source: UM.Theme.getIcon("check")
  85. opacity: control.checked ? 1 : 0
  86. Behavior on opacity { NumberAnimation { duration: 100; } }
  87. }
  88. }
  89. }
  90. }