ConfigurationMenu.qml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. enabled: Cura.MachineManager.hasMaterials || Cura.MachineManager.hasVariants || Cura.MachineManager.hasVariantBuildplates; //Only let it drop down if there is any configuration that you could change.
  30. headerItem: Item
  31. {
  32. // Horizontal list that shows the extruders and their materials
  33. ListView
  34. {
  35. id: extrudersList
  36. orientation: ListView.Horizontal
  37. anchors.fill: parent
  38. model: extrudersModel
  39. visible: Cura.MachineManager.hasMaterials
  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. //Placeholder text if there is a configuration to select but no materials (so we can't show the materials per extruder).
  90. Label
  91. {
  92. text: catalog.i18nc("@label", "Select configuration")
  93. elide: Text.ElideRight
  94. font: UM.Theme.getFont("default")
  95. color: UM.Theme.getColor("text")
  96. renderType: Text.NativeRendering
  97. visible: !Cura.MachineManager.hasMaterials && (Cura.MachineManager.hasVariants || Cura.MachineManager.hasVariantBuildplates)
  98. anchors
  99. {
  100. left: parent.left
  101. leftMargin: UM.Theme.getSize("default_margin").width
  102. verticalCenter: parent.verticalCenter
  103. }
  104. }
  105. }
  106. contentItem: Column
  107. {
  108. id: popupItem
  109. width: base.width - 2 * UM.Theme.getSize("default_margin").width
  110. height: implicitHeight //Required because ExpandableComponent will try to use this to determine the size of the background of the pop-up.
  111. spacing: UM.Theme.getSize("default_margin").height
  112. property bool is_connected: false //If current machine is connected to a printer. Only evaluated upon making popup visible.
  113. onVisibleChanged:
  114. {
  115. is_connected = Cura.MachineManager.activeMachineNetworkKey !== "" && Cura.MachineManager.printerConnected //Re-evaluate.
  116. }
  117. 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.
  118. Item
  119. {
  120. width: parent.width
  121. height:
  122. {
  123. var height = 0;
  124. if(autoConfiguration.visible)
  125. {
  126. height += autoConfiguration.height;
  127. }
  128. if(customConfiguration.visible)
  129. {
  130. height += customConfiguration.height;
  131. }
  132. return height;
  133. }
  134. AutoConfiguration
  135. {
  136. id: autoConfiguration
  137. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  138. }
  139. CustomConfiguration
  140. {
  141. id: customConfiguration
  142. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  143. }
  144. }
  145. Rectangle
  146. {
  147. id: separator
  148. visible: buttonBar.visible
  149. x: -contentPadding
  150. width: base.width
  151. height: UM.Theme.getSize("default_lining").height
  152. color: UM.Theme.getColor("lining")
  153. }
  154. //Allow switching between custom and auto.
  155. Item
  156. {
  157. id: buttonBar
  158. visible: popupItem.is_connected //Switching only makes sense if the "auto" part is possible.
  159. width: parent.width
  160. height: childrenRect.height
  161. Cura.SecondaryButton
  162. {
  163. id: goToCustom
  164. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Auto
  165. text: catalog.i18nc("@label", "Custom")
  166. anchors.right: parent.right
  167. iconSource: UM.Theme.getIcon("arrow_right")
  168. isIconOnRightSide: true
  169. onClicked: popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Custom
  170. }
  171. Cura.SecondaryButton
  172. {
  173. id: goToAuto
  174. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.Custom
  175. text: catalog.i18nc("@label", "Configurations")
  176. iconSource: UM.Theme.getIcon("arrow_left")
  177. onClicked: popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.Auto
  178. }
  179. }
  180. }
  181. }