CustomConfiguration.qml 15 KB

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