ExtruderBox.qml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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 extruder.")
  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.jobState == "printing" || connectedPrinter.jobState == "pre_print" || connectedPrinter.jobState == "resuming" || connectedPrinter.jobState == "pausing" || connectedPrinter.jobState == "paused" || connectedPrinter.jobState == "error" || connectedPrinter.jobState == "offline")
  123. {
  124. return false; //Printer is in a state where it can't react to pre-heating.
  125. }
  126. return true;
  127. }
  128. border.width: UM.Theme.getSize("default_lining").width
  129. 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")
  130. anchors.left: parent.left
  131. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  132. anchors.bottom: parent.bottom
  133. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  134. width: Math.floor(UM.Theme.getSize("setting_control").width * 0.75)
  135. height: UM.Theme.getSize("setting_control").height
  136. visible: extruderModel != null ? extruderModel.canPreHeatExtruders: true
  137. Rectangle //Highlight of input field.
  138. {
  139. anchors.fill: parent
  140. anchors.margins: UM.Theme.getSize("default_lining").width
  141. color: UM.Theme.getColor("setting_control_highlight")
  142. opacity: preheatTemperatureControl.hovered ? 1.0 : 0
  143. }
  144. MouseArea //Change cursor on hovering.
  145. {
  146. id: preheatTemperatureInputMouseArea
  147. hoverEnabled: true
  148. anchors.fill: parent
  149. cursorShape: Qt.IBeamCursor
  150. onHoveredChanged:
  151. {
  152. if (containsMouse)
  153. {
  154. base.showTooltip(
  155. base,
  156. {x: 0, y: preheatTemperatureInputMouseArea.mapToItem(base, 0, 0).y},
  157. catalog.i18nc("@tooltip of temperature input", "The temperature to pre-heat the extruder to.")
  158. );
  159. }
  160. else
  161. {
  162. base.hideTooltip();
  163. }
  164. }
  165. }
  166. TextInput
  167. {
  168. id: preheatTemperatureInput
  169. font: UM.Theme.getFont("default")
  170. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  171. selectByMouse: true
  172. maximumLength: 5
  173. enabled: parent.enabled
  174. validator: RegExpValidator { regExp: /^-?[0-9]{0,9}[.,]?[0-9]{0,10}$/ } //Floating point regex.
  175. anchors.left: parent.left
  176. anchors.leftMargin: UM.Theme.getSize("setting_unit_margin").width
  177. anchors.right: parent.right
  178. anchors.verticalCenter: parent.verticalCenter
  179. renderType: Text.NativeRendering
  180. Component.onCompleted:
  181. {
  182. if (!extruderTemperature.properties.value)
  183. {
  184. text = "";
  185. }
  186. else
  187. {
  188. text = extruderTemperature.properties.value;
  189. }
  190. }
  191. }
  192. }
  193. Button //The pre-heat button.
  194. {
  195. id: preheatButton
  196. height: UM.Theme.getSize("setting_control").height
  197. visible: extruderModel != null ? extruderModel.canPreHeatExtruders: true
  198. enabled:
  199. {
  200. if (!preheatTemperatureControl.enabled)
  201. {
  202. return false; //Not connected, not authenticated or printer is busy.
  203. }
  204. if (extruderModel.isPreheating)
  205. {
  206. return true;
  207. }
  208. if (extruderTemperature.properties.minimum_value != "None" && Math.floor(preheatTemperatureInput.text) < Math.floor(extruderTemperature.properties.minimum_value))
  209. {
  210. return false; //Target temperature too low.
  211. }
  212. if (extruderTemperature.properties.maximum_value != "None" && Math.floor(preheatTemperatureInput.text) > Math.floor(extruderTemperature.properties.maximum_value))
  213. {
  214. return false; //Target temperature too high.
  215. }
  216. if (Math.floor(preheatTemperatureInput.text) == 0)
  217. {
  218. return false; //Setting the temperature to 0 is not allowed (since that cancels the pre-heating).
  219. }
  220. return true; //Preconditions are met.
  221. }
  222. anchors.right: parent.right
  223. anchors.bottom: parent.bottom
  224. anchors.margins: UM.Theme.getSize("default_margin").width
  225. style: ButtonStyle {
  226. background: Rectangle
  227. {
  228. border.width: UM.Theme.getSize("default_lining").width
  229. implicitWidth: actualLabel.contentWidth + (UM.Theme.getSize("default_margin").width * 2)
  230. border.color:
  231. {
  232. if(!control.enabled)
  233. {
  234. return UM.Theme.getColor("action_button_disabled_border");
  235. }
  236. else if(control.pressed)
  237. {
  238. return UM.Theme.getColor("action_button_active_border");
  239. }
  240. else if(control.hovered)
  241. {
  242. return UM.Theme.getColor("action_button_hovered_border");
  243. }
  244. else
  245. {
  246. return UM.Theme.getColor("action_button_border");
  247. }
  248. }
  249. color:
  250. {
  251. if(!control.enabled)
  252. {
  253. return UM.Theme.getColor("action_button_disabled");
  254. }
  255. else if(control.pressed)
  256. {
  257. return UM.Theme.getColor("action_button_active");
  258. }
  259. else if(control.hovered)
  260. {
  261. return UM.Theme.getColor("action_button_hovered");
  262. }
  263. else
  264. {
  265. return UM.Theme.getColor("action_button");
  266. }
  267. }
  268. Behavior on color
  269. {
  270. ColorAnimation
  271. {
  272. duration: 50
  273. }
  274. }
  275. Label
  276. {
  277. id: actualLabel
  278. anchors.centerIn: parent
  279. color:
  280. {
  281. if(!control.enabled)
  282. {
  283. return UM.Theme.getColor("action_button_disabled_text");
  284. }
  285. else if(control.pressed)
  286. {
  287. return UM.Theme.getColor("action_button_active_text");
  288. }
  289. else if(control.hovered)
  290. {
  291. return UM.Theme.getColor("action_button_hovered_text");
  292. }
  293. else
  294. {
  295. return UM.Theme.getColor("action_button_text");
  296. }
  297. }
  298. font: UM.Theme.getFont("action_button")
  299. text:
  300. {
  301. if(extruderModel == null)
  302. {
  303. return ""
  304. }
  305. if(extruderModel.isPreheating )
  306. {
  307. return catalog.i18nc("@button Cancel pre-heating", "Cancel")
  308. } else
  309. {
  310. return catalog.i18nc("@button", "Pre-heat")
  311. }
  312. }
  313. }
  314. }
  315. }
  316. onClicked:
  317. {
  318. if (!extruderModel.isPreheating)
  319. {
  320. extruderModel.preheatExtruder(preheatTemperatureInput.text, 900);
  321. }
  322. else
  323. {
  324. extruderModel.cancelPreheatExtruder();
  325. }
  326. }
  327. onHoveredChanged:
  328. {
  329. if (hovered)
  330. {
  331. base.showTooltip(
  332. base,
  333. {x: 0, y: preheatButton.mapToItem(base, 0, 0).y},
  334. catalog.i18nc("@tooltip of pre-heat", "Heat the extruder in advance before printing. You can continue adjusting your print while it is heating, and you won't have to wait for the extruder to heat up when you're ready to print.")
  335. );
  336. }
  337. else
  338. {
  339. base.hideTooltip();
  340. }
  341. }
  342. }
  343. Rectangle //Material colour indication.
  344. {
  345. id: materialColor
  346. width: Math.floor(materialName.height * 0.75)
  347. height: Math.floor(materialName.height * 0.75)
  348. radius: width / 2
  349. color: extruderModel.activeMaterial ? extruderModel.activeMaterial.color: "#00000000"
  350. border.width: UM.Theme.getSize("default_lining").width
  351. border.color: UM.Theme.getColor("lining")
  352. visible: extruderModel.activeMaterial != null
  353. anchors.left: parent.left
  354. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  355. anchors.verticalCenter: materialName.verticalCenter
  356. MouseArea //For tooltip.
  357. {
  358. id: materialColorTooltipArea
  359. hoverEnabled: true
  360. anchors.fill: parent
  361. onHoveredChanged:
  362. {
  363. if (containsMouse)
  364. {
  365. base.showTooltip(
  366. base,
  367. {x: 0, y: parent.mapToItem(base, 0, -parent.height / 2).y},
  368. catalog.i18nc("@tooltip", "The colour of the material in this extruder.")
  369. );
  370. }
  371. else
  372. {
  373. base.hideTooltip();
  374. }
  375. }
  376. }
  377. }
  378. Label //Material name.
  379. {
  380. id: materialName
  381. text: extruderModel.activeMaterial != null ? extruderModel.activeMaterial.type : ""
  382. font: UM.Theme.getFont("default")
  383. color: UM.Theme.getColor("text")
  384. anchors.left: materialColor.right
  385. anchors.bottom: parent.bottom
  386. anchors.margins: UM.Theme.getSize("default_margin").width
  387. MouseArea //For tooltip.
  388. {
  389. id: materialNameTooltipArea
  390. hoverEnabled: true
  391. anchors.fill: parent
  392. onHoveredChanged:
  393. {
  394. if (containsMouse)
  395. {
  396. base.showTooltip(
  397. base,
  398. {x: 0, y: parent.mapToItem(base, 0, 0).y},
  399. catalog.i18nc("@tooltip", "The material in this extruder.")
  400. );
  401. }
  402. else
  403. {
  404. base.hideTooltip();
  405. }
  406. }
  407. }
  408. }
  409. Label //Variant name.
  410. {
  411. id: variantName
  412. text: extruderModel.hotendID
  413. font: UM.Theme.getFont("default")
  414. color: UM.Theme.getColor("text")
  415. anchors.right: parent.right
  416. anchors.bottom: parent.bottom
  417. anchors.margins: UM.Theme.getSize("default_margin").width
  418. MouseArea //For tooltip.
  419. {
  420. id: variantNameTooltipArea
  421. hoverEnabled: true
  422. anchors.fill: parent
  423. onHoveredChanged:
  424. {
  425. if (containsMouse)
  426. {
  427. base.showTooltip(
  428. base,
  429. {x: 0, y: parent.mapToItem(base, 0, -parent.height / 4).y},
  430. catalog.i18nc("@tooltip", "The nozzle inserted in this extruder.")
  431. );
  432. }
  433. else
  434. {
  435. base.hideTooltip();
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }