SettingCheckBox.qml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Layouts 1.2
  5. import QtQuick.Controls 2.0
  6. import UM 1.2 as UM
  7. SettingItem
  8. {
  9. id: base
  10. property var focusItem: control
  11. contents: MouseArea
  12. {
  13. id: control
  14. anchors
  15. {
  16. top: parent.top
  17. bottom: parent.bottom
  18. left: parent.left
  19. }
  20. width: UM.Theme.getSize("checkbox").width
  21. hoverEnabled: true
  22. property bool checked:
  23. {
  24. // FIXME this needs to go away once 'resolve' is combined with 'value' in our data model.
  25. // Stacklevels
  26. // 0: user -> unsaved change
  27. // 1: quality changes -> saved change
  28. // 2: quality
  29. // 3: material -> user changed material in materials page
  30. // 4: variant
  31. // 5: machine
  32. var value
  33. if ((base.resolve !== undefined && base.resolve != "None") && (stackLevel != 0) && (stackLevel != 1))
  34. {
  35. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  36. // we have to choose between the resolved value (default) and the global value
  37. // (if user has explicitly set this).
  38. value = base.resolve
  39. }
  40. else
  41. {
  42. value = propertyProvider.properties.value
  43. }
  44. switch(value)
  45. {
  46. case "True":
  47. return true
  48. case "False":
  49. return false
  50. default:
  51. return (value !== undefined) ? value : false
  52. }
  53. }
  54. Keys.onSpacePressed:
  55. {
  56. forceActiveFocus()
  57. propertyProvider.setPropertyValue("value", !checked)
  58. }
  59. onClicked:
  60. {
  61. forceActiveFocus()
  62. propertyProvider.setPropertyValue("value", !checked)
  63. }
  64. Keys.onTabPressed:
  65. {
  66. base.setActiveFocusToNextSetting(true)
  67. }
  68. Keys.onBacktabPressed:
  69. {
  70. base.setActiveFocusToNextSetting(false)
  71. }
  72. onActiveFocusChanged:
  73. {
  74. if (activeFocus)
  75. {
  76. base.focusReceived()
  77. }
  78. }
  79. Rectangle
  80. {
  81. anchors
  82. {
  83. verticalCenter: parent.verticalCenter
  84. left: parent.left
  85. }
  86. width: UM.Theme.getSize("checkbox").width
  87. height: width
  88. radius: UM.Theme.getSize("checkbox_radius").width
  89. border.width: UM.Theme.getSize("default_lining").width
  90. border.color:
  91. {
  92. if(!enabled)
  93. {
  94. return UM.Theme.getColor("checkbox_border_disabled")
  95. }
  96. switch (propertyProvider.properties.validationState)
  97. {
  98. case "ValidatorState.Invalid":
  99. case "ValidatorState.Exception":
  100. case "ValidatorState.MinimumError":
  101. case "ValidatorState.MaximumError":
  102. return UM.Theme.getColor("setting_validation_error");
  103. case "ValidatorState.MinimumWarning":
  104. case "ValidatorState.MaximumWarning":
  105. return UM.Theme.getColor("setting_validation_warning");
  106. }
  107. // Validation is OK.
  108. if (control.containsMouse || control.activeFocus || hovered)
  109. {
  110. return UM.Theme.getColor("checkbox_border_hover")
  111. }
  112. return UM.Theme.getColor("checkbox_border")
  113. }
  114. color: {
  115. if (!enabled)
  116. {
  117. return UM.Theme.getColor("checkbox_disabled")
  118. }
  119. switch (propertyProvider.properties.validationState)
  120. {
  121. case "ValidatorState.Invalid":
  122. case "ValidatorState.Exception":
  123. case "ValidatorState.MinimumError":
  124. case "ValidatorState.MaximumError":
  125. return UM.Theme.getColor("setting_validation_error_background")
  126. case "ValidatorState.MinimumWarning":
  127. case "ValidatorState.MaximumWarning":
  128. return UM.Theme.getColor("setting_validation_warning_background")
  129. }
  130. // Validation is OK.
  131. if (control.containsMouse || control.activeFocus)
  132. {
  133. return UM.Theme.getColor("checkbox_hover")
  134. }
  135. return UM.Theme.getColor("checkbox")
  136. }
  137. UM.ColorImage
  138. {
  139. anchors.verticalCenter: parent.verticalCenter
  140. anchors.horizontalCenter: parent.horizontalCenter
  141. height: UM.Theme.getSize("checkbox_mark").height
  142. width: UM.Theme.getSize("checkbox_mark").width
  143. color: !enabled ? UM.Theme.getColor("checkbox_mark_disabled") : UM.Theme.getColor("checkbox_mark");
  144. source: UM.Theme.getIcon("Check", "low")
  145. opacity: control.checked ? 1 : 0
  146. Behavior on opacity { NumberAnimation { duration: 100; } }
  147. }
  148. }
  149. }
  150. }