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