ExtruderBox.qml 15 KB

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