PrinterInfoBlock.qml 16 KB

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