SettingItem.qml 13 KB

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