PrinterInfoBlock.qml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. import QtQuick 2.2
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Controls.Styles 1.4
  4. import UM 1.3 as UM
  5. Rectangle
  6. {
  7. function strPadLeft(string, pad, length)
  8. {
  9. return (new Array(length + 1).join(pad) + string).slice(-length);
  10. }
  11. function getPrettyTime(time)
  12. {
  13. return OutputDevice.formatDuration(time)
  14. }
  15. function formatPrintJobPercent(printJob)
  16. {
  17. if (printJob == null)
  18. {
  19. return "";
  20. }
  21. if (printJob.time_total === 0)
  22. {
  23. return "";
  24. }
  25. return Math.min(100, Math.round(printJob.time_elapsed / printJob.time_total * 100)) + "%";
  26. }
  27. function printerStatusText(printer)
  28. {
  29. switch (printer.status)
  30. {
  31. case "pre_print":
  32. return catalog.i18nc("@label", "Preparing to print")
  33. case "printing":
  34. return catalog.i18nc("@label:status", "Printing");
  35. case "idle":
  36. return catalog.i18nc("@label:status", "Available");
  37. case "unreachable":
  38. return catalog.i18nc("@label:MonitorStatus", "Lost connection with the printer");
  39. case "maintenance": // TODO: new string
  40. case "unknown":
  41. default:
  42. return catalog.i18nc("@label", "Unknown");
  43. }
  44. }
  45. id: printerDelegate
  46. property var printer
  47. border.width: UM.Theme.getSize("default_lining").width
  48. border.color: mouse.containsMouse ? emphasisColor : lineColor
  49. z: mouse.containsMouse ? 1 : 0 // Push this item up a bit on mouse over to ensure that the highlighted bottom border is visible.
  50. property var printJob:
  51. {
  52. if (printer.reserved_by != null)
  53. {
  54. // Look in another list.
  55. return OutputDevice.printJobsByUUID[printer.reserved_by]
  56. }
  57. return OutputDevice.printJobsByPrinterUUID[printer.uuid]
  58. }
  59. MouseArea
  60. {
  61. id: mouse
  62. anchors.fill:parent
  63. onClicked: OutputDevice.selectPrinter(printer.unique_name, printer.friendly_name)
  64. hoverEnabled: true;
  65. // Only clickable if no printer is selected
  66. enabled: OutputDevice.selectedPrinterName == "" && printer.status !== "unreachable"
  67. }
  68. Row
  69. {
  70. anchors.left: parent.left
  71. anchors.right: parent.right
  72. anchors.top: parent.top
  73. anchors.bottom: parent.bottom
  74. anchors.margins: UM.Theme.getSize("default_margin").width
  75. Rectangle
  76. {
  77. width: parent.width / 3
  78. height: parent.height
  79. Label // Print job name
  80. {
  81. id: jobNameLabel
  82. anchors.top: parent.top
  83. anchors.left: parent.left
  84. anchors.right: parent.right
  85. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  86. text: printJob != null ? printJob.name : ""
  87. font: UM.Theme.getFont("default_bold")
  88. elide: Text.ElideRight
  89. }
  90. Label
  91. {
  92. id: jobOwnerLabel
  93. anchors.top: jobNameLabel.bottom
  94. anchors.left: parent.left
  95. anchors.right: parent.right
  96. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  97. text: printJob != null ? printJob.owner : ""
  98. opacity: 0.50
  99. elide: Text.ElideRight
  100. }
  101. Label
  102. {
  103. id: totalTimeLabel
  104. anchors.bottom: parent.bottom
  105. anchors.left: parent.left
  106. anchors.right: parent.right
  107. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  108. text: printJob != null ? getPrettyTime(printJob.time_total) : ""
  109. opacity: 0.65
  110. font: UM.Theme.getFont("default")
  111. elide: Text.ElideRight
  112. }
  113. }
  114. Rectangle
  115. {
  116. width: parent.width / 3 * 2
  117. height: parent.height
  118. Label // Friendly machine name
  119. {
  120. id: printerNameLabel
  121. anchors.top: parent.top
  122. anchors.left: parent.left
  123. width: parent.width / 2 - UM.Theme.getSize("default_margin").width - showCameraIcon.width
  124. text: printer.friendly_name
  125. font: UM.Theme.getFont("default_bold")
  126. elide: Text.ElideRight
  127. }
  128. Label // Machine variant
  129. {
  130. id: printerTypeLabel
  131. anchors.top: printerNameLabel.bottom
  132. width: parent.width / 2 - UM.Theme.getSize("default_margin").width
  133. text: printer.machine_variant
  134. anchors.left: parent.left
  135. elide: Text.ElideRight
  136. font: UM.Theme.getFont("very_small")
  137. opacity: 0.50
  138. }
  139. Rectangle // Camera icon
  140. {
  141. id: showCameraIcon
  142. width: 40 * screenScaleFactor
  143. height: width
  144. radius: width
  145. anchors.right: printProgressArea.left
  146. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  147. color: emphasisColor
  148. opacity: printer != null && printer.status === "unreachable" ? 0.3 : 1
  149. Image
  150. {
  151. width: parent.width
  152. height: width
  153. anchors.right: parent.right
  154. anchors.rightMargin: parent.rightMargin
  155. source: "camera-icon.svg"
  156. }
  157. }
  158. Row // PrintCore config
  159. {
  160. id: extruderInfo
  161. anchors.bottom: parent.bottom
  162. width: parent.width / 2 - UM.Theme.getSize("default_margin").width
  163. height: childrenRect.height
  164. spacing: UM.Theme.getSize("default_margin").width
  165. PrintCoreConfiguration
  166. {
  167. id: leftExtruderInfo
  168. width: Math.floor((parent.width - extruderSeperator.width) / 2)
  169. printCoreConfiguration: printer.configuration[0]
  170. }
  171. Rectangle
  172. {
  173. id: extruderSeperator
  174. width: UM.Theme.getSize("default_lining").width
  175. height: parent.height
  176. color: lineColor
  177. }
  178. PrintCoreConfiguration
  179. {
  180. id: rightExtruderInfo
  181. width: Math.floor((parent.width - extruderSeperator.width) / 2)
  182. printCoreConfiguration: printer.configuration[1]
  183. }
  184. }
  185. Rectangle // Print progress
  186. {
  187. id: printProgressArea
  188. anchors.right: parent.right
  189. anchors.top: parent.top
  190. height: showExtended ? parent.height: printProgressTitleBar.height
  191. width: parent.width / 2 - UM.Theme.getSize("default_margin").width
  192. border.width: UM.Theme.getSize("default_lining").width
  193. border.color: lineColor
  194. radius: cornerRadius
  195. property var showExtended: {
  196. if(printJob != null)
  197. {
  198. var extendStates = ["sent_to_printer", "wait_for_configuration", "printing", "pre_print", "post_print", "wait_cleanup", "queued"];
  199. return extendStates.indexOf(printJob.status) !== -1;
  200. }
  201. return !printer.enabled;
  202. }
  203. Item // Status and Percent
  204. {
  205. id: printProgressTitleBar
  206. property var showPercent: {
  207. return printJob != null && (["printing", "post_print", "pre_print", "sent_to_printer"].indexOf(printJob.status) !== -1);
  208. }
  209. width: parent.width
  210. //TODO: hardcoded value
  211. height: 40 * screenScaleFactor
  212. anchors.left: parent.left
  213. Label
  214. {
  215. id: statusText
  216. anchors.left: parent.left
  217. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  218. anchors.right: progressText.left
  219. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  220. anchors.verticalCenter: parent.verticalCenter
  221. text: {
  222. if (!printer.enabled)
  223. {
  224. return catalog.i18nc("@label:status", "Disabled");
  225. }
  226. if (printer.status === "unreachable")
  227. {
  228. return printerStatusText(printer);
  229. }
  230. if (printJob != null)
  231. {
  232. switch (printJob.status)
  233. {
  234. case "printing":
  235. case "post_print":
  236. return catalog.i18nc("@label:status", "Printing")
  237. case "wait_for_configuration":
  238. return catalog.i18nc("@label:status", "Reserved")
  239. case "wait_cleanup":
  240. return catalog.i18nc("@label:status", "Finished")
  241. case "pre_print":
  242. case "sent_to_printer":
  243. return catalog.i18nc("@label", "Preparing to print")
  244. case "queued":
  245. if (printJob.configuration_changes_required != null && printJob.configuration_changes_required.length !== 0)
  246. {
  247. return catalog.i18nc("@label:status", "Action required");
  248. }
  249. else
  250. {
  251. return "";
  252. }
  253. case "pausing":
  254. case "paused":
  255. return catalog.i18nc("@label:status", "Paused");
  256. case "resuming":
  257. return catalog.i18nc("@label:status", "Resuming");
  258. case "aborted":
  259. return catalog.i18nc("@label:status", "Print aborted");
  260. default:
  261. return printerStatusText(printer);
  262. }
  263. }
  264. return printerStatusText(printer);
  265. }
  266. elide: Text.ElideRight
  267. font: UM.Theme.getFont("small")
  268. }
  269. Label
  270. {
  271. id: progressText
  272. anchors.right: parent.right
  273. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  274. anchors.top: statusText.top
  275. text: formatPrintJobPercent(printJob)
  276. visible: printProgressTitleBar.showPercent
  277. //TODO: Hardcoded value
  278. opacity: 0.65
  279. font: UM.Theme.getFont("very_small")
  280. }
  281. Image
  282. {
  283. width: statusText.height
  284. height: width
  285. anchors.right: parent.right
  286. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  287. anchors.top: statusText.top
  288. visible: !printProgressTitleBar.showPercent
  289. source: {
  290. if (!printer.enabled)
  291. {
  292. return "blocked-icon.svg";
  293. }
  294. if (printer.status === "unreachable")
  295. {
  296. return "";
  297. }
  298. if (printJob != null)
  299. {
  300. if(printJob.status === "queued")
  301. {
  302. if (printJob.configuration_changes_required != null && printJob.configuration_changes_required.length !== 0)
  303. {
  304. return "action-required-icon.svg";
  305. }
  306. }
  307. else if (printJob.status === "wait_cleanup")
  308. {
  309. return "checkmark-icon.svg";
  310. }
  311. }
  312. return ""; // We're not going to show it, so it will not be resolved as a url.
  313. }
  314. }
  315. Rectangle
  316. {
  317. //TODO: This will become a progress bar in the future
  318. width: parent.width
  319. height: UM.Theme.getSize("default_lining").height
  320. anchors.bottom: parent.bottom
  321. anchors.left: parent.left
  322. visible: printProgressArea.showExtended
  323. color: lineColor
  324. }
  325. }
  326. Column
  327. {
  328. anchors.left: parent.left
  329. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  330. anchors.top: printProgressTitleBar.bottom
  331. anchors.topMargin: UM.Theme.getSize("default_margin").height
  332. width: parent.width - 2 * UM.Theme.getSize("default_margin").width
  333. visible: printProgressArea.showExtended
  334. Label // Status detail
  335. {
  336. text:
  337. {
  338. if (!printer.enabled)
  339. {
  340. return catalog.i18nc("@label", "Not accepting print jobs");
  341. }
  342. if (printer.status === "unreachable")
  343. {
  344. return "";
  345. }
  346. if(printJob != null)
  347. {
  348. switch (printJob.status)
  349. {
  350. case "printing":
  351. case "post_print":
  352. return catalog.i18nc("@label", "Finishes at: ") + OutputDevice.getTimeCompleted(printJob.time_total - printJob.time_elapsed)
  353. case "wait_cleanup":
  354. return catalog.i18nc("@label", "Clear build plate")
  355. case "sent_to_printer":
  356. case "pre_print":
  357. return catalog.i18nc("@label", "Preparing to print")
  358. case "wait_for_configuration":
  359. return catalog.i18nc("@label", "Not accepting print jobs")
  360. case "queued":
  361. if (printJob.configuration_changes_required != undefined)
  362. {
  363. return catalog.i18nc("@label", "Waiting for configuration change");
  364. }
  365. default:
  366. return "";
  367. }
  368. }
  369. return "";
  370. }
  371. anchors.left: parent.left
  372. anchors.right: parent.right
  373. elide: Text.ElideRight
  374. wrapMode: Text.Wrap
  375. font: UM.Theme.getFont("default")
  376. }
  377. Label // Status 2nd row
  378. {
  379. text: {
  380. if(printJob != null)
  381. {
  382. if(printJob.status == "printing" || printJob.status == "post_print")
  383. {
  384. return OutputDevice.getDateCompleted(printJob.time_total - printJob.time_elapsed)
  385. }
  386. }
  387. return "";
  388. }
  389. elide: Text.ElideRight
  390. font: UM.Theme.getFont("default")
  391. }
  392. }
  393. }
  394. }
  395. }
  396. }