ConfigurationMenu.qml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.2 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.fill: parent
  35. visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasMaterials : false
  36. Repeater
  37. {
  38. model: extrudersModel
  39. delegate: Item
  40. {
  41. Layout.preferredWidth: Math.round(parent.width / extrudersModel.count)
  42. Layout.fillHeight: true
  43. // Extruder icon. Shows extruder index and has the same color as the active material.
  44. Cura.ExtruderIcon
  45. {
  46. id: extruderIcon
  47. materialColor: model.color
  48. extruderEnabled: model.enabled
  49. height: parent.height
  50. width: height
  51. }
  52. // Label for the brand of the material
  53. Label
  54. {
  55. id: typeAndBrandNameLabel
  56. text: model.material_brand + " " + model.material
  57. elide: Text.ElideRight
  58. font: UM.Theme.getFont("default")
  59. color: UM.Theme.getColor("text")
  60. renderType: Text.NativeRendering
  61. anchors
  62. {
  63. top: extruderIcon.top
  64. left: extruderIcon.right
  65. leftMargin: UM.Theme.getSize("default_margin").width
  66. right: parent.right
  67. rightMargin: UM.Theme.getSize("default_margin").width
  68. }
  69. }
  70. // Label that shows the name of the variant
  71. Label
  72. {
  73. id: variantLabel
  74. visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasVariants : false
  75. text: model.variant
  76. elide: Text.ElideRight
  77. font: UM.Theme.getFont("default_bold")
  78. color: UM.Theme.getColor("text")
  79. renderType: Text.NativeRendering
  80. anchors
  81. {
  82. left: extruderIcon.right
  83. leftMargin: UM.Theme.getSize("default_margin").width
  84. top: typeAndBrandNameLabel.bottom
  85. right: parent.right
  86. rightMargin: UM.Theme.getSize("default_margin").width
  87. }
  88. }
  89. }
  90. }
  91. }
  92. // Placeholder text if there is a configuration to select but no materials (so we can't show the materials per extruder).
  93. Label
  94. {
  95. text: catalog.i18nc("@label", "Select configuration")
  96. elide: Text.ElideRight
  97. font: UM.Theme.getFont("medium")
  98. color: UM.Theme.getColor("text")
  99. renderType: Text.NativeRendering
  100. visible: Cura.MachineManager.activeMachine ? !Cura.MachineManager.activeMachine.hasMaterials && (Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasVariantBuildplates) : false
  101. anchors
  102. {
  103. left: parent.left
  104. leftMargin: UM.Theme.getSize("default_margin").width
  105. verticalCenter: parent.verticalCenter
  106. }
  107. }
  108. }
  109. contentItem: Column
  110. {
  111. id: popupItem
  112. width: UM.Theme.getSize("configuration_selector").width
  113. height: implicitHeight // Required because ExpandableComponent will try to use this to determine the size of the background of the pop-up.
  114. padding: UM.Theme.getSize("default_margin").height
  115. spacing: UM.Theme.getSize("default_margin").height
  116. property bool is_connected: false // If current machine is connected to a printer. Only evaluated upon making popup visible.
  117. property int configuration_method: ConfigurationMenu.ConfigurationMethod.Custom // Type of configuration being used. Only evaluated upon making popup visible.
  118. property int manual_selected_method: -1 // It stores the configuration method selected by the user. By default the selected method is
  119. onVisibleChanged:
  120. {
  121. is_connected = Cura.MachineManager.activeMachine.hasRemoteConnection && Cura.MachineManager.printerConnected && Cura.MachineManager.printerOutputDevices[0].uniqueConfigurations.length > 0 //Re-evaluate.
  122. // 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
  123. // or the previous state is selected
  124. configuration_method = is_connected ? (manual_selected_method == -1 ? ConfigurationMenu.ConfigurationMethod.Auto : manual_selected_method) : ConfigurationMenu.ConfigurationMethod.Custom
  125. }
  126. Item
  127. {
  128. width: parent.width - 2 * parent.padding
  129. height:
  130. {
  131. var height = 0
  132. if (autoConfiguration.visible)
  133. {
  134. height += autoConfiguration.height
  135. }
  136. if (customConfiguration.visible)
  137. {
  138. height += customConfiguration.height
  139. }
  140. return height
  141. }
  142. AutoConfiguration
  143. {
  144. id: autoConfiguration
  145. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  146. }
  147. CustomConfiguration
  148. {
  149. id: customConfiguration
  150. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  151. }
  152. }
  153. Rectangle
  154. {
  155. id: separator
  156. visible: buttonBar.visible
  157. x: -parent.padding
  158. width: parent.width
  159. height: UM.Theme.getSize("default_lining").height
  160. color: UM.Theme.getColor("lining")
  161. }
  162. //Allow switching between custom and auto.
  163. Item
  164. {
  165. id: buttonBar
  166. visible: popupItem.is_connected //Switching only makes sense if the "auto" part is possible.
  167. width: parent.width - 2 * parent.padding
  168. height: childrenRect.height
  169. Cura.SecondaryButton
  170. {
  171. id: goToCustom
  172. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  173. text: catalog.i18nc("@label", "Custom")
  174. anchors.right: parent.right
  175. iconSource: UM.Theme.getIcon("arrow_right")
  176. isIconOnRightSide: true
  177. onClicked:
  178. {
  179. popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Custom
  180. popupItem.manual_selected_method = popupItem.configuration_method
  181. }
  182. }
  183. Cura.SecondaryButton
  184. {
  185. id: goToAuto
  186. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  187. text: catalog.i18nc("@label", "Configurations")
  188. iconSource: UM.Theme.getIcon("arrow_left")
  189. onClicked:
  190. {
  191. popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Auto
  192. popupItem.manual_selected_method = popupItem.configuration_method
  193. }
  194. }
  195. }
  196. }
  197. Connections
  198. {
  199. target: Cura.MachineManager
  200. onGlobalContainerChanged: popupItem.manual_selected_method = -1 // When switching printers, reset the value of the manual selected method
  201. }
  202. }