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