SettingCheckBox.qml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.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 !== undefined && base.resolve != "None") && (stackLevel != 0) && (stackLevel != 1))
  28. {
  29. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  30. // we have to choose between the resolved value (default) and the global value
  31. // (if user has explicitly set this).
  32. value = base.resolve
  33. }
  34. else
  35. {
  36. value = propertyProvider.properties.value
  37. }
  38. switch(value)
  39. {
  40. case "True":
  41. return true
  42. case "False":
  43. return false
  44. default:
  45. return (value !== undefined) ? value : false
  46. }
  47. }
  48. Keys.onSpacePressed:
  49. {
  50. forceActiveFocus()
  51. propertyProvider.setPropertyValue("value", !checked)
  52. }
  53. onClicked:
  54. {
  55. forceActiveFocus()
  56. propertyProvider.setPropertyValue("value", !checked)
  57. }
  58. Keys.onTabPressed:
  59. {
  60. base.setActiveFocusToNextSetting(true)
  61. }
  62. Keys.onBacktabPressed:
  63. {
  64. base.setActiveFocusToNextSetting(false)
  65. }
  66. onActiveFocusChanged:
  67. {
  68. if (activeFocus)
  69. {
  70. base.focusReceived()
  71. }
  72. }
  73. Rectangle
  74. {
  75. anchors
  76. {
  77. top: parent.top
  78. bottom: parent.bottom
  79. left: parent.left
  80. }
  81. width: height
  82. radius: UM.Theme.getSize("setting_control_radius").width
  83. border.width: UM.Theme.getSize("default_lining").width
  84. border.color:
  85. {
  86. if(!enabled)
  87. {
  88. return UM.Theme.getColor("setting_control_disabled_border")
  89. }
  90. switch (propertyProvider.properties.validationState)
  91. {
  92. case "ValidatorState.Invalid":
  93. case "ValidatorState.Exception":
  94. case "ValidatorState.MinimumError":
  95. case "ValidatorState.MaximumError":
  96. return UM.Theme.getColor("setting_validation_error");
  97. case "ValidatorState.MinimumWarning":
  98. case "ValidatorState.MaximumWarning":
  99. return UM.Theme.getColor("setting_validation_warning");
  100. }
  101. // Validation is OK.
  102. if (control.containsMouse || control.activeFocus || hovered)
  103. {
  104. return UM.Theme.getColor("setting_control_border_highlight")
  105. }
  106. return UM.Theme.getColor("setting_control_border")
  107. }
  108. color: {
  109. if (!enabled)
  110. {
  111. return UM.Theme.getColor("setting_control_disabled")
  112. }
  113. switch (propertyProvider.properties.validationState)
  114. {
  115. case "ValidatorState.Invalid":
  116. case "ValidatorState.Exception":
  117. case "ValidatorState.MinimumError":
  118. case "ValidatorState.MaximumError":
  119. return UM.Theme.getColor("setting_validation_error_background")
  120. case "ValidatorState.MinimumWarning":
  121. case "ValidatorState.MaximumWarning":
  122. return UM.Theme.getColor("setting_validation_warning_background")
  123. }
  124. // Validation is OK.
  125. if (control.containsMouse || control.activeFocus)
  126. {
  127. return UM.Theme.getColor("setting_control_highlight")
  128. }
  129. return UM.Theme.getColor("setting_control")
  130. }
  131. UM.RecolorImage
  132. {
  133. anchors.verticalCenter: parent.verticalCenter
  134. anchors.horizontalCenter: parent.horizontalCenter
  135. width: Math.round(parent.width / 2.5)
  136. height: Math.round(parent.height / 2.5)
  137. sourceSize.height: width
  138. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text");
  139. source: UM.Theme.getIcon("Check")
  140. opacity: control.checked ? 1 : 0
  141. Behavior on opacity { NumberAnimation { duration: 100; } }
  142. }
  143. }
  144. }
  145. }