PrinterInfoBlock.qml 14 KB

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