SettingItem.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura 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.1 as UM
  7. import Cura 1.0 as Cura
  8. import "."
  9. Item {
  10. id: base;
  11. height: UM.Theme.getSize("section").height
  12. property alias contents: controlContainer.children
  13. property alias hovered: mouse.containsMouse
  14. property var showRevertButton: true
  15. property var showInheritButton: true
  16. property var showLinkedSettingIcon: true
  17. property var doDepthIndentation: true
  18. property var doQualityUserSettingEmphasis: true
  19. // Create properties to put property provider stuff in (bindings break in qt 5.5.1 otherwise)
  20. property var state: propertyProvider.properties.state
  21. // There is no resolve property if there is only one stack.
  22. property var resolve: Cura.MachineManager.activeStackId != Cura.MachineManager.activeMachineId ? propertyProvider.properties.resolve : "None"
  23. property var stackLevels: propertyProvider.stackLevels
  24. property var stackLevel: stackLevels[0]
  25. signal focusReceived()
  26. signal setActiveFocusToNextSetting(bool forward)
  27. signal contextMenuRequested()
  28. signal showTooltip(string text)
  29. signal hideTooltip()
  30. signal showAllHiddenInheritedSettings(string category_id)
  31. property string tooltipText:
  32. {
  33. var affects = settingDefinitionsModel.getRequiredBy(definition.key, "value")
  34. var affected_by = settingDefinitionsModel.getRequires(definition.key, "value")
  35. var affected_by_list = ""
  36. for(var i in affected_by)
  37. {
  38. affected_by_list += "<li>%1</li>\n".arg(affected_by[i].label)
  39. }
  40. var affects_list = ""
  41. for(var i in affects)
  42. {
  43. affects_list += "<li>%1</li>\n".arg(affects[i].label)
  44. }
  45. var tooltip = "<b>%1</b>\n<p>%2</p>".arg(definition.label).arg(definition.description)
  46. if(affects_list != "")
  47. {
  48. tooltip += "<br/><b>%1</b>\n<ul>\n%2</ul>".arg(catalog.i18nc("@label Header for list of settings.", "Affects")).arg(affects_list)
  49. }
  50. if(affected_by_list != "")
  51. {
  52. tooltip += "<br/><b>%1</b>\n<ul>\n%2</ul>".arg(catalog.i18nc("@label Header for list of settings.", "Affected By")).arg(affected_by_list)
  53. }
  54. return tooltip
  55. }
  56. MouseArea
  57. {
  58. id: mouse;
  59. anchors.fill: parent;
  60. acceptedButtons: Qt.RightButton;
  61. hoverEnabled: true;
  62. onClicked: base.contextMenuRequested();
  63. onEntered: {
  64. hoverTimer.start();
  65. }
  66. onExited: {
  67. if(controlContainer.item && controlContainer.item.hovered) {
  68. return;
  69. }
  70. hoverTimer.stop();
  71. base.hideTooltip();
  72. }
  73. Timer {
  74. id: hoverTimer;
  75. interval: 500;
  76. repeat: false;
  77. onTriggered:
  78. {
  79. base.showTooltip(base.tooltipText);
  80. }
  81. }
  82. Label
  83. {
  84. id: label;
  85. anchors.left: parent.left;
  86. anchors.leftMargin: doDepthIndentation ? Math.round((UM.Theme.getSize("section_icon_column").width + 5) + ((definition.depth - 1) * UM.Theme.getSize("setting_control_depth_margin").width)) : 0
  87. anchors.right: settingControls.left;
  88. anchors.verticalCenter: parent.verticalCenter
  89. text: definition.label
  90. elide: Text.ElideMiddle;
  91. renderType: Text.NativeRendering
  92. color: UM.Theme.getColor("setting_control_text");
  93. opacity: (definition.visible) ? 1 : 0.5
  94. // emphasize the setting if it has a value in the user or quality profile
  95. font: base.doQualityUserSettingEmphasis && base.stackLevel != undefined && base.stackLevel <= 1 ? UM.Theme.getFont("default_italic") : UM.Theme.getFont("default")
  96. }
  97. Row
  98. {
  99. id: settingControls
  100. height: Math.round(parent.height / 2)
  101. spacing: Math.round(UM.Theme.getSize("sidebar_margin").height / 2)
  102. anchors {
  103. right: controlContainer.left
  104. rightMargin: Math.round(UM.Theme.getSize("sidebar_margin").width / 2)
  105. verticalCenter: parent.verticalCenter
  106. }
  107. UM.SimpleButton
  108. {
  109. id: linkedSettingIcon;
  110. visible: Cura.MachineManager.activeStackId != Cura.MachineManager.activeMachineId && (!definition.settable_per_extruder || String(globalPropertyProvider.properties.limit_to_extruder) != "-1") && base.showLinkedSettingIcon
  111. height: parent.height;
  112. width: height;
  113. color: UM.Theme.getColor("setting_control_button")
  114. hoverColor: UM.Theme.getColor("setting_control_button")
  115. iconSource: UM.Theme.getIcon("link")
  116. onEntered: {
  117. hoverTimer.stop();
  118. var tooltipText = catalog.i18nc("@label", "This setting is always shared between all extruders. Changing it here will change the value for all extruders.");
  119. if ((resolve != "None") && (stackLevel != 0)) {
  120. // We come here if a setting has a resolve and the setting is not manually edited.
  121. tooltipText += " " + catalog.i18nc("@label", "The value is resolved from per-extruder values ") + "[" + Cura.ExtruderManager.getInstanceExtruderValues(definition.key) + "].";
  122. }
  123. base.showTooltip(tooltipText);
  124. }
  125. onExited: base.showTooltip(base.tooltipText);
  126. }
  127. UM.SimpleButton
  128. {
  129. id: revertButton;
  130. visible: base.stackLevel == 0 && base.showRevertButton
  131. height: parent.height;
  132. width: height;
  133. color: UM.Theme.getColor("setting_control_button")
  134. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  135. iconSource: UM.Theme.getIcon("reset")
  136. onClicked: {
  137. revertButton.focus = true
  138. if (externalResetHandler) {
  139. externalResetHandler(propertyProvider.key)
  140. } else {
  141. Cura.MachineManager.clearUserSettingAllCurrentStacks(propertyProvider.key)
  142. }
  143. }
  144. onEntered: { hoverTimer.stop(); base.showTooltip(catalog.i18nc("@label", "This setting has a value that is different from the profile.\n\nClick to restore the value of the profile.")) }
  145. onExited: base.showTooltip(base.tooltipText);
  146. }
  147. UM.SimpleButton
  148. {
  149. // This button shows when the setting has an inherited function, but is overriden by profile.
  150. id: inheritButton;
  151. // Inherit button needs to be visible if;
  152. // - User made changes that override any loaded settings
  153. // - This setting item uses inherit button at all
  154. // - The type of the value of any deeper container is an "object" (eg; is a function)
  155. visible:
  156. {
  157. if(!base.showInheritButton)
  158. {
  159. return false;
  160. }
  161. if(!propertyProvider.properties.enabled)
  162. {
  163. // Note: This is not strictly necessary since a disabled setting is hidden anyway.
  164. // But this will cause the binding to be re-evaluated when the enabled property changes.
  165. return false;
  166. }
  167. // There are no settings with any warning.
  168. if(Cura.SettingInheritanceManager.settingsWithInheritanceWarning.length == 0)
  169. {
  170. return false;
  171. }
  172. // This setting has a resolve value, so an inheritance warning doesn't do anything.
  173. if(resolve != "None")
  174. {
  175. return false
  176. }
  177. // If the setting does not have a limit_to_extruder property (or is -1), use the active stack.
  178. if(globalPropertyProvider.properties.limit_to_extruder == null || String(globalPropertyProvider.properties.limit_to_extruder) == "-1")
  179. {
  180. return Cura.SettingInheritanceManager.settingsWithInheritanceWarning.indexOf(definition.key) >= 0;
  181. }
  182. // Setting does have a limit_to_extruder property, so use that one instead.
  183. if (definition.key === undefined) {
  184. // Observed when loading workspace, probably when SettingItems are removed.
  185. return false;
  186. }
  187. return Cura.SettingInheritanceManager.getOverridesForExtruder(definition.key, String(globalPropertyProvider.properties.limit_to_extruder)).indexOf(definition.key) >= 0;
  188. }
  189. height: parent.height;
  190. width: height;
  191. onClicked: {
  192. focus = true;
  193. // Get the most shallow function value (eg not a number) that we can find.
  194. var last_entry = propertyProvider.stackLevels[propertyProvider.stackLevels.length - 1]
  195. for (var i = 1; i < base.stackLevels.length; i++)
  196. {
  197. var has_setting_function = typeof(propertyProvider.getPropertyValue("value", base.stackLevels[i])) == "object";
  198. if(has_setting_function)
  199. {
  200. last_entry = propertyProvider.stackLevels[i]
  201. break;
  202. }
  203. }
  204. if((last_entry == 4 || last_entry == 11) && base.stackLevel == 0 && base.stackLevels.length == 2)
  205. {
  206. // Special case of the inherit reset. If only the definition (4th or 11th) container) and the first
  207. // entry (user container) are set, we can simply remove the container.
  208. propertyProvider.removeFromContainer(0)
  209. }
  210. else if(last_entry - 1 == base.stackLevel)
  211. {
  212. // Another special case. The setting that is overriden is only 1 instance container deeper,
  213. // so we can remove it.
  214. propertyProvider.removeFromContainer(0)
  215. }
  216. else
  217. {
  218. // Put that entry into the "top" instance container.
  219. // This ensures that the value in any of the deeper containers need not be removed, which is
  220. // needed for the reset button (which deletes the top value) to correctly go back to profile
  221. // defaults.
  222. propertyProvider.setPropertyValue("value", propertyProvider.getPropertyValue("value", last_entry))
  223. propertyProvider.setPropertyValue("state", "InstanceState.Calculated")
  224. }
  225. }
  226. color: UM.Theme.getColor("setting_control_button")
  227. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  228. iconSource: UM.Theme.getIcon("notice");
  229. onEntered: { hoverTimer.stop(); base.showTooltip(catalog.i18nc("@label", "This setting is normally calculated, but it currently has an absolute value set.\n\nClick to restore the calculated value.")) }
  230. onExited: base.showTooltip(base.tooltipText);
  231. }
  232. }
  233. Item
  234. {
  235. id: controlContainer;
  236. enabled: propertyProvider.isValueUsed
  237. anchors.right: parent.right;
  238. anchors.rightMargin: UM.Theme.getSize("sidebar_margin").width
  239. anchors.verticalCenter: parent.verticalCenter;
  240. width: UM.Theme.getSize("setting_control").width;
  241. height: UM.Theme.getSize("setting_control").height
  242. }
  243. }
  244. UM.I18nCatalog { id: catalog; name: "cura" }
  245. }