SettingCheckBox.qml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. // 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. Keys.onSpacePressed:
  46. {
  47. forceActiveFocus();
  48. propertyProvider.setPropertyValue("value", !checked);
  49. }
  50. onClicked:
  51. {
  52. forceActiveFocus();
  53. propertyProvider.setPropertyValue("value", !checked);
  54. }
  55. Keys.onTabPressed:
  56. {
  57. base.setActiveFocusToNextSetting(true)
  58. }
  59. Keys.onBacktabPressed:
  60. {
  61. base.setActiveFocusToNextSetting(false)
  62. }
  63. onActiveFocusChanged:
  64. {
  65. if(activeFocus)
  66. {
  67. base.focusReceived();
  68. }
  69. }
  70. Rectangle
  71. {
  72. anchors
  73. {
  74. top: parent.top
  75. bottom: parent.bottom
  76. left: parent.left
  77. }
  78. width: height
  79. color:
  80. {
  81. if(!enabled)
  82. {
  83. return UM.Theme.getColor("setting_control_disabled")
  84. }
  85. if(control.containsMouse || control.activeFocus)
  86. {
  87. return UM.Theme.getColor("setting_control_highlight")
  88. }
  89. return UM.Theme.getColor("setting_control")
  90. }
  91. border.width: UM.Theme.getSize("default_lining").width
  92. border.color:
  93. {
  94. if(!enabled)
  95. {
  96. return UM.Theme.getColor("setting_control_disabled_border")
  97. }
  98. if(control.containsMouse || control.activeFocus)
  99. {
  100. return UM.Theme.getColor("setting_control_border_highlight")
  101. }
  102. return UM.Theme.getColor("setting_control_border")
  103. }
  104. UM.RecolorImage {
  105. anchors.verticalCenter: parent.verticalCenter
  106. anchors.horizontalCenter: parent.horizontalCenter
  107. width: Math.round(parent.width / 2.5)
  108. height: Math.round(parent.height / 2.5)
  109. sourceSize.width: width
  110. sourceSize.height: width
  111. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text");
  112. source: UM.Theme.getIcon("check")
  113. opacity: control.checked ? 1 : 0
  114. Behavior on opacity { NumberAnimation { duration: 100; } }
  115. }
  116. }
  117. }
  118. }