SettingItem.qml 13 KB

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