PrinterInfoBlock.qml 16 KB

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