SettingItem.qml 14 KB

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