HeatedBedBox.qml 15 KB

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