ConfigurationItem.qml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.2 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. 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. font: UM.Theme.getFont("default")
  126. color: UM.Theme.getColor("text")
  127. verticalAlignment: Text.AlignVCenter
  128. linkColor: UM.Theme.getColor("text_link")
  129. onLinkActivated:
  130. {
  131. Cura.Actions.browsePackages.trigger()
  132. }
  133. }
  134. MouseArea
  135. {
  136. anchors.fill: parent
  137. cursorShape: unknownMaterialMessage.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
  138. acceptedButtons: Qt.NoButton
  139. }
  140. }
  141. }
  142. //Buildplate row separator
  143. Rectangle
  144. {
  145. id: separator
  146. visible: buildplateInformation.visible
  147. anchors
  148. {
  149. left: parent.left
  150. leftMargin: UM.Theme.getSize("wide_margin").width
  151. right: parent.right
  152. rightMargin: UM.Theme.getSize("wide_margin").width
  153. }
  154. height: visible ? Math.round(UM.Theme.getSize("default_lining").height / 2) : 0
  155. color: UM.Theme.getColor("lining")
  156. }
  157. Item
  158. {
  159. id: buildplateInformation
  160. anchors
  161. {
  162. left: parent.left
  163. leftMargin: UM.Theme.getSize("wide_margin").width
  164. right: parent.right
  165. rightMargin: UM.Theme.getSize("wide_margin").width
  166. }
  167. height: childrenRect.height
  168. 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).
  169. // Show the type of buildplate. The first letter is capitalized
  170. Cura.IconWithText
  171. {
  172. id: buildplateLabel
  173. source: UM.Theme.getIcon("buildplate")
  174. text:
  175. {
  176. if (configuration === null)
  177. {
  178. return ""
  179. }
  180. return configuration.buildplateConfiguration.charAt(0).toUpperCase() + configuration.buildplateConfiguration.substr(1)
  181. }
  182. anchors.left: parent.left
  183. }
  184. }
  185. }
  186. Connections
  187. {
  188. target: Cura.MachineManager
  189. onCurrentConfigurationChanged:
  190. {
  191. configurationItem.checked = Cura.MachineManager.matchesConfiguration(configuration)
  192. }
  193. }
  194. Component.onCompleted:
  195. {
  196. configurationItem.checked = Cura.MachineManager.matchesConfiguration(configuration)
  197. }
  198. onClicked:
  199. {
  200. if(isValidMaterial)
  201. {
  202. toggleContent()
  203. Cura.MachineManager.applyRemoteConfiguration(configuration)
  204. }
  205. }
  206. }