ExtruderBox.qml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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. property alias color: background.color
  10. property var extruderModel
  11. property var position: index
  12. implicitWidth: parent.width
  13. implicitHeight: UM.Theme.getSize("sidebar_extruder_box").height
  14. UM.SettingPropertyProvider
  15. {
  16. id: extruderTemperature
  17. containerStackId: Cura.ExtruderManager.extruderIds[position]
  18. key: "material_print_temperature"
  19. watchedProperties: ["value", "minimum_value", "maximum_value", "resolve"]
  20. storeIndex: 0
  21. property var resolve: Cura.MachineManager.activeStackId != Cura.MachineManager.activeMachineId ? properties.resolve : "None"
  22. }
  23. Rectangle
  24. {
  25. id: background
  26. anchors.fill: parent
  27. Label //Extruder name.
  28. {
  29. text: Cura.ExtruderManager.getExtruderName(position) != "" ? Cura.ExtruderManager.getExtruderName(position) : catalog.i18nc("@label", "Extruder")
  30. color: UM.Theme.getColor("text")
  31. font: UM.Theme.getFont("default")
  32. anchors.left: parent.left
  33. anchors.top: parent.top
  34. anchors.margins: UM.Theme.getSize("default_margin").width
  35. }
  36. Label //Target temperature.
  37. {
  38. id: extruderTargetTemperature
  39. text: Math.round(extruderModel.targetHotendTemperature) + "°C"
  40. font: UM.Theme.getFont("small")
  41. color: UM.Theme.getColor("text_inactive")
  42. anchors.right: parent.right
  43. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  44. anchors.bottom: extruderCurrentTemperature.bottom
  45. MouseArea //For tooltip.
  46. {
  47. id: extruderTargetTemperatureTooltipArea
  48. hoverEnabled: true
  49. anchors.fill: parent
  50. onHoveredChanged:
  51. {
  52. if (containsMouse)
  53. {
  54. base.showTooltip(
  55. base,
  56. {x: 0, y: extruderTargetTemperature.mapToItem(base, 0, Math.floor(-parent.height / 4)).y},
  57. 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.")
  58. );
  59. }
  60. else
  61. {
  62. base.hideTooltip();
  63. }
  64. }
  65. }
  66. }
  67. Label //Temperature indication.
  68. {
  69. id: extruderCurrentTemperature
  70. text: Math.round(extruderModel.hotendTemperature) + "°C"
  71. color: UM.Theme.getColor("text")
  72. font: UM.Theme.getFont("large")
  73. anchors.right: extruderTargetTemperature.left
  74. anchors.top: parent.top
  75. anchors.margins: UM.Theme.getSize("default_margin").width
  76. MouseArea //For tooltip.
  77. {
  78. id: extruderCurrentTemperatureTooltipArea
  79. hoverEnabled: true
  80. anchors.fill: parent
  81. onHoveredChanged:
  82. {
  83. if (containsMouse)
  84. {
  85. base.showTooltip(
  86. base,
  87. {x: 0, y: parent.mapToItem(base, 0, Math.floor(-parent.height / 4)).y},
  88. catalog.i18nc("@tooltip", "The current temperature of this hotend.")
  89. );
  90. }
  91. else
  92. {
  93. base.hideTooltip();
  94. }
  95. }
  96. }
  97. }
  98. Rectangle //Input field for pre-heat temperature.
  99. {
  100. id: preheatTemperatureControl
  101. color: !enabled ? UM.Theme.getColor("setting_control_disabled") : showError ? UM.Theme.getColor("setting_validation_error_background") : UM.Theme.getColor("setting_validation_ok")
  102. property var showError:
  103. {
  104. if(extruderTemperature.properties.maximum_value != "None" && extruderTemperature.properties.maximum_value < Math.floor(preheatTemperatureInput.text))
  105. {
  106. return true;
  107. } else
  108. {
  109. return false;
  110. }
  111. }
  112. enabled:
  113. {
  114. if (extruderModel == null)
  115. {
  116. return false; //Can't preheat if not connected.
  117. }
  118. if (!connectedPrinter.acceptsCommands)
  119. {
  120. return false; //Not allowed to do anything.
  121. }
  122. if (connectedPrinter.activePrinter && connectedPrinter.activePrinter.activePrintJob)
  123. {
  124. if((["printing", "pre_print", "resuming", "pausing", "paused", "error", "offline"]).indexOf(connectedPrinter.activePrinter.activePrintJob.state) != -1)
  125. {
  126. return false; //Printer is in a state where it can't react to pre-heating.
  127. }
  128. }
  129. return true;
  130. }
  131. border.width: UM.Theme.getSize("default_lining").width
  132. 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")
  133. anchors.right: preheatButton.left
  134. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  135. anchors.bottom: parent.bottom
  136. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  137. width: UM.Theme.getSize("monitor_preheat_temperature_control").width
  138. height: UM.Theme.getSize("monitor_preheat_temperature_control").height
  139. visible: extruderModel != null ? enabled && extruderModel.canPreHeatHotends && !extruderModel.isPreheating : true
  140. Rectangle //Highlight of input field.
  141. {
  142. anchors.fill: parent
  143. anchors.margins: UM.Theme.getSize("default_lining").width
  144. color: UM.Theme.getColor("setting_control_highlight")
  145. opacity: preheatTemperatureControl.hovered ? 1.0 : 0
  146. }
  147. MouseArea //Change cursor on hovering.
  148. {
  149. id: preheatTemperatureInputMouseArea
  150. hoverEnabled: true
  151. anchors.fill: parent
  152. cursorShape: Qt.IBeamCursor
  153. onHoveredChanged:
  154. {
  155. if (containsMouse)
  156. {
  157. base.showTooltip(
  158. base,
  159. {x: 0, y: preheatTemperatureInputMouseArea.mapToItem(base, 0, 0).y},
  160. catalog.i18nc("@tooltip of temperature input", "The temperature to pre-heat the hotend to.")
  161. );
  162. }
  163. else
  164. {
  165. base.hideTooltip();
  166. }
  167. }
  168. }
  169. Label
  170. {
  171. id: unit
  172. anchors.right: parent.right
  173. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  174. anchors.verticalCenter: parent.verticalCenter
  175. text: "°C";
  176. color: UM.Theme.getColor("setting_unit")
  177. font: UM.Theme.getFont("default")
  178. }
  179. TextInput
  180. {
  181. id: preheatTemperatureInput
  182. font: UM.Theme.getFont("default")
  183. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  184. selectByMouse: true
  185. maximumLength: 5
  186. enabled: parent.enabled
  187. validator: RegExpValidator { regExp: /^-?[0-9]{0,9}[.,]?[0-9]{0,10}$/ } //Floating point regex.
  188. anchors.left: parent.left
  189. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  190. anchors.right: unit.left
  191. anchors.verticalCenter: parent.verticalCenter
  192. renderType: Text.NativeRendering
  193. Component.onCompleted:
  194. {
  195. if (!extruderTemperature.properties.value)
  196. {
  197. text = "";
  198. }
  199. else
  200. {
  201. text = extruderTemperature.properties.value;
  202. }
  203. }
  204. }
  205. }
  206. Button //The pre-heat button.
  207. {
  208. id: preheatButton
  209. height: UM.Theme.getSize("setting_control").height
  210. visible: extruderModel != null ? extruderModel.canPreHeatHotends: true
  211. enabled:
  212. {
  213. if (!preheatTemperatureControl.enabled)
  214. {
  215. return false; //Not connected, not authenticated or printer is busy.
  216. }
  217. if (extruderModel.isPreheating)
  218. {
  219. return true;
  220. }
  221. if (extruderTemperature.properties.minimum_value != "None" && Math.floor(preheatTemperatureInput.text) < Math.floor(extruderTemperature.properties.minimum_value))
  222. {
  223. return false; //Target temperature too low.
  224. }
  225. if (extruderTemperature.properties.maximum_value != "None" && Math.floor(preheatTemperatureInput.text) > Math.floor(extruderTemperature.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. style: ButtonStyle {
  239. background: Rectangle
  240. {
  241. border.width: UM.Theme.getSize("default_lining").width
  242. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  243. border.color:
  244. {
  245. if(!control.enabled)
  246. {
  247. return UM.Theme.getColor("action_button_disabled_border");
  248. }
  249. else if(control.pressed)
  250. {
  251. return UM.Theme.getColor("action_button_active_border");
  252. }
  253. else if(control.hovered)
  254. {
  255. return UM.Theme.getColor("action_button_hovered_border");
  256. }
  257. else
  258. {
  259. return UM.Theme.getColor("action_button_border");
  260. }
  261. }
  262. color:
  263. {
  264. if(!control.enabled)
  265. {
  266. return UM.Theme.getColor("action_button_disabled");
  267. }
  268. else if(control.pressed)
  269. {
  270. return UM.Theme.getColor("action_button_active");
  271. }
  272. else if(control.hovered)
  273. {
  274. return UM.Theme.getColor("action_button_hovered");
  275. }
  276. else
  277. {
  278. return UM.Theme.getColor("action_button");
  279. }
  280. }
  281. Behavior on color
  282. {
  283. ColorAnimation
  284. {
  285. duration: 50
  286. }
  287. }
  288. Label
  289. {
  290. id: actualLabel
  291. anchors.centerIn: parent
  292. color:
  293. {
  294. if(!control.enabled)
  295. {
  296. return UM.Theme.getColor("action_button_disabled_text");
  297. }
  298. else if(control.pressed)
  299. {
  300. return UM.Theme.getColor("action_button_active_text");
  301. }
  302. else if(control.hovered)
  303. {
  304. return UM.Theme.getColor("action_button_hovered_text");
  305. }
  306. else
  307. {
  308. return UM.Theme.getColor("action_button_text");
  309. }
  310. }
  311. font: UM.Theme.getFont("action_button")
  312. text:
  313. {
  314. if(extruderModel == null)
  315. {
  316. return ""
  317. }
  318. if(extruderModel.isPreheating )
  319. {
  320. return catalog.i18nc("@button Cancel pre-heating", "Cancel")
  321. } else
  322. {
  323. return catalog.i18nc("@button", "Pre-heat")
  324. }
  325. }
  326. }
  327. }
  328. }
  329. onClicked:
  330. {
  331. if (!extruderModel.isPreheating)
  332. {
  333. extruderModel.preheatHotend(preheatTemperatureInput.text, 900);
  334. }
  335. else
  336. {
  337. extruderModel.cancelPreheatHotend();
  338. }
  339. }
  340. onHoveredChanged:
  341. {
  342. if (hovered)
  343. {
  344. base.showTooltip(
  345. base,
  346. {x: 0, y: preheatButton.mapToItem(base, 0, 0).y},
  347. 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.")
  348. );
  349. }
  350. else
  351. {
  352. base.hideTooltip();
  353. }
  354. }
  355. }
  356. Rectangle //Material colour indication.
  357. {
  358. id: materialColor
  359. width: Math.floor(materialName.height * 0.75)
  360. height: Math.floor(materialName.height * 0.75)
  361. radius: width / 2
  362. color: extruderModel.activeMaterial ? extruderModel.activeMaterial.color: "#00000000"
  363. border.width: UM.Theme.getSize("default_lining").width
  364. border.color: UM.Theme.getColor("lining")
  365. visible: extruderModel.activeMaterial != null
  366. anchors.left: parent.left
  367. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  368. anchors.verticalCenter: materialName.verticalCenter
  369. MouseArea //For tooltip.
  370. {
  371. id: materialColorTooltipArea
  372. hoverEnabled: true
  373. anchors.fill: parent
  374. onHoveredChanged:
  375. {
  376. if (containsMouse)
  377. {
  378. base.showTooltip(
  379. base,
  380. {x: 0, y: parent.mapToItem(base, 0, -parent.height / 2).y},
  381. catalog.i18nc("@tooltip", "The colour of the material in this extruder.")
  382. );
  383. }
  384. else
  385. {
  386. base.hideTooltip();
  387. }
  388. }
  389. }
  390. }
  391. Label //Material name.
  392. {
  393. id: materialName
  394. text: extruderModel.activeMaterial != null ? extruderModel.activeMaterial.type : ""
  395. font: UM.Theme.getFont("default")
  396. color: UM.Theme.getColor("text")
  397. anchors.left: materialColor.right
  398. anchors.bottom: parent.bottom
  399. anchors.margins: UM.Theme.getSize("default_margin").width
  400. MouseArea //For tooltip.
  401. {
  402. id: materialNameTooltipArea
  403. hoverEnabled: true
  404. anchors.fill: parent
  405. onHoveredChanged:
  406. {
  407. if (containsMouse)
  408. {
  409. base.showTooltip(
  410. base,
  411. {x: 0, y: parent.mapToItem(base, 0, 0).y},
  412. catalog.i18nc("@tooltip", "The material in this extruder.")
  413. );
  414. }
  415. else
  416. {
  417. base.hideTooltip();
  418. }
  419. }
  420. }
  421. }
  422. Label //Variant name.
  423. {
  424. id: variantName
  425. text: extruderModel.hotendID
  426. font: UM.Theme.getFont("default")
  427. color: UM.Theme.getColor("text")
  428. anchors.right: parent.right
  429. anchors.bottom: parent.bottom
  430. anchors.margins: UM.Theme.getSize("default_margin").width
  431. MouseArea //For tooltip.
  432. {
  433. id: variantNameTooltipArea
  434. hoverEnabled: true
  435. anchors.fill: parent
  436. onHoveredChanged:
  437. {
  438. if (containsMouse)
  439. {
  440. base.showTooltip(
  441. base,
  442. {x: 0, y: parent.mapToItem(base, 0, -parent.height / 4).y},
  443. catalog.i18nc("@tooltip", "The nozzle inserted in this extruder.")
  444. );
  445. }
  446. else
  447. {
  448. base.hideTooltip();
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }