ExtruderBox.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. //Copyright (c) 2019 Ultimaker B.V.
  2. //Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. Item
  10. {
  11. property alias color: background.color
  12. property var extruderModel
  13. property var position: index
  14. property var connectedPrinter: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
  15. implicitWidth: parent.width
  16. implicitHeight: UM.Theme.getSize("print_setup_extruder_box").height
  17. UM.SettingPropertyProvider
  18. {
  19. id: extruderTemperature
  20. containerStackId: Cura.ExtruderManager.extruderIds[position]
  21. key: "material_print_temperature"
  22. watchedProperties: ["value", "minimum_value", "maximum_value", "resolve"]
  23. storeIndex: 0
  24. property var resolve: Cura.MachineManager.activeStack != Cura.MachineManager.activeMachine ? properties.resolve : "None"
  25. }
  26. Rectangle
  27. {
  28. id: background
  29. anchors.fill: parent
  30. Label //Extruder name.
  31. {
  32. text: Cura.MachineManager.activeMachine.extruderList[position].name !== "" ? Cura.MachineManager.activeMachine.extruderList[position].name : catalog.i18nc("@label", "Extruder")
  33. color: UM.Theme.getColor("text")
  34. font: UM.Theme.getFont("default")
  35. anchors.left: parent.left
  36. anchors.top: parent.top
  37. anchors.margins: UM.Theme.getSize("default_margin").width
  38. }
  39. Label //Target temperature.
  40. {
  41. id: extruderTargetTemperature
  42. text: Math.round(extruderModel.targetHotendTemperature) + "°C"
  43. font: UM.Theme.getFont("default_bold")
  44. color: UM.Theme.getColor("text_inactive")
  45. anchors.right: parent.right
  46. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  47. anchors.bottom: extruderCurrentTemperature.bottom
  48. MouseArea //For tooltip.
  49. {
  50. id: extruderTargetTemperatureTooltipArea
  51. hoverEnabled: true
  52. anchors.fill: parent
  53. onHoveredChanged:
  54. {
  55. if (containsMouse)
  56. {
  57. base.showTooltip(
  58. base,
  59. {x: 0, y: extruderTargetTemperature.mapToItem(base, 0, Math.floor(-parent.height / 4)).y},
  60. 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.")
  61. );
  62. }
  63. else
  64. {
  65. base.hideTooltip();
  66. }
  67. }
  68. }
  69. }
  70. Label //Temperature indication.
  71. {
  72. id: extruderCurrentTemperature
  73. text: Math.round(extruderModel.hotendTemperature) + "°C"
  74. color: UM.Theme.getColor("text")
  75. font: UM.Theme.getFont("large_bold")
  76. anchors.right: extruderTargetTemperature.left
  77. anchors.top: parent.top
  78. anchors.margins: UM.Theme.getSize("default_margin").width
  79. MouseArea //For tooltip.
  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. Rectangle //Input field for pre-heat temperature.
  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. Rectangle //Highlight of input field.
  144. {
  145. anchors.fill: parent
  146. anchors.margins: UM.Theme.getSize("default_lining").width
  147. color: UM.Theme.getColor("setting_control_highlight")
  148. opacity: preheatTemperatureControl.hovered ? 1.0 : 0
  149. }
  150. MouseArea //Change cursor on hovering.
  151. {
  152. id: preheatTemperatureInputMouseArea
  153. hoverEnabled: true
  154. anchors.fill: parent
  155. cursorShape: Qt.IBeamCursor
  156. onHoveredChanged:
  157. {
  158. if (containsMouse)
  159. {
  160. base.showTooltip(
  161. base,
  162. {x: 0, y: preheatTemperatureInputMouseArea.mapToItem(base, 0, -parent.height/2).y},
  163. catalog.i18nc("@tooltip of temperature input", "The temperature to pre-heat the hotend to.")
  164. );
  165. }
  166. else
  167. {
  168. base.hideTooltip();
  169. }
  170. }
  171. }
  172. Label
  173. {
  174. id: unit
  175. anchors.right: parent.right
  176. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  177. anchors.verticalCenter: parent.verticalCenter
  178. text: "°C";
  179. color: UM.Theme.getColor("setting_unit")
  180. font: UM.Theme.getFont("default")
  181. }
  182. TextInput
  183. {
  184. id: preheatTemperatureInput
  185. font: UM.Theme.getFont("default")
  186. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  187. selectByMouse: true
  188. maximumLength: 5
  189. enabled: parent.enabled
  190. validator: RegExpValidator { regExp: /^-?[0-9]{0,9}[.,]?[0-9]{0,10}$/ } //Floating point regex.
  191. anchors.left: parent.left
  192. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  193. anchors.right: unit.left
  194. anchors.verticalCenter: parent.verticalCenter
  195. renderType: Text.NativeRendering
  196. text:
  197. {
  198. if (!extruderTemperature.properties.value)
  199. {
  200. return "";
  201. }
  202. else
  203. {
  204. return extruderTemperature.properties.value;
  205. }
  206. }
  207. }
  208. }
  209. Cura.SecondaryButton
  210. {
  211. id: preheatButton
  212. height: UM.Theme.getSize("setting_control").height
  213. visible: extruderModel != null ? extruderModel.canPreHeatHotends: true
  214. enabled:
  215. {
  216. if (!preheatTemperatureControl.enabled)
  217. {
  218. return false; //Not connected, not authenticated or printer is busy.
  219. }
  220. if (extruderModel.isPreheating)
  221. {
  222. return true;
  223. }
  224. if (extruderTemperature.properties.minimum_value != "None" && Math.floor(preheatTemperatureInput.text) < Math.floor(extruderTemperature.properties.minimum_value))
  225. {
  226. return false; //Target temperature too low.
  227. }
  228. if (extruderTemperature.properties.maximum_value != "None" && Math.floor(preheatTemperatureInput.text) > Math.floor(extruderTemperature.properties.maximum_value))
  229. {
  230. return false; //Target temperature too high.
  231. }
  232. if (Math.floor(preheatTemperatureInput.text) == 0)
  233. {
  234. return false; //Setting the temperature to 0 is not allowed (since that cancels the pre-heating).
  235. }
  236. return true; //Preconditions are met.
  237. }
  238. anchors.right: parent.right
  239. anchors.bottom: parent.bottom
  240. anchors.margins: UM.Theme.getSize("default_margin").width
  241. text:
  242. {
  243. if(extruderModel == null)
  244. {
  245. return ""
  246. }
  247. if(extruderModel.isPreheating )
  248. {
  249. return catalog.i18nc("@button Cancel pre-heating", "Cancel")
  250. } else
  251. {
  252. return catalog.i18nc("@button", "Pre-heat")
  253. }
  254. }
  255. onClicked:
  256. {
  257. if (!extruderModel.isPreheating)
  258. {
  259. extruderModel.preheatHotend(preheatTemperatureInput.text, 900);
  260. }
  261. else
  262. {
  263. extruderModel.cancelPreheatHotend();
  264. }
  265. }
  266. onHoveredChanged:
  267. {
  268. if (hovered)
  269. {
  270. base.showTooltip(
  271. base,
  272. {x: 0, y: preheatButton.mapToItem(base, 0, -parent.height).y},
  273. 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.")
  274. );
  275. }
  276. else
  277. {
  278. base.hideTooltip();
  279. }
  280. }
  281. }
  282. Rectangle //Material colour indication.
  283. {
  284. id: materialColor
  285. width: Math.floor(materialName.height * 0.75)
  286. height: Math.floor(materialName.height * 0.75)
  287. radius: width / 2
  288. color: extruderModel.activeMaterial ? extruderModel.activeMaterial.color: "#00000000"
  289. border.width: UM.Theme.getSize("default_lining").width
  290. border.color: UM.Theme.getColor("lining")
  291. visible: extruderModel.activeMaterial != null
  292. anchors.left: parent.left
  293. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  294. anchors.verticalCenter: materialName.verticalCenter
  295. MouseArea //For tooltip.
  296. {
  297. id: materialColorTooltipArea
  298. hoverEnabled: true
  299. anchors.fill: parent
  300. onHoveredChanged:
  301. {
  302. if (containsMouse)
  303. {
  304. base.showTooltip(
  305. base,
  306. {x: 0, y: parent.mapToItem(base, 0, -parent.height / 2).y},
  307. catalog.i18nc("@tooltip", "The colour of the material in this extruder.")
  308. );
  309. }
  310. else
  311. {
  312. base.hideTooltip();
  313. }
  314. }
  315. }
  316. }
  317. Label //Material name.
  318. {
  319. id: materialName
  320. text: extruderModel.activeMaterial != null ? extruderModel.activeMaterial.type : ""
  321. font: UM.Theme.getFont("default")
  322. color: UM.Theme.getColor("text")
  323. anchors.left: materialColor.right
  324. anchors.bottom: parent.bottom
  325. anchors.margins: UM.Theme.getSize("default_margin").width
  326. MouseArea //For tooltip.
  327. {
  328. id: materialNameTooltipArea
  329. hoverEnabled: true
  330. anchors.fill: parent
  331. onHoveredChanged:
  332. {
  333. if (containsMouse)
  334. {
  335. base.showTooltip(
  336. base,
  337. {x: 0, y: parent.mapToItem(base, 0, 0).y},
  338. catalog.i18nc("@tooltip", "The material in this extruder.")
  339. );
  340. }
  341. else
  342. {
  343. base.hideTooltip();
  344. }
  345. }
  346. }
  347. }
  348. Label //Variant name.
  349. {
  350. id: variantName
  351. text: extruderModel.hotendID
  352. font: UM.Theme.getFont("default")
  353. color: UM.Theme.getColor("text")
  354. anchors.right: parent.right
  355. anchors.bottom: parent.bottom
  356. anchors.margins: UM.Theme.getSize("default_margin").width
  357. MouseArea //For tooltip.
  358. {
  359. id: variantNameTooltipArea
  360. hoverEnabled: true
  361. anchors.fill: parent
  362. onHoveredChanged:
  363. {
  364. if (containsMouse)
  365. {
  366. base.showTooltip(
  367. base,
  368. {x: 0, y: parent.mapToItem(base, 0, -parent.height / 4).y},
  369. catalog.i18nc("@tooltip", "The nozzle inserted in this extruder.")
  370. );
  371. }
  372. else
  373. {
  374. base.hideTooltip();
  375. }
  376. }
  377. }
  378. }
  379. }
  380. }