ExtruderBox.qml 18 KB

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