ConfigurationMenu.qml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. anchors
  62. {
  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 material
  70. Label
  71. {
  72. text: model.material
  73. elide: Text.ElideRight
  74. font: UM.Theme.getFont("default")
  75. color: UM.Theme.getColor("text")
  76. anchors
  77. {
  78. left: extruderIcon.right
  79. leftMargin: UM.Theme.getSize("default_margin").width
  80. right: parent.right
  81. rightMargin: UM.Theme.getSize("default_margin").width
  82. top: brandNameLabel.bottom
  83. }
  84. }
  85. }
  86. }
  87. }
  88. popupItem: Column
  89. {
  90. id: popupItem
  91. width: base.width - 2 * UM.Theme.getSize("default_margin").width
  92. height: implicitHeight //Required because ExpandableComponent will try to use this to determine the size of the background of the pop-up.
  93. spacing: UM.Theme.getSize("default_margin").height
  94. property bool is_connected: false //If current machine is connected to a printer. Only evaluated upon making popup visible.
  95. onVisibleChanged:
  96. {
  97. is_connected = Cura.MachineManager.activeMachineNetworkKey !== "" && Cura.MachineManager.printerConnected //Re-evaluate.
  98. }
  99. 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.
  100. Item
  101. {
  102. width: parent.width
  103. height: childrenRect.height
  104. AutoConfiguration
  105. {
  106. id: autoConfiguration
  107. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.AUTO
  108. }
  109. CustomConfiguration
  110. {
  111. id: customConfiguration
  112. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.CUSTOM
  113. }
  114. }
  115. Rectangle
  116. {
  117. id: separator
  118. visible: buttonBar.visible
  119. width: parent.width
  120. height: UM.Theme.getSize("default_lining").height
  121. color: UM.Theme.getColor("lining")
  122. }
  123. //Allow switching between custom and auto.
  124. Item
  125. {
  126. id: buttonBar
  127. visible: popupItem.is_connected //Switching only makes sense if the "auto" part is possible.
  128. width: parent.width
  129. height: childrenRect.height
  130. Cura.SecondaryButton
  131. {
  132. id: goToCustom
  133. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.AUTO
  134. text: catalog.i18nc("@label", "Custom")
  135. anchors.right: parent.right
  136. iconSource: UM.Theme.getIcon("arrow_right")
  137. isIconOnRightSide: true
  138. onClicked: popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.CUSTOM
  139. }
  140. Cura.SecondaryButton
  141. {
  142. id: goToAuto
  143. visible: popupItem.configuration_method == ConfigurationMenu.ConfigurationMethod.CUSTOM
  144. text: catalog.i18nc("@label", "Configurations")
  145. iconSource: UM.Theme.getIcon("arrow_left")
  146. onClicked: popupItem.configuration_method = ConfigurationMenu.ConfigurationMethod.AUTO
  147. }
  148. }
  149. }
  150. }