ConfigurationMenu.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. // Extruder icon. Shows extruder index and has the same color as the active material.
  48. Cura.ExtruderIcon
  49. {
  50. id: extruderIcon
  51. materialColor: model.color
  52. extruderEnabled: model.enabled
  53. anchors.verticalCenter: parent.verticalCenter
  54. }
  55. // Warning icon that indicates if no qualities are available for the variant/material combination for this extruder
  56. UM.StatusIcon
  57. {
  58. id: configurationWarning
  59. property var extruderStack: Cura.MachineManager.activeMachine.extruders[model.index]
  60. property bool valueWarning: !Cura.ExtruderManager.getExtruderHasQualityForMaterial(extruderStack)
  61. property bool valueError: Cura.ContainerManager.getContainerMetaDataEntry(extruderStack.material.id, "compatible", "") != "True"
  62. visible: valueWarning || valueError
  63. anchors
  64. {
  65. top: extruderIcon.top
  66. topMargin: - Math.round(height * 1 / 6)
  67. left: extruderIcon.left
  68. leftMargin: extruderIcon.width - Math.round(width * 5 / 6)
  69. }
  70. // width is set to draw the same size as the MachineSelector connectionStatusImage, which is drawn as an image instead of a statusicon
  71. width: UM.Theme.getSize("icon_indicator").width + 2 * UM.Theme.getSize("default_lining").width
  72. height: width
  73. status:
  74. {
  75. if (valueError)
  76. {
  77. return UM.StatusIcon.Status.ERROR
  78. }
  79. if (valueWarning)
  80. {
  81. return UM.StatusIcon.Status.WARNING
  82. }
  83. return UM.StatusIcon.Status.NEUTRAL
  84. }
  85. }
  86. Column
  87. {
  88. opacity: model.enabled ? 1 : UM.Theme.getColor("extruder_disabled").a
  89. spacing: 0
  90. visible: width > 0
  91. anchors
  92. {
  93. left: extruderIcon.right
  94. leftMargin: UM.Theme.getSize("default_margin").width
  95. verticalCenter: parent.verticalCenter
  96. right: parent.right
  97. rightMargin: UM.Theme.getSize("default_margin").width
  98. }
  99. // Label for the brand of the material
  100. Label
  101. {
  102. id: materialBrandNameLabel
  103. text: model.material_brand + " " + model.material_name
  104. elide: Text.ElideRight
  105. font: UM.Theme.getFont("default")
  106. color: UM.Theme.getColor("text")
  107. renderType: Text.NativeRendering
  108. width: parent.width
  109. visible: !truncated
  110. }
  111. Label
  112. {
  113. id: materialNameLabel
  114. text: model.material_name
  115. elide: Text.ElideRight
  116. font: UM.Theme.getFont("default")
  117. color: UM.Theme.getColor("text")
  118. renderType: Text.NativeRendering
  119. width: parent.width
  120. visible: !materialBrandNameLabel.visible && !truncated
  121. }
  122. Label
  123. {
  124. id: materialTypeLabel
  125. text: model.material_type
  126. elide: Text.ElideRight
  127. font: UM.Theme.getFont("default")
  128. color: UM.Theme.getColor("text")
  129. renderType: Text.NativeRendering
  130. width: parent.width
  131. visible: !materialBrandNameLabel.visible && !materialNameLabel.visible
  132. }
  133. // Label that shows the name of the variant
  134. Label
  135. {
  136. id: variantLabel
  137. visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasVariants : false
  138. text: model.variant
  139. elide: Text.ElideRight
  140. font: UM.Theme.getFont("default_bold")
  141. color: UM.Theme.getColor("text")
  142. renderType: Text.NativeRendering
  143. Layout.preferredWidth: parent.width
  144. }
  145. }
  146. }
  147. }
  148. }
  149. // Placeholder text if there is a configuration to select but no materials (so we can't show the materials per extruder).
  150. Label
  151. {
  152. text: catalog.i18nc("@label", "Select configuration")
  153. elide: Text.ElideRight
  154. font: UM.Theme.getFont("medium")
  155. color: UM.Theme.getColor("text")
  156. renderType: Text.NativeRendering
  157. visible: Cura.MachineManager.activeMachine ? !Cura.MachineManager.activeMachine.hasMaterials && (Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasVariantBuildplates) : false
  158. anchors
  159. {
  160. left: parent.left
  161. leftMargin: UM.Theme.getSize("default_margin").width
  162. verticalCenter: parent.verticalCenter
  163. }
  164. }
  165. }
  166. contentItem: Column
  167. {
  168. id: popupItem
  169. width: UM.Theme.getSize("configuration_selector").width
  170. height: implicitHeight // Required because ExpandableComponent will try to use this to determine the size of the background of the pop-up.
  171. padding: UM.Theme.getSize("default_margin").height
  172. spacing: UM.Theme.getSize("default_margin").height
  173. property bool is_connected: false // If current machine is connected to a printer. Only evaluated upon making popup visible.
  174. property int configuration_method: ConfigurationMenu.ConfigurationMethod.Custom // Type of configuration being used. Only evaluated upon making popup visible.
  175. property int manual_selected_method: -1 // It stores the configuration method selected by the user. By default the selected method is
  176. onVisibleChanged:
  177. {
  178. is_connected = Cura.MachineManager.activeMachine.hasRemoteConnection && Cura.MachineManager.printerConnected && Cura.MachineManager.printerOutputDevices[0].uniqueConfigurations.length > 0 //Re-evaluate.
  179. // 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
  180. // or the previous state is selected
  181. configuration_method = is_connected ? (manual_selected_method == -1 ? ConfigurationMenu.ConfigurationMethod.Auto : manual_selected_method) : ConfigurationMenu.ConfigurationMethod.Custom
  182. }
  183. Item
  184. {
  185. width: parent.width - 2 * parent.padding
  186. height:
  187. {
  188. var height = 0
  189. if (autoConfiguration.visible)
  190. {
  191. height += autoConfiguration.height
  192. }
  193. if (customConfiguration.visible)
  194. {
  195. height += customConfiguration.height
  196. }
  197. return height
  198. }
  199. AutoConfiguration
  200. {
  201. id: autoConfiguration
  202. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  203. }
  204. CustomConfiguration
  205. {
  206. id: customConfiguration
  207. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  208. }
  209. }
  210. Rectangle
  211. {
  212. id: separator
  213. visible: buttonBar.visible
  214. x: -parent.padding
  215. width: parent.width
  216. height: UM.Theme.getSize("default_lining").height
  217. color: UM.Theme.getColor("lining")
  218. }
  219. //Allow switching between custom and auto.
  220. Item
  221. {
  222. id: buttonBar
  223. visible: popupItem.is_connected //Switching only makes sense if the "auto" part is possible.
  224. width: parent.width - 2 * parent.padding
  225. height: childrenRect.height
  226. Cura.SecondaryButton
  227. {
  228. id: goToCustom
  229. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  230. text: catalog.i18nc("@label", "Custom")
  231. anchors.right: parent.right
  232. iconSource: UM.Theme.getIcon("ChevronSingleRight")
  233. isIconOnRightSide: true
  234. onClicked:
  235. {
  236. popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Custom
  237. popupItem.manual_selected_method = popupItem.configuration_method
  238. }
  239. }
  240. Cura.SecondaryButton
  241. {
  242. id: goToAuto
  243. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  244. text: catalog.i18nc("@label", "Configurations")
  245. iconSource: UM.Theme.getIcon("ChevronSingleLeft")
  246. onClicked:
  247. {
  248. popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Auto
  249. popupItem.manual_selected_method = popupItem.configuration_method
  250. }
  251. }
  252. }
  253. }
  254. Connections
  255. {
  256. target: Cura.MachineManager
  257. function onGlobalContainerChanged() { popupItem.manual_selected_method = -1 } // When switching printers, reset the value of the manual selected method
  258. }
  259. }