SettingItem.qml 14 KB

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