HeatedBedBox.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. // Copyright (c) 2017 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. implicitWidth: parent.width
  12. height: visible ? UM.Theme.getSize("sidebar_extruder_box").height : 0
  13. property var printerModel
  14. Rectangle
  15. {
  16. color: UM.Theme.getColor("sidebar")
  17. anchors.fill: parent
  18. Label //Build plate label.
  19. {
  20. text: catalog.i18nc("@label", "Build plate")
  21. font: UM.Theme.getFont("default")
  22. color: UM.Theme.getColor("text")
  23. anchors.left: parent.left
  24. anchors.top: parent.top
  25. anchors.margins: UM.Theme.getSize("default_margin").width
  26. }
  27. Label //Target temperature.
  28. {
  29. id: bedTargetTemperature
  30. text: printerModel != null ? printerModel.targetBedTemperature + "°C" : ""
  31. font: UM.Theme.getFont("small")
  32. color: UM.Theme.getColor("text_inactive")
  33. anchors.right: parent.right
  34. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  35. anchors.bottom: bedCurrentTemperature.bottom
  36. MouseArea //For tooltip.
  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. Label //Current temperature.
  59. {
  60. id: bedCurrentTemperature
  61. text: printerModel != null ? printerModel.bedTemperature + "°C" : ""
  62. font: UM.Theme.getFont("large")
  63. color: UM.Theme.getColor("text")
  64. anchors.right: bedTargetTemperature.left
  65. anchors.top: parent.top
  66. anchors.margins: UM.Theme.getSize("default_margin").width
  67. MouseArea //For tooltip.
  68. {
  69. id: bedTemperatureTooltipArea
  70. hoverEnabled: true
  71. anchors.fill: parent
  72. onHoveredChanged:
  73. {
  74. if (containsMouse)
  75. {
  76. base.showTooltip(
  77. base,
  78. {x: 0, y: bedCurrentTemperature.mapToItem(base, 0, -parent.height / 4).y},
  79. catalog.i18nc("@tooltip", "The current temperature of the heated bed.")
  80. );
  81. }
  82. else
  83. {
  84. base.hideTooltip();
  85. }
  86. }
  87. }
  88. }
  89. Rectangle //Input field for pre-heat temperature.
  90. {
  91. id: preheatTemperatureControl
  92. color: !enabled ? UM.Theme.getColor("setting_control_disabled") : showError ? UM.Theme.getColor("setting_validation_error_background") : UM.Theme.getColor("setting_validation_ok")
  93. property var showError:
  94. {
  95. if(bedTemperature.properties.maximum_value != "None" && bedTemperature.properties.maximum_value < Math.floor(preheatTemperatureInput.text))
  96. {
  97. return true;
  98. } else
  99. {
  100. return false;
  101. }
  102. }
  103. enabled:
  104. {
  105. if (printerModel == null)
  106. {
  107. return false; //Can't preheat if not connected.
  108. }
  109. if (!connectedPrinter.acceptsCommands)
  110. {
  111. return false; //Not allowed to do anything.
  112. }
  113. if (connectedPrinter.activePrinter && connectedPrinter.activePrinter.activePrintJob)
  114. {
  115. if((["printing", "pre_print", "resuming", "pausing", "paused", "error", "offline"]).indexOf(connectedPrinter.activePrinter.activePrintJob.state) != -1)
  116. {
  117. return false; //Printer is in a state where it can't react to pre-heating.
  118. }
  119. }
  120. return true;
  121. }
  122. border.width: UM.Theme.getSize("default_lining").width
  123. 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")
  124. anchors.right: preheatButton.left
  125. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  126. anchors.bottom: parent.bottom
  127. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  128. width: UM.Theme.getSize("monitor_preheat_temperature_control").width
  129. height: UM.Theme.getSize("monitor_preheat_temperature_control").height
  130. visible: printerModel != null ? enabled && printerModel.canPreHeatBed && !printerModel.isPreheating : true
  131. Rectangle //Highlight of input field.
  132. {
  133. anchors.fill: parent
  134. anchors.margins: UM.Theme.getSize("default_lining").width
  135. color: UM.Theme.getColor("setting_control_highlight")
  136. opacity: preheatTemperatureControl.hovered ? 1.0 : 0
  137. }
  138. MouseArea //Change cursor on hovering.
  139. {
  140. id: preheatTemperatureInputMouseArea
  141. hoverEnabled: true
  142. anchors.fill: parent
  143. cursorShape: Qt.IBeamCursor
  144. onHoveredChanged:
  145. {
  146. if (containsMouse)
  147. {
  148. base.showTooltip(
  149. base,
  150. {x: 0, y: preheatTemperatureInputMouseArea.mapToItem(base, 0, 0).y},
  151. catalog.i18nc("@tooltip of temperature input", "The temperature to pre-heat the bed to.")
  152. );
  153. }
  154. else
  155. {
  156. base.hideTooltip();
  157. }
  158. }
  159. }
  160. Label
  161. {
  162. id: unit
  163. anchors.right: parent.right
  164. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  165. anchors.verticalCenter: parent.verticalCenter
  166. text: "°C";
  167. color: UM.Theme.getColor("setting_unit")
  168. font: UM.Theme.getFont("default")
  169. }
  170. TextInput
  171. {
  172. id: preheatTemperatureInput
  173. font: UM.Theme.getFont("default")
  174. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  175. selectByMouse: true
  176. maximumLength: 5
  177. enabled: parent.enabled
  178. validator: RegExpValidator { regExp: /^-?[0-9]{0,9}[.,]?[0-9]{0,10}$/ } //Floating point regex.
  179. anchors.left: parent.left
  180. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  181. anchors.right: unit.left
  182. anchors.verticalCenter: parent.verticalCenter
  183. renderType: Text.NativeRendering
  184. Component.onCompleted:
  185. {
  186. if (!bedTemperature.properties.value)
  187. {
  188. text = "";
  189. }
  190. if ((bedTemperature.resolve != "None" && bedTemperature.resolve) && (bedTemperature.stackLevels[0] != 0) && (bedTemperature.stackLevels[0] != 1))
  191. {
  192. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  193. // we have to choose between the resolved value (default) and the global value
  194. // (if user has explicitly set this).
  195. text = bedTemperature.resolve;
  196. }
  197. else
  198. {
  199. text = bedTemperature.properties.value;
  200. }
  201. }
  202. }
  203. }
  204. Button // The pre-heat button.
  205. {
  206. id: preheatButton
  207. height: UM.Theme.getSize("setting_control").height
  208. visible: printerModel != null ? printerModel.canPreHeatBed: true
  209. enabled:
  210. {
  211. if (!preheatTemperatureControl.enabled)
  212. {
  213. return false; //Not connected, not authenticated or printer is busy.
  214. }
  215. if (printerModel.isPreheating)
  216. {
  217. return true;
  218. }
  219. if (bedTemperature.properties.minimum_value != "None" && Math.floor(preheatTemperatureInput.text) < Math.floor(bedTemperature.properties.minimum_value))
  220. {
  221. return false; //Target temperature too low.
  222. }
  223. if (bedTemperature.properties.maximum_value != "None" && Math.floor(preheatTemperatureInput.text) > Math.floor(bedTemperature.properties.maximum_value))
  224. {
  225. return false; //Target temperature too high.
  226. }
  227. if (Math.floor(preheatTemperatureInput.text) == 0)
  228. {
  229. return false; //Setting the temperature to 0 is not allowed (since that cancels the pre-heating).
  230. }
  231. return true; //Preconditions are met.
  232. }
  233. anchors.right: parent.right
  234. anchors.bottom: parent.bottom
  235. anchors.margins: UM.Theme.getSize("default_margin").width
  236. style: ButtonStyle {
  237. background: Rectangle
  238. {
  239. border.width: UM.Theme.getSize("default_lining").width
  240. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  241. border.color:
  242. {
  243. if(!control.enabled)
  244. {
  245. return UM.Theme.getColor("action_button_disabled_border");
  246. }
  247. else if(control.pressed)
  248. {
  249. return UM.Theme.getColor("action_button_active_border");
  250. }
  251. else if(control.hovered)
  252. {
  253. return UM.Theme.getColor("action_button_hovered_border");
  254. }
  255. else
  256. {
  257. return UM.Theme.getColor("action_button_border");
  258. }
  259. }
  260. color:
  261. {
  262. if(!control.enabled)
  263. {
  264. return UM.Theme.getColor("action_button_disabled");
  265. }
  266. else if(control.pressed)
  267. {
  268. return UM.Theme.getColor("action_button_active");
  269. }
  270. else if(control.hovered)
  271. {
  272. return UM.Theme.getColor("action_button_hovered");
  273. }
  274. else
  275. {
  276. return UM.Theme.getColor("action_button");
  277. }
  278. }
  279. Behavior on color
  280. {
  281. ColorAnimation
  282. {
  283. duration: 50
  284. }
  285. }
  286. Label
  287. {
  288. id: actualLabel
  289. anchors.centerIn: parent
  290. color:
  291. {
  292. if(!control.enabled)
  293. {
  294. return UM.Theme.getColor("action_button_disabled_text");
  295. }
  296. else if(control.pressed)
  297. {
  298. return UM.Theme.getColor("action_button_active_text");
  299. }
  300. else if(control.hovered)
  301. {
  302. return UM.Theme.getColor("action_button_hovered_text");
  303. }
  304. else
  305. {
  306. return UM.Theme.getColor("action_button_text");
  307. }
  308. }
  309. font: UM.Theme.getFont("action_button")
  310. text:
  311. {
  312. if(printerModel == null)
  313. {
  314. return ""
  315. }
  316. if(printerModel.isPreheating )
  317. {
  318. return catalog.i18nc("@button Cancel pre-heating", "Cancel")
  319. } else
  320. {
  321. return catalog.i18nc("@button", "Pre-heat")
  322. }
  323. }
  324. }
  325. }
  326. }
  327. onClicked:
  328. {
  329. if (!printerModel.isPreheating)
  330. {
  331. printerModel.preheatBed(preheatTemperatureInput.text, 900);
  332. }
  333. else
  334. {
  335. printerModel.cancelPreheatBed();
  336. }
  337. }
  338. onHoveredChanged:
  339. {
  340. if (hovered)
  341. {
  342. base.showTooltip(
  343. base,
  344. {x: 0, y: preheatButton.mapToItem(base, 0, 0).y},
  345. 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.")
  346. );
  347. }
  348. else
  349. {
  350. base.hideTooltip();
  351. }
  352. }
  353. }
  354. }
  355. }