ConfigurationMenu.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import QtQuick.Controls.Styles 1.4
  6. import QtQuick.Layouts 1.3
  7. import UM 1.4 as UM
  8. import Cura 1.0 as Cura
  9. /**
  10. * Menu that allows you to select the configuration of the current printer, such
  11. * as the nozzle sizes and materials in each extruder.
  12. */
  13. Cura.ExpandablePopup
  14. {
  15. id: base
  16. property var extrudersModel: CuraApplication.getExtrudersModel()
  17. UM.I18nCatalog
  18. {
  19. id: catalog
  20. name: "cura"
  21. }
  22. enum ConfigurationMethod
  23. {
  24. Auto,
  25. Custom
  26. }
  27. contentPadding: UM.Theme.getSize("default_lining").width
  28. enabled: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasMaterials || Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasVariantBuildplates : false; //Only let it drop down if there is any configuration that you could change.
  29. headerItem: Item
  30. {
  31. // Horizontal list that shows the extruders and their materials
  32. RowLayout
  33. {
  34. anchors.top: parent.top
  35. anchors.bottom: parent.bottom
  36. anchors.left: parent.left
  37. width: parent.width - UM.Theme.getSize("standard_arrow").width
  38. visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasMaterials : false
  39. Repeater
  40. {
  41. model: extrudersModel
  42. delegate: Item
  43. {
  44. Layout.preferredWidth: Math.round(parent.width / extrudersModel.count)
  45. Layout.maximumWidth: Math.round(parent.width / extrudersModel.count)
  46. Layout.fillHeight: true
  47. property var extruderStack: Cura.MachineManager.activeMachine.extruders[model.index]
  48. property bool valueWarning: !Cura.ExtruderManager.getExtruderHasQualityForMaterial(extruderStack)
  49. property bool valueError: Cura.ContainerManager.getContainerMetaDataEntry(extruderStack.material.id, "compatible", "") != "True"
  50. // Extruder icon. Shows extruder index and has the same color as the active material.
  51. Cura.ExtruderIcon
  52. {
  53. id: extruderIcon
  54. materialColor: model.color
  55. extruderEnabled: model.enabled
  56. anchors.verticalCenter: parent.verticalCenter
  57. }
  58. MouseArea // Connection status tooltip hover area
  59. {
  60. id: tooltipHoverArea
  61. anchors.fill: parent
  62. hoverEnabled: true //getConnectionStatusMessage() !== ""
  63. acceptedButtons: Qt.NoButton // react to hover only, don't steal clicks
  64. onEntered:
  65. {
  66. base.mouseArea.entered() // we want both this and the outer area to be entered
  67. tooltip.show()
  68. }
  69. onExited: { tooltip.hide() }
  70. }
  71. Cura.ToolTip
  72. {
  73. id: tooltip
  74. x: 0
  75. y: parent.height + UM.Theme.getSize("default_margin").height
  76. width: UM.Theme.getSize("tooltip").width
  77. targetPoint: Qt.point(Math.round(extruderIcon.width / 2), 0)
  78. text:
  79. {
  80. if (parent.valueError)
  81. {
  82. return catalog.i18nc("@tooltip", "The configuration of this extruder is not allowed, and prohibits slicing.")
  83. }
  84. if (parent.valueWarning)
  85. {
  86. return catalog.i18nc("@tooltip", "There are no profiles matching the configuration of this extruder.")
  87. }
  88. return ""
  89. }
  90. }
  91. // Warning icon that indicates if no qualities are available for the variant/material combination for this extruder
  92. UM.StatusIcon
  93. {
  94. id: configurationWarning
  95. visible: parent.valueWarning || parent.valueError
  96. anchors
  97. {
  98. top: extruderIcon.top
  99. topMargin: - Math.round(height * 1 / 6)
  100. left: extruderIcon.left
  101. leftMargin: extruderIcon.width - Math.round(width * 5 / 6)
  102. }
  103. // width is set to draw the same size as the MachineSelector connectionStatusImage, which is drawn as an image instead of a statusicon
  104. width: UM.Theme.getSize("icon_indicator").width + 2 * UM.Theme.getSize("default_lining").width
  105. height: width
  106. status:
  107. {
  108. if (parent.valueError)
  109. {
  110. return UM.StatusIcon.Status.ERROR
  111. }
  112. if (parent.valueWarning)
  113. {
  114. return UM.StatusIcon.Status.WARNING
  115. }
  116. return UM.StatusIcon.Status.NEUTRAL
  117. }
  118. }
  119. Column
  120. {
  121. opacity: model.enabled ? 1 : UM.Theme.getColor("extruder_disabled").a
  122. spacing: 0
  123. visible: width > 0
  124. anchors
  125. {
  126. left: extruderIcon.right
  127. leftMargin: UM.Theme.getSize("default_margin").width
  128. verticalCenter: parent.verticalCenter
  129. right: parent.right
  130. rightMargin: UM.Theme.getSize("default_margin").width
  131. }
  132. // Label for the brand of the material
  133. Label
  134. {
  135. id: materialBrandNameLabel
  136. text: model.material_brand + " " + model.material_name
  137. elide: Text.ElideRight
  138. font: UM.Theme.getFont("default")
  139. color: UM.Theme.getColor("text")
  140. renderType: Text.NativeRendering
  141. width: parent.width
  142. visible: !truncated
  143. }
  144. Label
  145. {
  146. id: materialNameLabel
  147. text: model.material_name
  148. elide: Text.ElideRight
  149. font: UM.Theme.getFont("default")
  150. color: UM.Theme.getColor("text")
  151. renderType: Text.NativeRendering
  152. width: parent.width
  153. visible: !materialBrandNameLabel.visible && !truncated
  154. }
  155. Label
  156. {
  157. id: materialTypeLabel
  158. text: model.material_type
  159. elide: Text.ElideRight
  160. font: UM.Theme.getFont("default")
  161. color: UM.Theme.getColor("text")
  162. renderType: Text.NativeRendering
  163. width: parent.width
  164. visible: !materialBrandNameLabel.visible && !materialNameLabel.visible
  165. }
  166. // Label that shows the name of the variant
  167. Label
  168. {
  169. id: variantLabel
  170. visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasVariants : false
  171. text: model.variant
  172. elide: Text.ElideRight
  173. font: UM.Theme.getFont("default_bold")
  174. color: UM.Theme.getColor("text")
  175. renderType: Text.NativeRendering
  176. Layout.preferredWidth: parent.width
  177. }
  178. }
  179. }
  180. }
  181. }
  182. // Placeholder text if there is a configuration to select but no materials (so we can't show the materials per extruder).
  183. Label
  184. {
  185. text: catalog.i18nc("@label", "Select configuration")
  186. elide: Text.ElideRight
  187. font: UM.Theme.getFont("medium")
  188. color: UM.Theme.getColor("text")
  189. renderType: Text.NativeRendering
  190. visible: Cura.MachineManager.activeMachine ? !Cura.MachineManager.activeMachine.hasMaterials && (Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasVariantBuildplates) : false
  191. anchors
  192. {
  193. left: parent.left
  194. leftMargin: UM.Theme.getSize("default_margin").width
  195. verticalCenter: parent.verticalCenter
  196. }
  197. }
  198. }
  199. contentItem: Column
  200. {
  201. id: popupItem
  202. width: UM.Theme.getSize("configuration_selector").width
  203. height: implicitHeight // Required because ExpandableComponent will try to use this to determine the size of the background of the pop-up.
  204. padding: UM.Theme.getSize("default_margin").height
  205. spacing: UM.Theme.getSize("default_margin").height
  206. property bool is_connected: false // If current machine is connected to a printer. Only evaluated upon making popup visible.
  207. property int configuration_method: ConfigurationMenu.ConfigurationMethod.Custom // Type of configuration being used. Only evaluated upon making popup visible.
  208. property int manual_selected_method: -1 // It stores the configuration method selected by the user. By default the selected method is
  209. onVisibleChanged:
  210. {
  211. is_connected = Cura.MachineManager.activeMachine.hasRemoteConnection && Cura.MachineManager.printerConnected && Cura.MachineManager.printerOutputDevices[0].uniqueConfigurations.length > 0 //Re-evaluate.
  212. // If the printer is not connected or does not have configurations, we switch always to the custom mode. If is connected instead, the auto mode
  213. // or the previous state is selected
  214. configuration_method = is_connected ? (manual_selected_method == -1 ? ConfigurationMenu.ConfigurationMethod.Auto : manual_selected_method) : ConfigurationMenu.ConfigurationMethod.Custom
  215. }
  216. Item
  217. {
  218. width: parent.width - 2 * parent.padding
  219. height:
  220. {
  221. var height = 0
  222. if (autoConfiguration.visible)
  223. {
  224. height += autoConfiguration.height
  225. }
  226. if (customConfiguration.visible)
  227. {
  228. height += customConfiguration.height
  229. }
  230. return height
  231. }
  232. AutoConfiguration
  233. {
  234. id: autoConfiguration
  235. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  236. }
  237. CustomConfiguration
  238. {
  239. id: customConfiguration
  240. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  241. }
  242. }
  243. Rectangle
  244. {
  245. id: separator
  246. visible: buttonBar.visible
  247. x: -parent.padding
  248. width: parent.width
  249. height: UM.Theme.getSize("default_lining").height
  250. color: UM.Theme.getColor("lining")
  251. }
  252. //Allow switching between custom and auto.
  253. Item
  254. {
  255. id: buttonBar
  256. visible: popupItem.is_connected //Switching only makes sense if the "auto" part is possible.
  257. width: parent.width - 2 * parent.padding
  258. height: childrenRect.height
  259. Cura.SecondaryButton
  260. {
  261. id: goToCustom
  262. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  263. text: catalog.i18nc("@label", "Custom")
  264. anchors.right: parent.right
  265. iconSource: UM.Theme.getIcon("ChevronSingleRight")
  266. isIconOnRightSide: true
  267. onClicked:
  268. {
  269. popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Custom
  270. popupItem.manual_selected_method = popupItem.configuration_method
  271. }
  272. }
  273. Cura.SecondaryButton
  274. {
  275. id: goToAuto
  276. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  277. text: catalog.i18nc("@label", "Configurations")
  278. iconSource: UM.Theme.getIcon("ChevronSingleLeft")
  279. onClicked:
  280. {
  281. popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Auto
  282. popupItem.manual_selected_method = popupItem.configuration_method
  283. }
  284. }
  285. }
  286. }
  287. Connections
  288. {
  289. target: Cura.MachineManager
  290. function onGlobalContainerChanged() { popupItem.manual_selected_method = -1 } // When switching printers, reset the value of the manual selected method
  291. }
  292. }