SettingCheckBox.qml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 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. property var focusItem: control
  12. contents: MouseArea
  13. {
  14. id: control
  15. anchors.fill: parent
  16. hoverEnabled: true
  17. property bool checked:
  18. {
  19. // FIXME this needs to go away once 'resolve' is combined with 'value' in our data model.
  20. // Stacklevels
  21. // 0: user -> unsaved change
  22. // 1: quality changes -> saved change
  23. // 2: quality
  24. // 3: material -> user changed material in materials page
  25. // 4: variant
  26. // 5: machine
  27. var value;
  28. if ((base.resolve != "None") && (stackLevel != 0) && (stackLevel != 1)) {
  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. } else {
  34. value = propertyProvider.properties.value;
  35. }
  36. switch(value)
  37. {
  38. case "True":
  39. return true;
  40. case "False":
  41. return false;
  42. default:
  43. return value;
  44. }
  45. }
  46. Keys.onSpacePressed:
  47. {
  48. forceActiveFocus();
  49. propertyProvider.setPropertyValue("value", !checked);
  50. }
  51. onClicked:
  52. {
  53. forceActiveFocus();
  54. propertyProvider.setPropertyValue("value", !checked);
  55. }
  56. Keys.onTabPressed:
  57. {
  58. base.setActiveFocusToNextSetting(true)
  59. }
  60. Keys.onBacktabPressed:
  61. {
  62. base.setActiveFocusToNextSetting(false)
  63. }
  64. onActiveFocusChanged:
  65. {
  66. if(activeFocus)
  67. {
  68. base.focusReceived();
  69. }
  70. }
  71. Rectangle
  72. {
  73. anchors
  74. {
  75. top: parent.top
  76. bottom: parent.bottom
  77. left: parent.left
  78. }
  79. width: height
  80. color:
  81. {
  82. if(!enabled)
  83. {
  84. return UM.Theme.getColor("setting_control_disabled")
  85. }
  86. if(control.containsMouse || control.activeFocus)
  87. {
  88. return UM.Theme.getColor("setting_control_highlight")
  89. }
  90. return UM.Theme.getColor("setting_control")
  91. }
  92. border.width: UM.Theme.getSize("default_lining").width
  93. border.color:
  94. {
  95. if(!enabled)
  96. {
  97. return UM.Theme.getColor("setting_control_disabled_border")
  98. }
  99. if(control.containsMouse || control.activeFocus)
  100. {
  101. return UM.Theme.getColor("setting_control_border_highlight")
  102. }
  103. return UM.Theme.getColor("setting_control_border")
  104. }
  105. UM.RecolorImage {
  106. anchors.verticalCenter: parent.verticalCenter
  107. anchors.horizontalCenter: parent.horizontalCenter
  108. width: parent.width / 2.5
  109. height: parent.height / 2.5
  110. sourceSize.width: width
  111. sourceSize.height: width
  112. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text");
  113. source: UM.Theme.getIcon("check")
  114. opacity: control.checked ? 1 : 0
  115. Behavior on opacity { NumberAnimation { duration: 100; } }
  116. }
  117. }
  118. }
  119. }