ConfigurationItem.qml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. Button
  8. {
  9. id: configurationItem
  10. property var configuration: null
  11. hoverEnabled: isValidMaterial
  12. property bool isValidMaterial:
  13. {
  14. if (configuration === null)
  15. {
  16. return false
  17. }
  18. var extruderConfigurations = configuration.extruderConfigurations
  19. for (var index in extruderConfigurations)
  20. {
  21. var name = extruderConfigurations[index].material ? extruderConfigurations[index].material.name : ""
  22. if (name == "" || name == "Unknown")
  23. {
  24. return false
  25. }
  26. }
  27. return true
  28. }
  29. background: Rectangle
  30. {
  31. color: parent.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  32. border.color: parent.checked ? UM.Theme.getColor("primary") : UM.Theme.getColor("lining")
  33. border.width: UM.Theme.getSize("default_lining").width
  34. radius: UM.Theme.getSize("default_radius").width
  35. }
  36. contentItem: Column
  37. {
  38. id: contentColumn
  39. width: parent.width
  40. padding: UM.Theme.getSize("default_margin").width
  41. spacing: UM.Theme.getSize("narrow_margin").height
  42. Row
  43. {
  44. id: extruderRow
  45. anchors
  46. {
  47. left: parent.left
  48. leftMargin: UM.Theme.getSize("default_margin").width
  49. right: parent.right
  50. rightMargin: UM.Theme.getSize("wide_margin").width
  51. }
  52. height: childrenRect.height
  53. spacing: UM.Theme.getSize("default_margin").width
  54. Repeater
  55. {
  56. id: repeater
  57. model: configuration !== null ? configuration.extruderConfigurations: null
  58. width: parent.width
  59. delegate: PrintCoreConfiguration
  60. {
  61. width: Math.round(parent.width / (configuration !== null ? configuration.extruderConfigurations.length : 1))
  62. printCoreConfiguration: modelData
  63. visible: configurationItem.isValidMaterial
  64. }
  65. }
  66. // Unknown material
  67. Item
  68. {
  69. id: unknownMaterial
  70. height: unknownMaterialMessage.height + UM.Theme.getSize("thin_margin").width / 2
  71. width: parent.width
  72. anchors.top: parent.top
  73. anchors.topMargin: UM.Theme.getSize("thin_margin").width / 2
  74. visible: !configurationItem.isValidMaterial
  75. UM.RecolorImage
  76. {
  77. id: icon
  78. anchors.verticalCenter: unknownMaterialMessage.verticalCenter
  79. source: UM.Theme.getIcon("Warning")
  80. color: UM.Theme.getColor("warning")
  81. width: UM.Theme.getSize("section_icon").width
  82. height: width
  83. }
  84. UM.Label
  85. {
  86. id: unknownMaterialMessage
  87. text:
  88. {
  89. if (configuration === null)
  90. {
  91. return ""
  92. }
  93. var extruderConfigurations = configuration.extruderConfigurations
  94. var unknownMaterials = []
  95. for (var index in extruderConfigurations)
  96. {
  97. var name = extruderConfigurations[index].material ? extruderConfigurations[index].material.name : ""
  98. if (name == "" || name == "Unknown")
  99. {
  100. var materialType = extruderConfigurations[index].material.type
  101. if (extruderConfigurations[index].material.type == "")
  102. {
  103. materialType = "Unknown"
  104. }
  105. var brand = extruderConfigurations[index].material.brand
  106. if (brand == "")
  107. {
  108. brand = "Unknown"
  109. }
  110. name = materialType + " (" + brand + ")"
  111. unknownMaterials.push(name)
  112. }
  113. }
  114. unknownMaterials = "<b>" + unknownMaterials + "</b>"
  115. var draftResult = catalog.i18nc("@label", "This configuration is not available because %1 is not recognized. Please visit %2 to download the correct material profile.");
  116. var result = draftResult.arg(unknownMaterials).arg("<a href=' '>" + catalog.i18nc("@label","Marketplace") + "</a> ")
  117. return result
  118. }
  119. width: extruderRow.width
  120. anchors.left: icon.right
  121. anchors.right: unknownMaterial.right
  122. anchors.leftMargin: UM.Theme.getSize("wide_margin").height
  123. anchors.top: unknownMaterial.top
  124. wrapMode: Text.WordWrap
  125. onLinkActivated:
  126. {
  127. Cura.Actions.browsePackages.trigger()
  128. }
  129. }
  130. MouseArea
  131. {
  132. anchors.fill: parent
  133. cursorShape: unknownMaterialMessage.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
  134. acceptedButtons: Qt.NoButton
  135. }
  136. }
  137. }
  138. //Buildplate row separator
  139. Rectangle
  140. {
  141. id: separator
  142. visible: buildplateInformation.visible
  143. anchors
  144. {
  145. left: parent.left
  146. leftMargin: UM.Theme.getSize("wide_margin").width
  147. right: parent.right
  148. rightMargin: UM.Theme.getSize("wide_margin").width
  149. }
  150. height: visible ? Math.round(UM.Theme.getSize("default_lining").height / 2) : 0
  151. color: UM.Theme.getColor("lining")
  152. }
  153. Item
  154. {
  155. id: buildplateInformation
  156. anchors
  157. {
  158. left: parent.left
  159. leftMargin: UM.Theme.getSize("wide_margin").width
  160. right: parent.right
  161. rightMargin: UM.Theme.getSize("wide_margin").width
  162. }
  163. height: childrenRect.height
  164. visible: configuration !== null && configuration.buildplateConfiguration != "" && false //Buildplate is disabled as long as we have no printers that properly support buildplate swapping (so we can't test).
  165. // Show the type of buildplate. The first letter is capitalized
  166. Cura.IconWithText
  167. {
  168. id: buildplateLabel
  169. source: UM.Theme.getIcon("Buildplate")
  170. text:
  171. {
  172. if (configuration === null)
  173. {
  174. return ""
  175. }
  176. return configuration.buildplateConfiguration.charAt(0).toUpperCase() + configuration.buildplateConfiguration.substr(1)
  177. }
  178. anchors.left: parent.left
  179. }
  180. }
  181. }
  182. Connections
  183. {
  184. target: Cura.MachineManager
  185. function onCurrentConfigurationChanged()
  186. {
  187. configurationItem.checked = Cura.MachineManager.matchesConfiguration(configuration)
  188. }
  189. }
  190. Component.onCompleted:
  191. {
  192. configurationItem.checked = Cura.MachineManager.matchesConfiguration(configuration)
  193. }
  194. onClicked:
  195. {
  196. if(isValidMaterial)
  197. {
  198. toggleContent()
  199. Cura.MachineManager.applyRemoteConfiguration(configuration)
  200. }
  201. }
  202. }