ExtruderBox.qml 19 KB

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