SettingItem.qml 12 KB

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