SettingItem.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 / 1.2) + ((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. textFormat: Text.PlainText
  93. color: UM.Theme.getColor("setting_control_text");
  94. opacity: (definition.visible) ? 1 : 0.5
  95. // emphasize the setting if it has a value in the user or quality profile
  96. font: base.doQualityUserSettingEmphasis && base.stackLevel != undefined && base.stackLevel <= 1 ? UM.Theme.getFont("default_italic") : UM.Theme.getFont("default")
  97. }
  98. Row
  99. {
  100. id: settingControls
  101. height: Math.round(parent.height / 2)
  102. spacing: Math.round(UM.Theme.getSize("thick_margin").height / 2)
  103. anchors {
  104. right: controlContainer.left
  105. rightMargin: Math.round(UM.Theme.getSize("thick_margin").width / 2)
  106. verticalCenter: parent.verticalCenter
  107. }
  108. UM.SimpleButton
  109. {
  110. id: linkedSettingIcon;
  111. visible: Cura.MachineManager.activeStack != Cura.MachineManager.activeMachine && (!definition.settable_per_extruder || String(globalPropertyProvider.properties.limit_to_extruder) != "-1") && base.showLinkedSettingIcon
  112. height: parent.height;
  113. width: height;
  114. color: UM.Theme.getColor("setting_control_button")
  115. hoverColor: UM.Theme.getColor("setting_control_button")
  116. iconSource: UM.Theme.getIcon("link")
  117. onEntered: {
  118. hoverTimer.stop();
  119. var tooltipText = catalog.i18nc("@label", "This setting is always shared between all extruders. Changing it here will change the value for all extruders.");
  120. if ((resolve != "None") && (stackLevel != 0)) {
  121. // We come here if a setting has a resolve and the setting is not manually edited.
  122. tooltipText += " " + catalog.i18nc("@label", "The value is resolved from per-extruder values ") + "[" + Cura.ExtruderManager.getInstanceExtruderValues(definition.key) + "].";
  123. }
  124. base.showTooltip(tooltipText);
  125. }
  126. onExited: base.showTooltip(base.tooltipText);
  127. }
  128. UM.SimpleButton
  129. {
  130. id: revertButton;
  131. visible: base.stackLevel == 0 && base.showRevertButton
  132. height: parent.height;
  133. width: height;
  134. color: UM.Theme.getColor("setting_control_button")
  135. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  136. iconSource: UM.Theme.getIcon("reset")
  137. onClicked: {
  138. revertButton.focus = true
  139. if (externalResetHandler) {
  140. externalResetHandler(propertyProvider.key)
  141. } else {
  142. Cura.MachineManager.clearUserSettingAllCurrentStacks(propertyProvider.key)
  143. }
  144. }
  145. 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.")) }
  146. onExited: base.showTooltip(base.tooltipText);
  147. }
  148. UM.SimpleButton
  149. {
  150. // This button shows when the setting has an inherited function, but is overriden by profile.
  151. id: inheritButton;
  152. // Inherit button needs to be visible if;
  153. // - User made changes that override any loaded settings
  154. // - This setting item uses inherit button at all
  155. // - The type of the value of any deeper container is an "object" (eg; is a function)
  156. visible:
  157. {
  158. if(!base.showInheritButton)
  159. {
  160. return false;
  161. }
  162. if(!propertyProvider.properties.enabled)
  163. {
  164. // Note: This is not strictly necessary since a disabled setting is hidden anyway.
  165. // But this will cause the binding to be re-evaluated when the enabled property changes.
  166. return false;
  167. }
  168. // There are no settings with any warning.
  169. if(Cura.SettingInheritanceManager.settingsWithInheritanceWarning.length == 0)
  170. {
  171. return false;
  172. }
  173. // This setting has a resolve value, so an inheritance warning doesn't do anything.
  174. if(resolve != "None")
  175. {
  176. return false
  177. }
  178. // If the setting does not have a limit_to_extruder property (or is -1), use the active stack.
  179. if(globalPropertyProvider.properties.limit_to_extruder == null || String(globalPropertyProvider.properties.limit_to_extruder) == "-1")
  180. {
  181. return Cura.SettingInheritanceManager.settingsWithInheritanceWarning.indexOf(definition.key) >= 0;
  182. }
  183. // Setting does have a limit_to_extruder property, so use that one instead.
  184. if (definition.key === undefined) {
  185. // Observed when loading workspace, probably when SettingItems are removed.
  186. return false;
  187. }
  188. return Cura.SettingInheritanceManager.getOverridesForExtruder(definition.key, String(globalPropertyProvider.properties.limit_to_extruder)).indexOf(definition.key) >= 0;
  189. }
  190. height: parent.height;
  191. width: height;
  192. onClicked: {
  193. focus = true;
  194. // Get the most shallow function value (eg not a number) that we can find.
  195. var last_entry = propertyProvider.stackLevels[propertyProvider.stackLevels.length - 1]
  196. for (var i = 1; i < base.stackLevels.length; i++)
  197. {
  198. var has_setting_function = typeof(propertyProvider.getPropertyValue("value", base.stackLevels[i])) == "object";
  199. if(has_setting_function)
  200. {
  201. last_entry = propertyProvider.stackLevels[i]
  202. break;
  203. }
  204. }
  205. if((last_entry == 4 || last_entry == 11) && base.stackLevel == 0 && base.stackLevels.length == 2)
  206. {
  207. // Special case of the inherit reset. If only the definition (4th or 11th) container) and the first
  208. // entry (user container) are set, we can simply remove the container.
  209. propertyProvider.removeFromContainer(0)
  210. }
  211. else
  212. {
  213. // Put that entry into the "top" instance container.
  214. // This ensures that the value in any of the deeper containers need not be removed, which is
  215. // needed for the reset button (which deletes the top value) to correctly go back to profile
  216. // defaults.
  217. propertyProvider.setPropertyValue("value", propertyProvider.getPropertyValue("value", last_entry))
  218. propertyProvider.setPropertyValue("state", "InstanceState.Calculated")
  219. }
  220. }
  221. color: UM.Theme.getColor("setting_control_button")
  222. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  223. iconSource: UM.Theme.getIcon("formula");
  224. 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.")) }
  225. onExited: base.showTooltip(base.tooltipText);
  226. }
  227. }
  228. Item
  229. {
  230. id: controlContainer;
  231. enabled: propertyProvider.isValueUsed
  232. anchors.right: parent.right;
  233. anchors.rightMargin: UM.Theme.getSize("default_margin").width * 3
  234. anchors.verticalCenter: parent.verticalCenter;
  235. width: UM.Theme.getSize("setting_control").width;
  236. height: UM.Theme.getSize("setting_control").height
  237. }
  238. }
  239. UM.I18nCatalog { id: catalog; name: "cura" }
  240. }