ConfigurationItem.qml 7.7 KB

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