HeatedBedBox.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. // Copyright (c) 2017 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import QtQuick.Layouts 1.3
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. Item
  10. {
  11. implicitWidth: parent.width
  12. height: visible ? UM.Theme.getSize("print_setup_extruder_box").height : 0
  13. property var printerModel
  14. property var connectedPrinter: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
  15. Rectangle
  16. {
  17. color: UM.Theme.getColor("main_background")
  18. anchors.fill: parent
  19. Label //Build plate label.
  20. {
  21. text: catalog.i18nc("@label", "Build plate")
  22. font: UM.Theme.getFont("default")
  23. color: UM.Theme.getColor("text")
  24. anchors.left: parent.left
  25. anchors.top: parent.top
  26. anchors.margins: UM.Theme.getSize("default_margin").width
  27. }
  28. Label //Target temperature.
  29. {
  30. id: bedTargetTemperature
  31. text: printerModel != null ? printerModel.targetBedTemperature + "°C" : ""
  32. font: UM.Theme.getFont("default_bold")
  33. color: UM.Theme.getColor("text_inactive")
  34. anchors.right: parent.right
  35. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  36. anchors.bottom: bedCurrentTemperature.bottom
  37. MouseArea //For tooltip.
  38. {
  39. id: bedTargetTemperatureTooltipArea
  40. hoverEnabled: true
  41. anchors.fill: parent
  42. onHoveredChanged:
  43. {
  44. if (containsMouse)
  45. {
  46. base.showTooltip(
  47. base,
  48. {x: 0, y: bedTargetTemperature.mapToItem(base, 0, -parent.height / 4).y},
  49. 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.")
  50. );
  51. }
  52. else
  53. {
  54. base.hideTooltip();
  55. }
  56. }
  57. }
  58. }
  59. Label //Current temperature.
  60. {
  61. id: bedCurrentTemperature
  62. text: printerModel != null ? printerModel.bedTemperature + "°C" : ""
  63. font: UM.Theme.getFont("large_bold")
  64. color: UM.Theme.getColor("text")
  65. anchors.right: bedTargetTemperature.left
  66. anchors.top: parent.top
  67. anchors.margins: UM.Theme.getSize("default_margin").width
  68. MouseArea //For tooltip.
  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. Rectangle //Input field for pre-heat temperature.
  91. {
  92. id: preheatTemperatureControl
  93. color: !enabled ? UM.Theme.getColor("setting_control_disabled") : showError ? UM.Theme.getColor("setting_validation_error_background") : UM.Theme.getColor("setting_validation_ok")
  94. property var showError:
  95. {
  96. if(bedTemperature.properties.maximum_value != "None" && bedTemperature.properties.maximum_value < Math.floor(preheatTemperatureInput.text))
  97. {
  98. return true;
  99. } else
  100. {
  101. return false;
  102. }
  103. }
  104. enabled:
  105. {
  106. if (printerModel == null)
  107. {
  108. return false; //Can't preheat if not connected.
  109. }
  110. if (connectedPrinter == null || !connectedPrinter.acceptsCommands)
  111. {
  112. return false; //Not allowed to do anything.
  113. }
  114. if (connectedPrinter.activePrinter && connectedPrinter.activePrinter.activePrintJob)
  115. {
  116. if((["printing", "pre_print", "resuming", "pausing", "paused", "error", "offline"]).indexOf(connectedPrinter.activePrinter.activePrintJob.state) != -1)
  117. {
  118. return false; //Printer is in a state where it can't react to pre-heating.
  119. }
  120. }
  121. return true;
  122. }
  123. border.width: UM.Theme.getSize("default_lining").width
  124. 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")
  125. anchors.right: preheatButton.left
  126. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  127. anchors.bottom: parent.bottom
  128. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  129. width: UM.Theme.getSize("monitor_preheat_temperature_control").width
  130. height: UM.Theme.getSize("monitor_preheat_temperature_control").height
  131. visible: printerModel != null ? enabled && printerModel.canPreHeatBed && !printerModel.isPreheating : true
  132. Rectangle //Highlight of input field.
  133. {
  134. anchors.fill: parent
  135. anchors.margins: UM.Theme.getSize("default_lining").width
  136. color: UM.Theme.getColor("setting_control_highlight")
  137. opacity: preheatTemperatureControl.hovered ? 1.0 : 0
  138. }
  139. MouseArea //Change cursor on hovering.
  140. {
  141. id: preheatTemperatureInputMouseArea
  142. hoverEnabled: true
  143. anchors.fill: parent
  144. cursorShape: Qt.IBeamCursor
  145. onHoveredChanged:
  146. {
  147. if (containsMouse)
  148. {
  149. base.showTooltip(
  150. base,
  151. {x: 0, y: preheatTemperatureInputMouseArea.mapToItem(base, 0, 0).y},
  152. catalog.i18nc("@tooltip of temperature input", "The temperature to pre-heat the bed to.")
  153. );
  154. }
  155. else
  156. {
  157. base.hideTooltip();
  158. }
  159. }
  160. }
  161. Label
  162. {
  163. id: unit
  164. anchors.right: parent.right
  165. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  166. anchors.verticalCenter: parent.verticalCenter
  167. text: "°C";
  168. color: UM.Theme.getColor("setting_unit")
  169. font: UM.Theme.getFont("default")
  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: RegExpValidator { regExp: /^-?[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. Button // The pre-heat button.
  206. {
  207. id: preheatButton
  208. height: UM.Theme.getSize("setting_control").height
  209. visible: printerModel != null ? printerModel.canPreHeatBed: true
  210. enabled:
  211. {
  212. if (!preheatTemperatureControl.enabled)
  213. {
  214. return false; //Not connected, not authenticated or printer is busy.
  215. }
  216. if (printerModel.isPreheating)
  217. {
  218. return true;
  219. }
  220. if (bedTemperature.properties.minimum_value != "None" && Math.floor(preheatTemperatureInput.text) < Math.floor(bedTemperature.properties.minimum_value))
  221. {
  222. return false; //Target temperature too low.
  223. }
  224. if (bedTemperature.properties.maximum_value != "None" && Math.floor(preheatTemperatureInput.text) > Math.floor(bedTemperature.properties.maximum_value))
  225. {
  226. return false; //Target temperature too high.
  227. }
  228. if (Math.floor(preheatTemperatureInput.text) == 0)
  229. {
  230. return false; //Setting the temperature to 0 is not allowed (since that cancels the pre-heating).
  231. }
  232. return true; //Preconditions are met.
  233. }
  234. anchors.right: parent.right
  235. anchors.bottom: parent.bottom
  236. anchors.margins: UM.Theme.getSize("default_margin").width
  237. style: ButtonStyle {
  238. background: Rectangle
  239. {
  240. border.width: UM.Theme.getSize("default_lining").width
  241. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  242. border.color:
  243. {
  244. if(!control.enabled)
  245. {
  246. return UM.Theme.getColor("action_button_disabled_border");
  247. }
  248. else if(control.pressed)
  249. {
  250. return UM.Theme.getColor("action_button_active_border");
  251. }
  252. else if(control.hovered)
  253. {
  254. return UM.Theme.getColor("action_button_hovered_border");
  255. }
  256. else
  257. {
  258. return UM.Theme.getColor("action_button_border");
  259. }
  260. }
  261. color:
  262. {
  263. if(!control.enabled)
  264. {
  265. return UM.Theme.getColor("action_button_disabled");
  266. }
  267. else if(control.pressed)
  268. {
  269. return UM.Theme.getColor("action_button_active");
  270. }
  271. else if(control.hovered)
  272. {
  273. return UM.Theme.getColor("action_button_hovered");
  274. }
  275. else
  276. {
  277. return UM.Theme.getColor("action_button");
  278. }
  279. }
  280. Behavior on color
  281. {
  282. ColorAnimation
  283. {
  284. duration: 50
  285. }
  286. }
  287. Label
  288. {
  289. id: actualLabel
  290. anchors.centerIn: parent
  291. color:
  292. {
  293. if(!control.enabled)
  294. {
  295. return UM.Theme.getColor("action_button_disabled_text");
  296. }
  297. else if(control.pressed)
  298. {
  299. return UM.Theme.getColor("action_button_active_text");
  300. }
  301. else if(control.hovered)
  302. {
  303. return UM.Theme.getColor("action_button_hovered_text");
  304. }
  305. else
  306. {
  307. return UM.Theme.getColor("action_button_text");
  308. }
  309. }
  310. font: UM.Theme.getFont("medium")
  311. text:
  312. {
  313. if(printerModel == null)
  314. {
  315. return ""
  316. }
  317. if(printerModel.isPreheating )
  318. {
  319. return catalog.i18nc("@button Cancel pre-heating", "Cancel")
  320. } else
  321. {
  322. return catalog.i18nc("@button", "Pre-heat")
  323. }
  324. }
  325. }
  326. }
  327. }
  328. onClicked:
  329. {
  330. if (!printerModel.isPreheating)
  331. {
  332. printerModel.preheatBed(preheatTemperatureInput.text, 900);
  333. }
  334. else
  335. {
  336. printerModel.cancelPreheatBed();
  337. }
  338. }
  339. onHoveredChanged:
  340. {
  341. if (hovered)
  342. {
  343. base.showTooltip(
  344. base,
  345. {x: 0, y: preheatButton.mapToItem(base, 0, 0).y},
  346. 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.")
  347. );
  348. }
  349. else
  350. {
  351. base.hideTooltip();
  352. }
  353. }
  354. }
  355. }
  356. }