SettingItem.qml 13 KB

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