CustomConfiguration.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.6
  4. import QtQuick.Controls 2.0
  5. import QtQuick.Controls 1.1 as OldControls
  6. import Cura 1.0 as Cura
  7. import UM 1.3 as UM
  8. Item
  9. {
  10. UM.I18nCatalog
  11. {
  12. id: catalog
  13. name: "cura"
  14. }
  15. width: parent.width
  16. height: childrenRect.height
  17. Label
  18. {
  19. id: header
  20. text: catalog.i18nc("@header", "Custom")
  21. font: UM.Theme.getFont("medium")
  22. color: UM.Theme.getColor("small_button_text")
  23. height: contentHeight
  24. renderType: Text.NativeRendering
  25. anchors
  26. {
  27. top: parent.top
  28. left: parent.left
  29. right: parent.right
  30. }
  31. }
  32. //Printer type selector.
  33. Item
  34. {
  35. id: printerTypeSelectorRow
  36. visible:
  37. {
  38. return Cura.MachineManager.printerOutputDevices.length >= 1 //If connected...
  39. && Cura.MachineManager.printerOutputDevices[0].connectedPrintersTypeCount != null //...and we have configuration information...
  40. && Cura.MachineManager.printerOutputDevices[0].connectedPrintersTypeCount.length > 1; //...and there is more than one type of printer in the configuration list.
  41. }
  42. height: visible ? childrenRect.height : 0
  43. anchors
  44. {
  45. left: parent.left
  46. right: parent.right
  47. top: header.bottom
  48. topMargin: visible ? UM.Theme.getSize("default_margin").height : 0
  49. }
  50. Label
  51. {
  52. text: catalog.i18nc("@label", "Printer")
  53. width: Math.round(parent.width * 0.3) - UM.Theme.getSize("default_margin").width
  54. height: contentHeight
  55. font: UM.Theme.getFont("default")
  56. color: UM.Theme.getColor("text")
  57. anchors.verticalCenter: printerTypeSelector.verticalCenter
  58. anchors.left: parent.left
  59. }
  60. OldControls.ToolButton
  61. {
  62. id: printerTypeSelector
  63. text: Cura.MachineManager.activeMachineDefinitionName
  64. tooltip: Cura.MachineManager.activeMachineDefinitionName
  65. height: UM.Theme.getSize("print_setup_big_item").height
  66. width: Math.round(parent.width * 0.7) + UM.Theme.getSize("default_margin").width
  67. anchors.right: parent.right
  68. style: UM.Theme.styles.print_setup_header_button
  69. menu: Cura.PrinterTypeMenu { }
  70. }
  71. }
  72. UM.TabRow
  73. {
  74. id: tabBar
  75. anchors.top: printerTypeSelectorRow.bottom
  76. anchors.topMargin: UM.Theme.getSize("default_margin").height
  77. visible: extrudersModel.count > 1
  78. Repeater
  79. {
  80. id: repeater
  81. model: extrudersModel
  82. delegate: UM.TabRowButton
  83. {
  84. contentItem: Item
  85. {
  86. Cura.ExtruderIcon
  87. {
  88. anchors.horizontalCenter: parent.horizontalCenter
  89. materialColor: model.color
  90. extruderEnabled: model.enabled
  91. width: parent.height
  92. height: parent.height
  93. }
  94. }
  95. onClicked:
  96. {
  97. Cura.ExtruderManager.setActiveExtruderIndex(tabBar.currentIndex)
  98. }
  99. }
  100. }
  101. //When active extruder changes for some other reason, switch tabs.
  102. //Don't directly link currentIndex to Cura.ExtruderManager.activeExtruderIndex!
  103. //This causes a segfault in Qt 5.11. Something with VisualItemModel removing index -1. We have to use setCurrentIndex instead.
  104. Connections
  105. {
  106. target: Cura.ExtruderManager
  107. onActiveExtruderChanged:
  108. {
  109. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex);
  110. }
  111. }
  112. // Can't use 'item: ...activeExtruderIndex' directly apparently, see also the comment on the previous block.
  113. onVisibleChanged:
  114. {
  115. if (tabBar.visible)
  116. {
  117. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex);
  118. }
  119. }
  120. //When the model of the extruders is rebuilt, the list of extruders is briefly emptied and rebuilt.
  121. //This causes the currentIndex of the tab to be in an invalid position which resets it to 0.
  122. //Therefore we need to change it back to what it was: The active extruder index.
  123. Connections
  124. {
  125. target: repeater.model
  126. onModelChanged:
  127. {
  128. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex)
  129. }
  130. }
  131. }
  132. Rectangle
  133. {
  134. width: parent.width
  135. height: childrenRect.height
  136. anchors.top: tabBar.bottom
  137. radius: tabBar.visible ? UM.Theme.getSize("default_radius").width : 0
  138. border.width: tabBar.visible ? UM.Theme.getSize("default_lining").width : 0
  139. border.color: UM.Theme.getColor("lining")
  140. color: UM.Theme.getColor("main_background")
  141. //Remove rounding and lining at the top.
  142. Rectangle
  143. {
  144. width: parent.width
  145. height: parent.radius
  146. anchors.top: parent.top
  147. color: UM.Theme.getColor("lining")
  148. visible: tabBar.visible
  149. Rectangle
  150. {
  151. anchors
  152. {
  153. left: parent.left
  154. leftMargin: parent.parent.border.width
  155. right: parent.right
  156. rightMargin: parent.parent.border.width
  157. top: parent.top
  158. }
  159. height: parent.parent.radius
  160. color: parent.parent.color
  161. }
  162. }
  163. Column
  164. {
  165. id: selectors
  166. padding: UM.Theme.getSize("default_margin").width
  167. spacing: UM.Theme.getSize("default_margin").height
  168. property var model: extrudersModel.items[tabBar.currentIndex]
  169. readonly property real paddedWidth: parent.width - padding * 2
  170. property real textWidth: Math.round(paddedWidth * 0.3)
  171. property real controlWidth:
  172. {
  173. if(instructionLink == "")
  174. {
  175. return paddedWidth - textWidth
  176. }
  177. else
  178. {
  179. return paddedWidth - textWidth - UM.Theme.getSize("print_setup_big_item").height * 0.5 - UM.Theme.getSize("default_margin").width
  180. }
  181. }
  182. property string instructionLink: Cura.ContainerManager.getContainerMetaDataEntry(Cura.MachineManager.activeStack.material.id, "instruction_link", "")
  183. Row
  184. {
  185. height: visible ? UM.Theme.getSize("setting_control").height : 0
  186. visible: extrudersModel.count > 1 // If there is only one extruder, there is no point to enable/disable that.
  187. Label
  188. {
  189. text: catalog.i18nc("@label", "Enabled")
  190. verticalAlignment: Text.AlignVCenter
  191. font: UM.Theme.getFont("default")
  192. color: UM.Theme.getColor("text")
  193. height: parent.height
  194. width: selectors.textWidth
  195. renderType: Text.NativeRendering
  196. }
  197. OldControls.CheckBox
  198. {
  199. checked: Cura.MachineManager.activeStack != null ? Cura.MachineManager.activeStack.isEnabled : false
  200. enabled: !checked || Cura.MachineManager.numberExtrudersEnabled > 1 //Disable if it's the last enabled extruder.
  201. height: parent.height
  202. style: UM.Theme.styles.checkbox
  203. /* Use a MouseArea to process the click on this checkbox.
  204. This is necessary because actually clicking the checkbox
  205. causes the "checked" property to be overwritten. After
  206. it's been overwritten, the original link that made it
  207. depend on the active extruder stack is broken. */
  208. MouseArea
  209. {
  210. anchors.fill: parent
  211. onClicked: Cura.MachineManager.setExtruderEnabled(Cura.ExtruderManager.activeExtruderIndex, !parent.checked)
  212. enabled: parent.enabled
  213. }
  214. }
  215. }
  216. Row
  217. {
  218. height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0
  219. visible: Cura.MachineManager.hasMaterials
  220. Label
  221. {
  222. text: catalog.i18nc("@label", "Material")
  223. verticalAlignment: Text.AlignVCenter
  224. font: UM.Theme.getFont("default")
  225. color: UM.Theme.getColor("text")
  226. height: parent.height
  227. width: selectors.textWidth
  228. renderType: Text.NativeRendering
  229. }
  230. OldControls.ToolButton
  231. {
  232. id: materialSelection
  233. property bool valueError: Cura.MachineManager.activeStack !== null ? Cura.ContainerManager.getContainerMetaDataEntry(Cura.MachineManager.activeStack.material.id, "compatible", "") !== "True" : true
  234. property bool valueWarning: !Cura.MachineManager.isActiveQualitySupported
  235. text: Cura.MachineManager.activeStack !== null ? Cura.MachineManager.activeStack.material.name : ""
  236. tooltip: text
  237. width: selectors.controlWidth
  238. height: parent.height
  239. style: UM.Theme.styles.print_setup_header_button
  240. activeFocusOnPress: true
  241. menu: Cura.MaterialMenu
  242. {
  243. extruderIndex: Cura.ExtruderManager.activeExtruderIndex
  244. updateModels: materialSelection.visible
  245. }
  246. }
  247. Item
  248. {
  249. width: instructionButton.width + 2 * UM.Theme.getSize("default_margin").width
  250. height: instructionButton.visible ? materialSelection.height: 0
  251. Button
  252. {
  253. id: instructionButton
  254. hoverEnabled: true
  255. contentItem: Item {}
  256. height: 0.5 * materialSelection.height
  257. width: height
  258. anchors.centerIn: parent
  259. background: UM.RecolorImage
  260. {
  261. source: UM.Theme.getIcon("printing_guideline")
  262. color: instructionButton.hovered ? UM.Theme.getColor("primary") : UM.Theme.getColor("icon")
  263. }
  264. visible: selectors.instructionLink != ""
  265. onClicked:Qt.openUrlExternally(selectors.instructionLink)
  266. }
  267. }
  268. }
  269. Row
  270. {
  271. height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0
  272. visible: Cura.MachineManager.hasVariants
  273. Label
  274. {
  275. text: Cura.MachineManager.activeDefinitionVariantsName
  276. verticalAlignment: Text.AlignVCenter
  277. font: UM.Theme.getFont("default")
  278. color: UM.Theme.getColor("text")
  279. height: parent.height
  280. width: selectors.textWidth
  281. renderType: Text.NativeRendering
  282. }
  283. OldControls.ToolButton
  284. {
  285. id: variantSelection
  286. text: Cura.MachineManager.activeVariantName
  287. tooltip: Cura.MachineManager.activeVariantName
  288. height: parent.height
  289. width: selectors.controlWidth
  290. style: UM.Theme.styles.print_setup_header_button
  291. activeFocusOnPress: true;
  292. menu: Cura.NozzleMenu { extruderIndex: Cura.ExtruderManager.activeExtruderIndex }
  293. }
  294. }
  295. Row
  296. {
  297. id: warnings
  298. height: visible ? childrenRect.height : 0
  299. visible: buildplateCompatibilityError || buildplateCompatibilityWarning
  300. property bool buildplateCompatibilityError: !Cura.MachineManager.variantBuildplateCompatible && !Cura.MachineManager.variantBuildplateUsable
  301. property bool buildplateCompatibilityWarning: Cura.MachineManager.variantBuildplateUsable
  302. // This is a space holder aligning the warning messages.
  303. Label
  304. {
  305. text: ""
  306. width: selectors.textWidth
  307. renderType: Text.NativeRendering
  308. }
  309. Item
  310. {
  311. width: selectors.controlWidth
  312. height: childrenRect.height
  313. UM.RecolorImage
  314. {
  315. id: warningImage
  316. anchors.left: parent.left
  317. source: UM.Theme.getIcon("warning")
  318. width: UM.Theme.getSize("section_icon").width
  319. height: UM.Theme.getSize("section_icon").height
  320. sourceSize.width: width
  321. sourceSize.height: height
  322. color: UM.Theme.getColor("material_compatibility_warning")
  323. visible: !Cura.MachineManager.isCurrentSetupSupported || warnings.buildplateCompatibilityError || warnings.buildplateCompatibilityWarning
  324. }
  325. Label
  326. {
  327. id: materialCompatibilityLabel
  328. anchors.left: warningImage.right
  329. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  330. verticalAlignment: Text.AlignVCenter
  331. width: selectors.controlWidth - warningImage.width - UM.Theme.getSize("default_margin").width
  332. text: catalog.i18nc("@label", "Use glue for better adhesion with this material combination.")
  333. font: UM.Theme.getFont("default")
  334. color: UM.Theme.getColor("text")
  335. visible: CuraSDKVersion == "dev" ? false : warnings.buildplateCompatibilityError || warnings.buildplateCompatibilityWarning
  336. wrapMode: Text.WordWrap
  337. renderType: Text.NativeRendering
  338. }
  339. }
  340. }
  341. }
  342. }
  343. }