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: 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.item && controlContainer.item.hovered)
  91. {
  92. return
  93. }
  94. hoverTimer.stop()
  95. base.hideTooltip()
  96. }
  97. Timer
  98. {
  99. id: hoverTimer
  100. interval: 500
  101. repeat: false
  102. onTriggered:
  103. {
  104. base.showTooltip(base.createTooltipText())
  105. }
  106. }
  107. Label
  108. {
  109. id: label
  110. anchors.left: parent.left
  111. anchors.leftMargin: doDepthIndentation ? Math.round(UM.Theme.getSize("thin_margin").width + ((definition.depth - 1) * UM.Theme.getSize("default_margin").width)) : 0
  112. anchors.right: settingControls.left
  113. anchors.verticalCenter: parent.verticalCenter
  114. text: definition.label
  115. elide: Text.ElideMiddle
  116. renderType: Text.NativeRendering
  117. textFormat: Text.PlainText
  118. color: UM.Theme.getColor("setting_control_text")
  119. opacity: (definition.visible) ? 1 : 0.5
  120. // emphasize the setting if it has a value in the user or quality profile
  121. font: base.doQualityUserSettingEmphasis && base.stackLevel !== undefined && base.stackLevel <= 1 ? UM.Theme.getFont("default_italic") : UM.Theme.getFont("default")
  122. }
  123. Row
  124. {
  125. id: settingControls
  126. height: UM.Theme.getSize("small_button_icon").height
  127. spacing: Math.round(UM.Theme.getSize("thick_margin").height / 2)
  128. anchors
  129. {
  130. right: controlContainer.left
  131. rightMargin: Math.round(UM.Theme.getSize("thick_margin").width / 2)
  132. verticalCenter: parent.verticalCenter
  133. }
  134. UM.SimpleButton
  135. {
  136. id: linkedSettingIcon;
  137. visible: (!definition.settable_per_extruder || String(globalPropertyProvider.properties.limit_to_extruder) != "-1") && base.showLinkedSettingIcon
  138. anchors.top: parent.top
  139. anchors.bottom: parent.bottom
  140. height: UM.Theme.getSize("small_button_icon").height
  141. width: height
  142. color: UM.Theme.getColor("setting_control_button")
  143. hoverColor: UM.Theme.getColor("setting_control_button")
  144. iconSource: UM.Theme.getIcon("Link")
  145. onEntered:
  146. {
  147. hoverTimer.stop()
  148. var tooltipText = catalog.i18nc("@label", "This setting is always shared between all extruders. Changing it here will change the value for all extruders.")
  149. if ((resolve !== "None") && (stackLevel !== 0))
  150. {
  151. // We come here if a setting has a resolve and the setting is not manually edited.
  152. tooltipText += " " + catalog.i18nc("@label", "This setting is resolved from conflicting extruder-specific values:") + " [" + Cura.ExtruderManager.getInstanceExtruderValues(definition.key) + "]."
  153. }
  154. base.showTooltip(tooltipText)
  155. }
  156. onExited: base.showTooltip(base.createTooltipText())
  157. }
  158. UM.SimpleButton
  159. {
  160. id: revertButton
  161. visible: base.resetButtonVisible
  162. anchors.top: parent.top
  163. anchors.bottom: parent.bottom
  164. height: UM.Theme.getSize("small_button_icon").height
  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("ArrowReset")
  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 || 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.hasOverrides(definition.key, globalPropertyProvider.properties.limit_to_extruder)
  233. }
  234. anchors.top: parent.top
  235. anchors.bottom: parent.bottom
  236. height: UM.Theme.getSize("small_button_icon").height
  237. width: height
  238. onClicked:
  239. {
  240. focus = true
  241. // Get the most shallow function value (eg not a number) that we can find.
  242. var last_entry = propertyProvider.stackLevels[propertyProvider.stackLevels.length - 1]
  243. for (var i = 1; i < base.stackLevels.length; i++)
  244. {
  245. var has_setting_function = typeof(propertyProvider.getPropertyValue("value", base.stackLevels[i])) == "object"
  246. if(has_setting_function)
  247. {
  248. last_entry = propertyProvider.stackLevels[i]
  249. break
  250. }
  251. }
  252. if ((last_entry === 4 || last_entry === 11) && base.stackLevel === 0 && base.stackLevels.length === 2)
  253. {
  254. // Special case of the inherit reset. If only the definition (4th or 11th) container) and the first
  255. // entry (user container) are set, we can simply remove the container.
  256. propertyProvider.removeFromContainer(0)
  257. }
  258. else
  259. {
  260. // Put that entry into the "top" instance container.
  261. // This ensures that the value in any of the deeper containers need not be removed, which is
  262. // needed for the reset button (which deletes the top value) to correctly go back to profile
  263. // defaults.
  264. propertyProvider.setPropertyValue("value", propertyProvider.getPropertyValue("value", last_entry))
  265. propertyProvider.setPropertyValue("state", "InstanceState.Calculated")
  266. }
  267. }
  268. color: UM.Theme.getColor("setting_control_button")
  269. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  270. iconSource: UM.Theme.getIcon("Function")
  271. 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.")) }
  272. onExited: base.showTooltip(base.createTooltipText())
  273. }
  274. }
  275. Item
  276. {
  277. id: controlContainer
  278. enabled: propertyProvider.isValueUsed
  279. anchors.right: parent.right
  280. anchors.verticalCenter: parent.verticalCenter
  281. width: UM.Theme.getSize("setting_control").width
  282. height: UM.Theme.getSize("setting_control").height
  283. }
  284. }
  285. }