ExtruderBox.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. //Copyright (c) 2022 Ultimaker B.V.
  2. //Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.15
  4. import QtQuick.Controls 2.1
  5. import UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. Item
  8. {
  9. property alias color: background.color
  10. property var extruderModel
  11. property var position: index
  12. property var connectedPrinter: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
  13. implicitWidth: parent.width
  14. implicitHeight: UM.Theme.getSize("print_setup_extruder_box").height
  15. UM.SettingPropertyProvider
  16. {
  17. id: extruderTemperature
  18. containerStackId: Cura.ExtruderManager.extruderIds[position]
  19. key: "material_print_temperature_layer_0"
  20. watchedProperties: ["value", "minimum_value", "maximum_value", "resolve"]
  21. storeIndex: 0
  22. }
  23. Rectangle
  24. {
  25. id: background
  26. anchors.fill: parent
  27. // Extruder name.
  28. UM.Label
  29. {
  30. text: Cura.MachineManager.activeMachine.extruderList[position].name !== "" ? Cura.MachineManager.activeMachine.extruderList[position].name : catalog.i18nc("@label", "Extruder")
  31. anchors.left: parent.left
  32. anchors.top: parent.top
  33. anchors.margins: UM.Theme.getSize("default_margin").width
  34. }
  35. // Target temperature.
  36. UM.Label
  37. {
  38. id: extruderTargetTemperature
  39. text: Math.round(extruderModel.targetHotendTemperature) + "°C"
  40. font: UM.Theme.getFont("default_bold")
  41. color: UM.Theme.getColor("text_inactive")
  42. anchors.right: parent.right
  43. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  44. anchors.bottom: extruderCurrentTemperature.bottom
  45. //For tooltip.
  46. MouseArea
  47. {
  48. id: extruderTargetTemperatureTooltipArea
  49. hoverEnabled: true
  50. anchors.fill: parent
  51. onHoveredChanged:
  52. {
  53. if (containsMouse)
  54. {
  55. base.showTooltip(
  56. base,
  57. {x: 0, y: extruderTargetTemperature.mapToItem(base, 0, Math.floor(-parent.height / 4)).y},
  58. catalog.i18nc("@tooltip", "The target temperature of the hotend. The hotend will heat up or cool down towards this temperature. If this is 0, the hotend heating is turned off.")
  59. );
  60. }
  61. else
  62. {
  63. base.hideTooltip();
  64. }
  65. }
  66. }
  67. }
  68. //Temperature indication.
  69. UM.Label
  70. {
  71. id: extruderCurrentTemperature
  72. text: Math.round(extruderModel.hotendTemperature) + "°C"
  73. font: UM.Theme.getFont("large_bold")
  74. anchors.right: extruderTargetTemperature.left
  75. anchors.top: parent.top
  76. anchors.margins: UM.Theme.getSize("default_margin").width
  77. //For tooltip.
  78. MouseArea
  79. {
  80. id: extruderCurrentTemperatureTooltipArea
  81. hoverEnabled: true
  82. anchors.fill: parent
  83. onHoveredChanged:
  84. {
  85. if (containsMouse)
  86. {
  87. base.showTooltip(
  88. base,
  89. {x: 0, y: parent.mapToItem(base, 0, Math.floor(-parent.height / 4)).y},
  90. catalog.i18nc("@tooltip", "The current temperature of this hotend.")
  91. );
  92. }
  93. else
  94. {
  95. base.hideTooltip();
  96. }
  97. }
  98. }
  99. }
  100. //Input field for pre-heat temperature.
  101. Rectangle
  102. {
  103. id: preheatTemperatureControl
  104. color: !enabled ? UM.Theme.getColor("setting_control_disabled") : showError ? UM.Theme.getColor("setting_validation_error_background") : UM.Theme.getColor("setting_validation_ok")
  105. property var showError:
  106. {
  107. if(extruderTemperature.properties.maximum_value != "None" && extruderTemperature.properties.maximum_value < Math.floor(preheatTemperatureInput.text))
  108. {
  109. return true;
  110. } else
  111. {
  112. return false;
  113. }
  114. }
  115. enabled:
  116. {
  117. if (extruderModel == null)
  118. {
  119. return false; //Can't preheat if not connected.
  120. }
  121. if (!connectedPrinter.acceptsCommands)
  122. {
  123. return false; //Not allowed to do anything.
  124. }
  125. if (connectedPrinter.activePrinter && connectedPrinter.activePrinter.activePrintJob)
  126. {
  127. if((["printing", "pre_print", "resuming", "pausing", "paused", "error", "offline"]).indexOf(connectedPrinter.activePrinter.activePrintJob.state) != -1)
  128. {
  129. return false; //Printer is in a state where it can't react to pre-heating.
  130. }
  131. }
  132. return true;
  133. }
  134. border.width: UM.Theme.getSize("default_lining").width
  135. border.color: !enabled ? UM.Theme.getColor("setting_control_disabled_border") : preheatTemperatureInputMouseArea.containsMouse ? UM.Theme.getColor("setting_control_border_highlight") : UM.Theme.getColor("setting_control_border")
  136. anchors.right: preheatButton.left
  137. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  138. anchors.bottom: parent.bottom
  139. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  140. width: UM.Theme.getSize("monitor_preheat_temperature_control").width
  141. height: UM.Theme.getSize("monitor_preheat_temperature_control").height
  142. visible: extruderModel != null ? enabled && extruderModel.canPreHeatHotends && !extruderModel.isPreheating : true
  143. //Highlight of input field.
  144. Rectangle
  145. {
  146. anchors.fill: parent
  147. anchors.margins: UM.Theme.getSize("default_lining").width
  148. color: UM.Theme.getColor("setting_control_highlight")
  149. opacity: preheatTemperatureControl.hovered ? 1.0 : 0
  150. }
  151. //Change cursor on hovering.
  152. MouseArea
  153. {
  154. id: preheatTemperatureInputMouseArea
  155. hoverEnabled: true
  156. anchors.fill: parent
  157. cursorShape: Qt.IBeamCursor
  158. onHoveredChanged:
  159. {
  160. if (containsMouse)
  161. {
  162. base.showTooltip(
  163. base,
  164. {x: 0, y: preheatTemperatureInputMouseArea.mapToItem(base, 0, -parent.height/2).y},
  165. catalog.i18nc("@tooltip of temperature input", "The temperature to pre-heat the hotend to.")
  166. );
  167. }
  168. else
  169. {
  170. base.hideTooltip();
  171. }
  172. }
  173. }
  174. UM.Label
  175. {
  176. id: unit
  177. anchors.right: parent.right
  178. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  179. anchors.verticalCenter: parent.verticalCenter
  180. text: "°C";
  181. color: UM.Theme.getColor("setting_unit")
  182. }
  183. TextInput
  184. {
  185. id: preheatTemperatureInput
  186. font: UM.Theme.getFont("default")
  187. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  188. selectByMouse: true
  189. maximumLength: 5
  190. enabled: parent.enabled
  191. validator: RegularExpressionValidator { regularExpression: /^-?[0-9]{0,9}[.,]?[0-9]{0,10}$/ } //Floating point regex.
  192. anchors.left: parent.left
  193. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  194. anchors.right: unit.left
  195. anchors.verticalCenter: parent.verticalCenter
  196. renderType: Text.NativeRendering
  197. text:
  198. {
  199. if (!extruderTemperature.properties.value)
  200. {
  201. return "";
  202. }
  203. else
  204. {
  205. return extruderTemperature.properties.value;
  206. }
  207. }
  208. }
  209. }
  210. Cura.SecondaryButton
  211. {
  212. id: preheatButton
  213. height: UM.Theme.getSize("setting_control").height
  214. visible: extruderModel != null ? extruderModel.canPreHeatHotends: true
  215. enabled:
  216. {
  217. if (!preheatTemperatureControl.enabled)
  218. {
  219. return false; //Not connected, not authenticated or printer is busy.
  220. }
  221. if (extruderModel.isPreheating)
  222. {
  223. return true;
  224. }
  225. if (extruderTemperature.properties.minimum_value != "None" && Math.floor(preheatTemperatureInput.text) < Math.floor(extruderTemperature.properties.minimum_value))
  226. {
  227. return false; //Target temperature too low.
  228. }
  229. if (extruderTemperature.properties.maximum_value != "None" && Math.floor(preheatTemperatureInput.text) > Math.floor(extruderTemperature.properties.maximum_value))
  230. {
  231. return false; //Target temperature too high.
  232. }
  233. if (Math.floor(preheatTemperatureInput.text) == 0)
  234. {
  235. return false; //Setting the temperature to 0 is not allowed (since that cancels the pre-heating).
  236. }
  237. return true; //Preconditions are met.
  238. }
  239. anchors.right: parent.right
  240. anchors.bottom: parent.bottom
  241. anchors.margins: UM.Theme.getSize("default_margin").width
  242. text:
  243. {
  244. if(extruderModel == null)
  245. {
  246. return ""
  247. }
  248. if(extruderModel.isPreheating )
  249. {
  250. return catalog.i18nc("@button Cancel pre-heating", "Cancel")
  251. } else
  252. {
  253. return catalog.i18nc("@button", "Pre-heat")
  254. }
  255. }
  256. onClicked:
  257. {
  258. if (!extruderModel.isPreheating)
  259. {
  260. extruderModel.preheatHotend(preheatTemperatureInput.text, 900);
  261. }
  262. else
  263. {
  264. extruderModel.cancelPreheatHotend();
  265. }
  266. }
  267. onHoveredChanged:
  268. {
  269. if (hovered)
  270. {
  271. base.showTooltip(
  272. base,
  273. {x: 0, y: preheatButton.mapToItem(base, 0, -parent.height).y},
  274. catalog.i18nc("@tooltip of pre-heat", "Heat the hotend in advance before printing. You can continue adjusting your print while it is heating, and you won't have to wait for the hotend to heat up when you're ready to print.")
  275. );
  276. }
  277. else
  278. {
  279. base.hideTooltip();
  280. }
  281. }
  282. }
  283. //Material colour indication.
  284. Rectangle
  285. {
  286. id: materialColor
  287. width: Math.floor(materialName.height * 0.75)
  288. height: Math.floor(materialName.height * 0.75)
  289. radius: width / 2
  290. color: extruderModel.activeMaterial ? extruderModel.activeMaterial.color: "#00000000"
  291. border.width: UM.Theme.getSize("default_lining").width
  292. border.color: UM.Theme.getColor("lining")
  293. visible: extruderModel.activeMaterial != null
  294. anchors.left: parent.left
  295. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  296. anchors.verticalCenter: materialName.verticalCenter
  297. //For tooltip.
  298. MouseArea
  299. {
  300. id: materialColorTooltipArea
  301. hoverEnabled: true
  302. anchors.fill: parent
  303. onHoveredChanged:
  304. {
  305. if (containsMouse)
  306. {
  307. base.showTooltip(
  308. base,
  309. {x: 0, y: parent.mapToItem(base, 0, -parent.height / 2).y},
  310. catalog.i18nc("@tooltip", "The colour of the material in this extruder.")
  311. );
  312. }
  313. else
  314. {
  315. base.hideTooltip();
  316. }
  317. }
  318. }
  319. }
  320. //Material name.
  321. UM.Label
  322. {
  323. id: materialName
  324. text: extruderModel.activeMaterial != null ? extruderModel.activeMaterial.type : ""
  325. anchors.left: materialColor.right
  326. anchors.bottom: parent.bottom
  327. anchors.margins: UM.Theme.getSize("default_margin").width
  328. //For tooltip.
  329. MouseArea
  330. {
  331. id: materialNameTooltipArea
  332. hoverEnabled: true
  333. anchors.fill: parent
  334. onHoveredChanged:
  335. {
  336. if (containsMouse)
  337. {
  338. base.showTooltip(
  339. base,
  340. {x: 0, y: parent.mapToItem(base, 0, 0).y},
  341. catalog.i18nc("@tooltip", "The material in this extruder.")
  342. );
  343. }
  344. else
  345. {
  346. base.hideTooltip();
  347. }
  348. }
  349. }
  350. }
  351. //Variant name.
  352. UM.Label
  353. {
  354. id: variantName
  355. text: extruderModel.hotendID
  356. anchors.right: parent.right
  357. anchors.bottom: parent.bottom
  358. anchors.margins: UM.Theme.getSize("default_margin").width
  359. //For tooltip.
  360. MouseArea
  361. {
  362. id: variantNameTooltipArea
  363. hoverEnabled: true
  364. anchors.fill: parent
  365. onHoveredChanged:
  366. {
  367. if (containsMouse)
  368. {
  369. base.showTooltip(
  370. base,
  371. { x: 0, y: parent.mapToItem(base, 0, -parent.height / 4).y },
  372. catalog.i18nc("@tooltip", "The nozzle inserted in this extruder.")
  373. );
  374. }
  375. else
  376. {
  377. base.hideTooltip();
  378. }
  379. }
  380. }
  381. }
  382. }
  383. }