PrinterInfoBlock.qml 13 KB

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