CustomConfiguration.qml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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.activeMachine !== null ? Cura.MachineManager.activeMachine.definition.name: ""
  64. tooltip: text
  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. function 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. function 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.MachineManager.activeStack != null ? 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. id: enabledCheckbox
  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. Binding
  204. {
  205. target: enabledCheckbox
  206. property: "checked"
  207. value: Cura.MachineManager.activeStack.isEnabled
  208. when: Cura.MachineManager.activeStack != null
  209. }
  210. /* Use a MouseArea to process the click on this checkbox.
  211. This is necessary because actually clicking the checkbox
  212. causes the "checked" property to be overwritten. After
  213. it's been overwritten, the original link that made it
  214. depend on the active extruder stack is broken. */
  215. MouseArea
  216. {
  217. anchors.fill: parent
  218. onClicked:
  219. {
  220. if(!parent.enabled)
  221. {
  222. return
  223. }
  224. // Already update the visual indication
  225. parent.checked = !parent.checked
  226. // Update the settings on the background!
  227. Cura.MachineManager.setExtruderEnabled(Cura.ExtruderManager.activeExtruderIndex, parent.checked)
  228. }
  229. }
  230. }
  231. }
  232. Row
  233. {
  234. height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0
  235. visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasMaterials : false
  236. Label
  237. {
  238. text: catalog.i18nc("@label", "Material")
  239. verticalAlignment: Text.AlignVCenter
  240. font: UM.Theme.getFont("default")
  241. color: UM.Theme.getColor("text")
  242. height: parent.height
  243. width: selectors.textWidth
  244. renderType: Text.NativeRendering
  245. }
  246. OldControls.ToolButton
  247. {
  248. id: materialSelection
  249. property bool valueError: Cura.MachineManager.activeStack !== null ? Cura.ContainerManager.getContainerMetaDataEntry(Cura.MachineManager.activeStack.material.id, "compatible", "") !== "True" : true
  250. property bool valueWarning: !Cura.MachineManager.isActiveQualitySupported
  251. text: Cura.MachineManager.activeStack !== null ? Cura.MachineManager.activeStack.material.name : ""
  252. tooltip: text
  253. enabled: enabledCheckbox.checked
  254. width: selectors.controlWidth
  255. height: parent.height
  256. style: UM.Theme.styles.print_setup_header_button
  257. activeFocusOnPress: true
  258. Cura.MaterialMenu
  259. {
  260. id: materialsMenu
  261. extruderIndex: Cura.ExtruderManager.activeExtruderIndex
  262. updateModels: materialSelection.visible
  263. }
  264. onClicked:
  265. {
  266. materialsMenu.popup();
  267. }
  268. }
  269. Item
  270. {
  271. width: instructionButton.width + 2 * UM.Theme.getSize("narrow_margin").width
  272. height: instructionButton.visible ? materialSelection.height: 0
  273. Button
  274. {
  275. id: instructionButton
  276. hoverEnabled: true
  277. contentItem: Item {}
  278. height: UM.Theme.getSize("small_button").height
  279. width: UM.Theme.getSize("small_button").width
  280. anchors.centerIn: parent
  281. background: UM.RecolorImage
  282. {
  283. source: UM.Theme.getIcon("Guide")
  284. color: instructionButton.hovered ? UM.Theme.getColor("primary") : UM.Theme.getColor("icon")
  285. }
  286. visible: selectors.instructionLink != ""
  287. onClicked:Qt.openUrlExternally(selectors.instructionLink)
  288. }
  289. }
  290. }
  291. Row
  292. {
  293. height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0
  294. visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasVariants : false
  295. Label
  296. {
  297. text: Cura.MachineManager.activeDefinitionVariantsName
  298. verticalAlignment: Text.AlignVCenter
  299. font: UM.Theme.getFont("default")
  300. color: UM.Theme.getColor("text")
  301. height: parent.height
  302. width: selectors.textWidth
  303. renderType: Text.NativeRendering
  304. }
  305. OldControls.ToolButton
  306. {
  307. id: variantSelection
  308. text: Cura.MachineManager.activeStack != null ? Cura.MachineManager.activeStack.variant.name : ""
  309. tooltip: text
  310. height: parent.height
  311. width: selectors.controlWidth
  312. style: UM.Theme.styles.print_setup_header_button
  313. activeFocusOnPress: true
  314. enabled: enabledCheckbox.checked
  315. Cura.NozzleMenu
  316. {
  317. id: nozzlesMenu
  318. extruderIndex: Cura.ExtruderManager.activeExtruderIndex
  319. }
  320. onClicked:
  321. {
  322. nozzlesMenu.popup();
  323. }
  324. }
  325. }
  326. Row
  327. {
  328. id: warnings
  329. height: visible ? childrenRect.height : 0
  330. visible: buildplateCompatibilityError || buildplateCompatibilityWarning
  331. property bool buildplateCompatibilityError: !Cura.MachineManager.variantBuildplateCompatible && !Cura.MachineManager.variantBuildplateUsable
  332. property bool buildplateCompatibilityWarning: Cura.MachineManager.variantBuildplateUsable
  333. // This is a space holder aligning the warning messages.
  334. Label
  335. {
  336. text: ""
  337. width: selectors.textWidth
  338. renderType: Text.NativeRendering
  339. }
  340. Item
  341. {
  342. width: selectors.controlWidth
  343. height: childrenRect.height
  344. UM.RecolorImage
  345. {
  346. id: warningImage
  347. anchors.left: parent.left
  348. source: UM.Theme.getIcon("Warning")
  349. width: UM.Theme.getSize("section_icon").width
  350. height: UM.Theme.getSize("section_icon").height
  351. sourceSize.width: width
  352. sourceSize.height: height
  353. color: UM.Theme.getColor("material_compatibility_warning")
  354. visible: !Cura.MachineManager.isCurrentSetupSupported || warnings.buildplateCompatibilityError || warnings.buildplateCompatibilityWarning
  355. }
  356. Label
  357. {
  358. id: materialCompatibilityLabel
  359. anchors.left: warningImage.right
  360. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  361. verticalAlignment: Text.AlignVCenter
  362. width: selectors.controlWidth - warningImage.width - UM.Theme.getSize("default_margin").width
  363. text: catalog.i18nc("@label", "Use glue for better adhesion with this material combination.")
  364. font: UM.Theme.getFont("default")
  365. color: UM.Theme.getColor("text")
  366. visible: CuraSDKVersion == "dev" ? false : warnings.buildplateCompatibilityError || warnings.buildplateCompatibilityWarning
  367. wrapMode: Text.WordWrap
  368. renderType: Text.NativeRendering
  369. }
  370. }
  371. }
  372. }
  373. }
  374. }