SettingCheckBox.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 != "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
  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. color:
  83. {
  84. if (!enabled)
  85. {
  86. return UM.Theme.getColor("setting_control_disabled")
  87. }
  88. if (control.containsMouse || control.activeFocus)
  89. {
  90. return UM.Theme.getColor("setting_control_highlight")
  91. }
  92. return UM.Theme.getColor("setting_control")
  93. }
  94. radius: UM.Theme.getSize("setting_control_radius").width
  95. border.width: UM.Theme.getSize("default_lining").width
  96. border.color:
  97. {
  98. if (!enabled)
  99. {
  100. return UM.Theme.getColor("setting_control_disabled_border")
  101. }
  102. if (control.containsMouse || control.activeFocus)
  103. {
  104. return UM.Theme.getColor("setting_control_border_highlight")
  105. }
  106. return UM.Theme.getColor("setting_control_border")
  107. }
  108. UM.RecolorImage
  109. {
  110. anchors.verticalCenter: parent.verticalCenter
  111. anchors.horizontalCenter: parent.horizontalCenter
  112. width: Math.round(parent.width / 2.5)
  113. height: Math.round(parent.height / 2.5)
  114. sourceSize.height: width
  115. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text");
  116. source: UM.Theme.getIcon("check")
  117. opacity: control.checked ? 1 : 0
  118. Behavior on opacity { NumberAnimation { duration: 100; } }
  119. }
  120. }
  121. }
  122. }