SettingItem.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 overlaping 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 var showRevertButton: true
  20. property var showInheritButton: true
  21. property var showLinkedSettingIcon: true
  22. property var doDepthIndentation: true
  23. property var 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. // There is no resolve property if there is only one stack.
  28. property var resolve: Cura.MachineManager.activeStackId != Cura.MachineManager.activeMachineId ? propertyProvider.properties.resolve : "None"
  29. property var stackLevels: propertyProvider.stackLevels
  30. property var stackLevel: stackLevels[0]
  31. signal focusReceived()
  32. signal setActiveFocusToNextSetting(bool forward)
  33. signal contextMenuRequested()
  34. signal showTooltip(string text)
  35. signal hideTooltip()
  36. signal showAllHiddenInheritedSettings(string category_id)
  37. property string tooltipText:
  38. {
  39. var affects = settingDefinitionsModel.getRequiredBy(definition.key, "value")
  40. var affected_by = settingDefinitionsModel.getRequires(definition.key, "value")
  41. var affected_by_list = ""
  42. for (var i in affected_by)
  43. {
  44. affected_by_list += "<li>%1</li>\n".arg(affected_by[i].label)
  45. }
  46. var affects_list = ""
  47. for (var i in affects)
  48. {
  49. affects_list += "<li>%1</li>\n".arg(affects[i].label)
  50. }
  51. var tooltip = "<b>%1</b>\n<p>%2</p>".arg(definition.label).arg(definition.description)
  52. if (affects_list != "")
  53. {
  54. tooltip += "<br/><b>%1</b>\n<ul>\n%2</ul>".arg(catalog.i18nc("@label Header for list of settings.", "Affects")).arg(affects_list)
  55. }
  56. if (affected_by_list != "")
  57. {
  58. tooltip += "<br/><b>%1</b>\n<ul>\n%2</ul>".arg(catalog.i18nc("@label Header for list of settings.", "Affected By")).arg(affected_by_list)
  59. }
  60. return tooltip
  61. }
  62. MouseArea
  63. {
  64. id: mouse
  65. anchors.fill: parent
  66. acceptedButtons: Qt.RightButton
  67. hoverEnabled: true;
  68. onClicked: base.contextMenuRequested()
  69. onEntered:
  70. {
  71. hoverTimer.start()
  72. }
  73. onExited:
  74. {
  75. if (controlContainer.item && controlContainer.item.hovered)
  76. {
  77. return
  78. }
  79. hoverTimer.stop()
  80. base.hideTooltip()
  81. }
  82. Timer
  83. {
  84. id: hoverTimer
  85. interval: 500
  86. repeat: false
  87. onTriggered:
  88. {
  89. base.showTooltip(base.tooltipText)
  90. }
  91. }
  92. Label
  93. {
  94. id: label
  95. anchors.left: parent.left
  96. anchors.leftMargin: doDepthIndentation ? Math.round(UM.Theme.getSize("thin_margin").width + ((definition.depth - 1) * UM.Theme.getSize("setting_control_depth_margin").width)) : 0
  97. anchors.right: settingControls.left
  98. anchors.verticalCenter: parent.verticalCenter
  99. text: definition.label
  100. elide: Text.ElideMiddle
  101. renderType: Text.NativeRendering
  102. textFormat: Text.PlainText
  103. color: UM.Theme.getColor("setting_control_text")
  104. opacity: (definition.visible) ? 1 : 0.5
  105. // emphasize the setting if it has a value in the user or quality profile
  106. font: base.doQualityUserSettingEmphasis && base.stackLevel != undefined && base.stackLevel <= 1 ? UM.Theme.getFont("default_italic") : UM.Theme.getFont("default")
  107. }
  108. Row
  109. {
  110. id: settingControls
  111. height: Math.round(parent.height / 2)
  112. spacing: Math.round(UM.Theme.getSize("thick_margin").height / 2)
  113. anchors
  114. {
  115. right: controlContainer.left
  116. rightMargin: Math.round(UM.Theme.getSize("thick_margin").width / 2)
  117. verticalCenter: parent.verticalCenter
  118. }
  119. UM.SimpleButton
  120. {
  121. id: linkedSettingIcon;
  122. visible: Cura.MachineManager.activeStack != Cura.MachineManager.activeMachine && (!definition.settable_per_extruder || String(globalPropertyProvider.properties.limit_to_extruder) != "-1") && base.showLinkedSettingIcon
  123. height: parent.height;
  124. width: height;
  125. color: UM.Theme.getColor("setting_control_button")
  126. hoverColor: UM.Theme.getColor("setting_control_button")
  127. iconSource: UM.Theme.getIcon("link")
  128. onEntered:
  129. {
  130. hoverTimer.stop()
  131. var tooltipText = catalog.i18nc("@label", "This setting is always shared between all extruders. Changing it here will change the value for all extruders.")
  132. if ((resolve != "None") && (stackLevel != 0))
  133. {
  134. // We come here if a setting has a resolve and the setting is not manually edited.
  135. tooltipText += " " + catalog.i18nc("@label", "The value is resolved from per-extruder values ") + "[" + Cura.ExtruderManager.getInstanceExtruderValues(definition.key) + "]."
  136. }
  137. base.showTooltip(tooltipText)
  138. }
  139. onExited: base.showTooltip(base.tooltipText)
  140. }
  141. UM.SimpleButton
  142. {
  143. id: revertButton
  144. visible: base.stackLevel == 0 && base.showRevertButton
  145. height: parent.height
  146. width: height
  147. color: UM.Theme.getColor("setting_control_button")
  148. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  149. iconSource: UM.Theme.getIcon("reset")
  150. onClicked:
  151. {
  152. revertButton.focus = true
  153. if (externalResetHandler)
  154. {
  155. externalResetHandler(propertyProvider.key)
  156. }
  157. else
  158. {
  159. Cura.MachineManager.clearUserSettingAllCurrentStacks(propertyProvider.key)
  160. }
  161. }
  162. onEntered:
  163. {
  164. hoverTimer.stop()
  165. 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."))
  166. }
  167. onExited: base.showTooltip(base.tooltipText)
  168. }
  169. UM.SimpleButton
  170. {
  171. // This button shows when the setting has an inherited function, but is overriden by profile.
  172. id: inheritButton
  173. // Inherit button needs to be visible if;
  174. // - User made changes that override any loaded settings
  175. // - This setting item uses inherit button at all
  176. // - The type of the value of any deeper container is an "object" (eg; is a function)
  177. visible:
  178. {
  179. if (!base.showInheritButton)
  180. {
  181. return false
  182. }
  183. if (!propertyProvider.properties.enabled)
  184. {
  185. // Note: This is not strictly necessary since a disabled setting is hidden anyway.
  186. // But this will cause the binding to be re-evaluated when the enabled property changes.
  187. return false
  188. }
  189. // There are no settings with any warning.
  190. if (Cura.SettingInheritanceManager.settingsWithInheritanceWarning.length == 0)
  191. {
  192. return false
  193. }
  194. // This setting has a resolve value, so an inheritance warning doesn't do anything.
  195. if (resolve != "None")
  196. {
  197. return false
  198. }
  199. // If the setting does not have a limit_to_extruder property (or is -1), use the active stack.
  200. if (globalPropertyProvider.properties.limit_to_extruder == null || String(globalPropertyProvider.properties.limit_to_extruder) == "-1")
  201. {
  202. return Cura.SettingInheritanceManager.settingsWithInheritanceWarning.indexOf(definition.key) >= 0
  203. }
  204. // Setting does have a limit_to_extruder property, so use that one instead.
  205. if (definition.key === undefined) {
  206. // Observed when loading workspace, probably when SettingItems are removed.
  207. return false
  208. }
  209. return Cura.SettingInheritanceManager.getOverridesForExtruder(definition.key, String(globalPropertyProvider.properties.limit_to_extruder)).indexOf(definition.key) >= 0
  210. }
  211. height: parent.height
  212. width: height
  213. onClicked:
  214. {
  215. focus = true
  216. // Get the most shallow function value (eg not a number) that we can find.
  217. var last_entry = propertyProvider.stackLevels[propertyProvider.stackLevels.length - 1]
  218. for (var i = 1; i < base.stackLevels.length; i++)
  219. {
  220. var has_setting_function = typeof(propertyProvider.getPropertyValue("value", base.stackLevels[i])) == "object"
  221. if(has_setting_function)
  222. {
  223. last_entry = propertyProvider.stackLevels[i]
  224. break
  225. }
  226. }
  227. if ((last_entry == 4 || last_entry == 11) && base.stackLevel == 0 && base.stackLevels.length == 2)
  228. {
  229. // Special case of the inherit reset. If only the definition (4th or 11th) container) and the first
  230. // entry (user container) are set, we can simply remove the container.
  231. propertyProvider.removeFromContainer(0)
  232. }
  233. else
  234. {
  235. // Put that entry into the "top" instance container.
  236. // This ensures that the value in any of the deeper containers need not be removed, which is
  237. // needed for the reset button (which deletes the top value) to correctly go back to profile
  238. // defaults.
  239. propertyProvider.setPropertyValue("value", propertyProvider.getPropertyValue("value", last_entry))
  240. propertyProvider.setPropertyValue("state", "InstanceState.Calculated")
  241. }
  242. }
  243. color: UM.Theme.getColor("setting_control_button")
  244. hoverColor: UM.Theme.getColor("setting_control_button_hover")
  245. iconSource: UM.Theme.getIcon("formula")
  246. 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.")) }
  247. onExited: base.showTooltip(base.tooltipText)
  248. }
  249. }
  250. Item
  251. {
  252. id: controlContainer
  253. enabled: propertyProvider.isValueUsed
  254. anchors.right: parent.right
  255. anchors.verticalCenter: parent.verticalCenter
  256. width: UM.Theme.getSize("setting_control").width
  257. height: UM.Theme.getSize("setting_control").height
  258. }
  259. }
  260. UM.I18nCatalog { id: catalog; name: "cura" }
  261. }