ConfigurationMenu.qml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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.Controls 2.0
  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.ExpandableComponent
  13. {
  14. id: base
  15. Cura.ExtrudersModel
  16. {
  17. id: extrudersModel
  18. }
  19. UM.I18nCatalog
  20. {
  21. id: catalog
  22. name: "cura"
  23. }
  24. enum ConfigurationMethod
  25. {
  26. Auto,
  27. Custom
  28. }
  29. iconSource: expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
  30. headerItem: Item
  31. {
  32. // Horizontal list that shows the extruders
  33. ListView
  34. {
  35. id: extrudersList
  36. orientation: ListView.Horizontal
  37. anchors.fill: parent
  38. model: extrudersModel
  39. visible: base.enabled
  40. delegate: Item
  41. {
  42. height: parent.height
  43. width: Math.round(ListView.view.width / extrudersModel.count)
  44. // Extruder icon. Shows extruder index and has the same color as the active material.
  45. Cura.ExtruderIcon
  46. {
  47. id: extruderIcon
  48. materialColor: model.color
  49. extruderEnabled: model.enabled
  50. height: parent.height
  51. width: height
  52. }
  53. // Label for the brand of the material
  54. Label
  55. {
  56. id: brandNameLabel
  57. text: model.material_brand
  58. elide: Text.ElideRight
  59. font: UM.Theme.getFont("default")
  60. color: UM.Theme.getColor("text_inactive")
  61. renderType: Text.NativeRendering
  62. anchors
  63. {
  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 material
  71. Label
  72. {
  73. text: model.material
  74. elide: Text.ElideRight
  75. font: UM.Theme.getFont("default")
  76. color: UM.Theme.getColor("text")
  77. renderType: Text.NativeRendering
  78. anchors
  79. {
  80. left: extruderIcon.right
  81. leftMargin: UM.Theme.getSize("default_margin").width
  82. right: parent.right
  83. rightMargin: UM.Theme.getSize("default_margin").width
  84. top: brandNameLabel.bottom
  85. }
  86. }
  87. }
  88. }
  89. }
  90. //Disable the menu if there are no materials, variants or build plates to change.
  91. function updateEnabled()
  92. {
  93. var active_definition_id = Cura.MachineManager.activeMachine.definition.id;
  94. var has_materials = Cura.ContainerManager.getContainerMetaDataEntry(active_definition_id, "has_materials");
  95. var has_variants = Cura.ContainerManager.getContainerMetaDataEntry(active_definition_id, "has_variants");
  96. var has_buildplates = Cura.ContainerManager.getContainerMetaDataEntry(active_definition_id, "has_variant_buildplates");
  97. base.enabled = has_materials || has_variants || has_buildplates; //Only let it drop down if there is any configuration that you could change.
  98. }
  99. Connections
  100. {
  101. target: Cura.MachineManager
  102. onGlobalContainerChanged: base.updateEnabled();
  103. }
  104. Component.onCompleted: updateEnabled();
  105. popupItem: Column
  106. {
  107. id: popupItem
  108. width: base.width - 2 * UM.Theme.getSize("default_margin").width
  109. height: implicitHeight //Required because ExpandableComponent will try to use this to determine the size of the background of the pop-up.
  110. spacing: UM.Theme.getSize("default_margin").height
  111. property bool is_connected: false //If current machine is connected to a printer. Only evaluated upon making popup visible.
  112. onVisibleChanged:
  113. {
  114. is_connected = Cura.MachineManager.activeMachineNetworkKey !== "" && Cura.MachineManager.printerConnected //Re-evaluate.
  115. }
  116. property int configuration_method: is_connected ? ConfigurationMenu.ConfigurationMethod.Auto : ConfigurationMenu.ConfigurationMethod.Custom //Auto if connected to a printer at start-up, or Custom if not.
  117. Item
  118. {
  119. width: parent.width
  120. height:
  121. {
  122. var height = 0;
  123. if(autoConfiguration.visible)
  124. {
  125. height += autoConfiguration.height;
  126. }
  127. if(customConfiguration.visible)
  128. {
  129. height += customConfiguration.height;
  130. }
  131. return height;
  132. }
  133. AutoConfiguration
  134. {
  135. id: autoConfiguration
  136. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  137. }
  138. CustomConfiguration
  139. {
  140. id: customConfiguration
  141. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  142. }
  143. }
  144. Rectangle
  145. {
  146. id: separator
  147. visible: buttonBar.visible
  148. x: -popupPadding
  149. width: base.width
  150. height: UM.Theme.getSize("default_lining").height
  151. color: UM.Theme.getColor("lining")
  152. }
  153. //Allow switching between custom and auto.
  154. Item
  155. {
  156. id: buttonBar
  157. visible: popupItem.is_connected //Switching only makes sense if the "auto" part is possible.
  158. width: parent.width
  159. height: childrenRect.height
  160. Cura.SecondaryButton
  161. {
  162. id: goToCustom
  163. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  164. text: catalog.i18nc("@label", "Custom")
  165. anchors.right: parent.right
  166. iconSource: UM.Theme.getIcon("arrow_right")
  167. isIconOnRightSide: true
  168. onClicked: popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Custom
  169. }
  170. Cura.SecondaryButton
  171. {
  172. id: goToAuto
  173. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  174. text: catalog.i18nc("@label", "Configurations")
  175. iconSource: UM.Theme.getIcon("arrow_left")
  176. onClicked: popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Auto
  177. }
  178. }
  179. }
  180. }