SettingItem.qml 13 KB

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