PrinterInfoBlock.qml 16 KB

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