HeatedBedBox.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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.4
  5. import UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. Item
  8. {
  9. implicitWidth: parent.width
  10. height: visible ? UM.Theme.getSize("print_setup_extruder_box").height : 0
  11. property var printerModel
  12. property var connectedPrinter: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
  13. Rectangle
  14. {
  15. color: UM.Theme.getColor("main_background")
  16. anchors.fill: parent
  17. // Build plate label.
  18. UM.Label
  19. {
  20. text: catalog.i18nc("@label", "Build plate")
  21. anchors.left: parent.left
  22. anchors.top: parent.top
  23. anchors.margins: UM.Theme.getSize("default_margin").width
  24. }
  25. // Target temperature.
  26. UM.Label
  27. {
  28. id: bedTargetTemperature
  29. text: printerModel != null ? printerModel.targetBedTemperature + "°C" : ""
  30. font: UM.Theme.getFont("default_bold")
  31. color: UM.Theme.getColor("text_inactive")
  32. anchors.right: parent.right
  33. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  34. anchors.bottom: bedCurrentTemperature.bottom
  35. // For tooltip.
  36. MouseArea
  37. {
  38. id: bedTargetTemperatureTooltipArea
  39. hoverEnabled: true
  40. anchors.fill: parent
  41. onHoveredChanged:
  42. {
  43. if (containsMouse)
  44. {
  45. base.showTooltip(
  46. base,
  47. {x: 0, y: bedTargetTemperature.mapToItem(base, 0, -parent.height / 4).y},
  48. catalog.i18nc("@tooltip", "The target temperature of the heated bed. The bed will heat up or cool down towards this temperature. If this is 0, the bed heating is turned off.")
  49. );
  50. }
  51. else
  52. {
  53. base.hideTooltip();
  54. }
  55. }
  56. }
  57. }
  58. // Current temperature.
  59. UM.Label
  60. {
  61. id: bedCurrentTemperature
  62. text: printerModel != null ? printerModel.bedTemperature + "°C" : ""
  63. font: UM.Theme.getFont("large_bold")
  64. anchors.right: bedTargetTemperature.left
  65. anchors.top: parent.top
  66. anchors.margins: UM.Theme.getSize("default_margin").width
  67. //For tooltip.
  68. MouseArea
  69. {
  70. id: bedTemperatureTooltipArea
  71. hoverEnabled: true
  72. anchors.fill: parent
  73. onHoveredChanged:
  74. {
  75. if (containsMouse)
  76. {
  77. base.showTooltip(
  78. base,
  79. {x: 0, y: bedCurrentTemperature.mapToItem(base, 0, -parent.height / 4).y},
  80. catalog.i18nc("@tooltip", "The current temperature of the heated bed.")
  81. );
  82. }
  83. else
  84. {
  85. base.hideTooltip();
  86. }
  87. }
  88. }
  89. }
  90. //Input field for pre-heat temperature.
  91. Rectangle
  92. {
  93. id: preheatTemperatureControl
  94. color: !enabled ? UM.Theme.getColor("setting_control_disabled") : showError ? UM.Theme.getColor("setting_validation_error_background") : UM.Theme.getColor("setting_validation_ok")
  95. property var showError:
  96. {
  97. if(bedTemperature.properties.maximum_value != "None" && bedTemperature.properties.maximum_value < Math.floor(preheatTemperatureInput.text))
  98. {
  99. return true;
  100. } else
  101. {
  102. return false;
  103. }
  104. }
  105. enabled:
  106. {
  107. if (printerModel == null)
  108. {
  109. return false; //Can't preheat if not connected.
  110. }
  111. if (connectedPrinter == null || !connectedPrinter.acceptsCommands)
  112. {
  113. return false; //Not allowed to do anything.
  114. }
  115. if (connectedPrinter.activePrinter && connectedPrinter.activePrinter.activePrintJob)
  116. {
  117. if((["printing", "pre_print", "resuming", "pausing", "paused", "error", "offline"]).indexOf(connectedPrinter.activePrinter.activePrintJob.state) != -1)
  118. {
  119. return false; //Printer is in a state where it can't react to pre-heating.
  120. }
  121. }
  122. return true;
  123. }
  124. border.width: UM.Theme.getSize("default_lining").width
  125. 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")
  126. anchors.right: preheatButton.left
  127. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  128. anchors.bottom: parent.bottom
  129. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  130. width: UM.Theme.getSize("monitor_preheat_temperature_control").width
  131. height: UM.Theme.getSize("monitor_preheat_temperature_control").height
  132. visible: printerModel != null ? enabled && printerModel.canPreHeatBed && !printerModel.isPreheating : true
  133. Rectangle //Highlight of input field.
  134. {
  135. anchors.fill: parent
  136. anchors.margins: UM.Theme.getSize("default_lining").width
  137. color: UM.Theme.getColor("setting_control_highlight")
  138. opacity: preheatTemperatureControl.hovered ? 1.0 : 0
  139. }
  140. MouseArea //Change cursor on hovering.
  141. {
  142. id: preheatTemperatureInputMouseArea
  143. hoverEnabled: true
  144. anchors.fill: parent
  145. cursorShape: Qt.IBeamCursor
  146. onHoveredChanged:
  147. {
  148. if (containsMouse)
  149. {
  150. base.showTooltip(
  151. base,
  152. {x: 0, y: preheatTemperatureInputMouseArea.mapToItem(base, 0, 0).y},
  153. catalog.i18nc("@tooltip of temperature input", "The temperature to pre-heat the bed to.")
  154. );
  155. }
  156. else
  157. {
  158. base.hideTooltip();
  159. }
  160. }
  161. }
  162. UM.Label
  163. {
  164. id: unit
  165. anchors.right: parent.right
  166. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  167. anchors.verticalCenter: parent.verticalCenter
  168. text: "°C";
  169. color: UM.Theme.getColor("setting_unit")
  170. }
  171. TextInput
  172. {
  173. id: preheatTemperatureInput
  174. font: UM.Theme.getFont("default")
  175. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  176. selectByMouse: true
  177. maximumLength: 5
  178. enabled: parent.enabled
  179. validator: RegularExpressionValidator { regularExpression: /^-?[0-9]{0,9}[.,]?[0-9]{0,10}$/ } //Floating point regex.
  180. anchors.left: parent.left
  181. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  182. anchors.right: unit.left
  183. anchors.verticalCenter: parent.verticalCenter
  184. renderType: Text.NativeRendering
  185. text:
  186. {
  187. if (!bedTemperature.properties.value)
  188. {
  189. return "";
  190. }
  191. if ((bedTemperature.resolve != "None" && bedTemperature.resolve) && (bedTemperature.stackLevels[0] != 0) && (bedTemperature.stackLevels[0] != 1))
  192. {
  193. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  194. // we have to choose between the resolved value (default) and the global value
  195. // (if user has explicitly set this).
  196. return bedTemperature.resolve;
  197. }
  198. else
  199. {
  200. return bedTemperature.properties.value;
  201. }
  202. }
  203. }
  204. }
  205. // The pre-heat button.
  206. Cura.SecondaryButton
  207. {
  208. id: preheatButton
  209. height: UM.Theme.getSize("setting_control").height
  210. visible: printerModel != null ? printerModel.canPreHeatBed: true
  211. enabled:
  212. {
  213. if (!preheatTemperatureControl.enabled)
  214. {
  215. return false; //Not connected, not authenticated or printer is busy.
  216. }
  217. if (printerModel.isPreheating)
  218. {
  219. return true;
  220. }
  221. if (bedTemperature.properties.minimum_value != "None" && Math.floor(preheatTemperatureInput.text) < Math.floor(bedTemperature.properties.minimum_value))
  222. {
  223. return false; //Target temperature too low.
  224. }
  225. if (bedTemperature.properties.maximum_value != "None" && Math.floor(preheatTemperatureInput.text) > Math.floor(bedTemperature.properties.maximum_value))
  226. {
  227. return false; //Target temperature too high.
  228. }
  229. if (Math.floor(preheatTemperatureInput.text) == 0)
  230. {
  231. return false; //Setting the temperature to 0 is not allowed (since that cancels the pre-heating).
  232. }
  233. return true; //Preconditions are met.
  234. }
  235. anchors.right: parent.right
  236. anchors.bottom: parent.bottom
  237. anchors.margins: UM.Theme.getSize("default_margin").width
  238. text:
  239. {
  240. if (printerModel == null)
  241. {
  242. return ""
  243. }
  244. if (printerModel.isPreheating )
  245. {
  246. return catalog.i18nc("@button Cancel pre-heating", "Cancel")
  247. }
  248. else
  249. {
  250. return catalog.i18nc("@button", "Pre-heat")
  251. }
  252. }
  253. onClicked:
  254. {
  255. if (!printerModel.isPreheating)
  256. {
  257. printerModel.preheatBed(preheatTemperatureInput.text, 900);
  258. }
  259. else
  260. {
  261. printerModel.cancelPreheatBed();
  262. }
  263. }
  264. onHoveredChanged:
  265. {
  266. if (hovered)
  267. {
  268. base.showTooltip(
  269. base,
  270. { x: 0, y: preheatButton.mapToItem(base, 0, 0).y },
  271. catalog.i18nc("@tooltip of pre-heat", "Heat the bed in advance before printing. You can continue adjusting your print while it is heating, and you won't have to wait for the bed to heat up when you're ready to print.")
  272. );
  273. }
  274. else
  275. {
  276. base.hideTooltip();
  277. }
  278. }
  279. }
  280. }
  281. }