CustomConfiguration.qml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. 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.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. menu: Cura.MaterialMenu
  259. {
  260. extruderIndex: Cura.ExtruderManager.activeExtruderIndex
  261. updateModels: materialSelection.visible
  262. }
  263. }
  264. Item
  265. {
  266. width: instructionButton.width + 2 * UM.Theme.getSize("default_margin").width
  267. height: instructionButton.visible ? materialSelection.height: 0
  268. Button
  269. {
  270. id: instructionButton
  271. hoverEnabled: true
  272. contentItem: Item {}
  273. height: 0.5 * materialSelection.height
  274. width: height
  275. anchors.centerIn: parent
  276. background: UM.RecolorImage
  277. {
  278. source: UM.Theme.getIcon("printing_guideline")
  279. color: instructionButton.hovered ? UM.Theme.getColor("primary") : UM.Theme.getColor("icon")
  280. }
  281. visible: selectors.instructionLink != ""
  282. onClicked:Qt.openUrlExternally(selectors.instructionLink)
  283. }
  284. }
  285. }
  286. Row
  287. {
  288. height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0
  289. visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasVariants : false
  290. Label
  291. {
  292. text: Cura.MachineManager.activeDefinitionVariantsName
  293. verticalAlignment: Text.AlignVCenter
  294. font: UM.Theme.getFont("default")
  295. color: UM.Theme.getColor("text")
  296. height: parent.height
  297. width: selectors.textWidth
  298. renderType: Text.NativeRendering
  299. }
  300. OldControls.ToolButton
  301. {
  302. id: variantSelection
  303. text: Cura.MachineManager.activeStack != null ? Cura.MachineManager.activeStack.variant.name : ""
  304. tooltip: text
  305. height: parent.height
  306. width: selectors.controlWidth
  307. style: UM.Theme.styles.print_setup_header_button
  308. activeFocusOnPress: true
  309. enabled: enabledCheckbox.checked
  310. menu: Cura.NozzleMenu { extruderIndex: Cura.ExtruderManager.activeExtruderIndex }
  311. }
  312. }
  313. Row
  314. {
  315. id: warnings
  316. height: visible ? childrenRect.height : 0
  317. visible: buildplateCompatibilityError || buildplateCompatibilityWarning
  318. property bool buildplateCompatibilityError: !Cura.MachineManager.variantBuildplateCompatible && !Cura.MachineManager.variantBuildplateUsable
  319. property bool buildplateCompatibilityWarning: Cura.MachineManager.variantBuildplateUsable
  320. // This is a space holder aligning the warning messages.
  321. Label
  322. {
  323. text: ""
  324. width: selectors.textWidth
  325. renderType: Text.NativeRendering
  326. }
  327. Item
  328. {
  329. width: selectors.controlWidth
  330. height: childrenRect.height
  331. UM.RecolorImage
  332. {
  333. id: warningImage
  334. anchors.left: parent.left
  335. source: UM.Theme.getIcon("warning")
  336. width: UM.Theme.getSize("section_icon").width
  337. height: UM.Theme.getSize("section_icon").height
  338. sourceSize.width: width
  339. sourceSize.height: height
  340. color: UM.Theme.getColor("material_compatibility_warning")
  341. visible: !Cura.MachineManager.isCurrentSetupSupported || warnings.buildplateCompatibilityError || warnings.buildplateCompatibilityWarning
  342. }
  343. Label
  344. {
  345. id: materialCompatibilityLabel
  346. anchors.left: warningImage.right
  347. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  348. verticalAlignment: Text.AlignVCenter
  349. width: selectors.controlWidth - warningImage.width - UM.Theme.getSize("default_margin").width
  350. text: catalog.i18nc("@label", "Use glue for better adhesion with this material combination.")
  351. font: UM.Theme.getFont("default")
  352. color: UM.Theme.getColor("text")
  353. visible: CuraSDKVersion == "dev" ? false : warnings.buildplateCompatibilityError || warnings.buildplateCompatibilityWarning
  354. wrapMode: Text.WordWrap
  355. renderType: Text.NativeRendering
  356. }
  357. }
  358. }
  359. }
  360. }
  361. }