ConfigurationMenu.qml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.ExpandablePopup
  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. contentPadding: UM.Theme.getSize("default_lining").width
  30. enabled: Cura.MachineManager.hasMaterials || Cura.MachineManager.hasVariants || Cura.MachineManager.hasVariantBuildplates; //Only let it drop down if there is any configuration that you could change.
  31. headerItem: Item
  32. {
  33. // Horizontal list that shows the extruders and their materials
  34. ListView
  35. {
  36. id: extrudersList
  37. orientation: ListView.Horizontal
  38. anchors.fill: parent
  39. model: extrudersModel
  40. visible: Cura.MachineManager.hasMaterials
  41. delegate: Item
  42. {
  43. height: parent.height
  44. width: Math.round(ListView.view.width / extrudersModel.count)
  45. // Extruder icon. Shows extruder index and has the same color as the active material.
  46. Cura.ExtruderIcon
  47. {
  48. id: extruderIcon
  49. materialColor: model.color
  50. extruderEnabled: model.enabled
  51. height: parent.height
  52. width: height
  53. }
  54. // Label for the brand of the material
  55. Label
  56. {
  57. id: brandNameLabel
  58. text: model.material_brand
  59. elide: Text.ElideRight
  60. font: UM.Theme.getFont("default")
  61. color: UM.Theme.getColor("text_inactive")
  62. renderType: Text.NativeRendering
  63. anchors
  64. {
  65. left: extruderIcon.right
  66. leftMargin: UM.Theme.getSize("default_margin").width
  67. right: parent.right
  68. rightMargin: UM.Theme.getSize("default_margin").width
  69. }
  70. }
  71. // Label that shows the name of the material
  72. Label
  73. {
  74. text: model.material
  75. elide: Text.ElideRight
  76. font: UM.Theme.getFont("default")
  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. right: parent.right
  84. rightMargin: UM.Theme.getSize("default_margin").width
  85. top: brandNameLabel.bottom
  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("default")
  96. color: UM.Theme.getColor("text")
  97. renderType: Text.NativeRendering
  98. visible: !Cura.MachineManager.hasMaterials && (Cura.MachineManager.hasVariants || Cura.MachineManager.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. onVisibleChanged:
  117. {
  118. is_connected = Cura.MachineManager.activeMachineNetworkKey !== "" && Cura.MachineManager.printerConnected // Re-evaluate.
  119. configuration_method = is_connected ? ConfigurationMenu.ConfigurationMethod.Auto : ConfigurationMenu.ConfigurationMethod.Custom // Auto if connected to a printer at start-up, or Custom if not.
  120. }
  121. Item
  122. {
  123. width: parent.width - 2 * parent.padding
  124. height:
  125. {
  126. var height = 0
  127. if (autoConfiguration.visible)
  128. {
  129. height += autoConfiguration.height
  130. }
  131. if (customConfiguration.visible)
  132. {
  133. height += customConfiguration.height
  134. }
  135. return height
  136. }
  137. AutoConfiguration
  138. {
  139. id: autoConfiguration
  140. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  141. }
  142. CustomConfiguration
  143. {
  144. id: customConfiguration
  145. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  146. }
  147. }
  148. Rectangle
  149. {
  150. id: separator
  151. visible: buttonBar.visible
  152. x: -parent.padding
  153. width: parent.width
  154. height: UM.Theme.getSize("default_lining").height
  155. color: UM.Theme.getColor("lining")
  156. }
  157. //Allow switching between custom and auto.
  158. Item
  159. {
  160. id: buttonBar
  161. visible: popupItem.is_connected //Switching only makes sense if the "auto" part is possible.
  162. width: parent.width - 2 * parent.padding
  163. height: childrenRect.height
  164. Cura.SecondaryButton
  165. {
  166. id: goToCustom
  167. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  168. text: catalog.i18nc("@label", "Custom")
  169. anchors.right: parent.right
  170. iconSource: UM.Theme.getIcon("arrow_right")
  171. isIconOnRightSide: true
  172. onClicked: popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Custom
  173. }
  174. Cura.SecondaryButton
  175. {
  176. id: goToAuto
  177. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  178. text: catalog.i18nc("@label", "Configurations")
  179. iconSource: UM.Theme.getIcon("arrow_left")
  180. onClicked: popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Auto
  181. }
  182. }
  183. }
  184. }