ExtruderBox.qml 18 KB

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