MonitorPrintJobCard.qml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.0
  5. import UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. /**
  8. * A Print Job Card is essentially just a filled-in Expandable Card item. All
  9. * data within it is derived from being passed a printJob property.
  10. *
  11. * NOTE: For most labels, a fixed height with vertical alignment is used to make
  12. * layouts more deterministic (like the fixed-size textboxes used in original
  13. * mock-ups). This is also a stand-in for CSS's 'line-height' property. Denoted
  14. * with '// FIXED-LINE-HEIGHT:'.
  15. */
  16. Item
  17. {
  18. id: base
  19. // The print job which all other data is derived from
  20. property var printJob: null
  21. width: parent.width
  22. height: childrenRect.height
  23. ExpandableCard
  24. {
  25. enabled: printJob != null
  26. borderColor: printJob && printJob.configurationChanges.length !== 0 ? UM.Theme.getColor("warning") : UM.Theme.getColor("monitor_card_border")
  27. headerItem: Row
  28. {
  29. height: Math.round(48 * screenScaleFactor) // TODO: Theme!
  30. anchors.left: parent.left
  31. anchors.leftMargin: Math.round(24 * screenScaleFactor) // TODO: Theme!
  32. spacing: Math.round(18 * screenScaleFactor) // TODO: Theme!
  33. MonitorPrintJobPreview
  34. {
  35. printJob: base.printJob
  36. size: Math.round(32 * screenScaleFactor) // TODO: Theme!
  37. anchors.verticalCenter: parent.verticalCenter
  38. }
  39. Item
  40. {
  41. anchors.verticalCenter: parent.verticalCenter
  42. height: Math.round(18 * screenScaleFactor) // TODO: Theme!
  43. width: UM.Theme.getSize("monitor_column").width
  44. Rectangle
  45. {
  46. color: UM.Theme.getColor("monitor_skeleton_loading")
  47. width: Math.round(parent.width / 2)
  48. height: parent.height
  49. visible: !printJob
  50. radius: 2 * screenScaleFactor // TODO: Theme!
  51. }
  52. UM.Label
  53. {
  54. text: printJob && printJob.name ? printJob.name : ""
  55. elide: Text.ElideRight
  56. font: UM.Theme.getFont("medium") // 14pt, regular
  57. visible: printJob
  58. // FIXED-LINE-HEIGHT:
  59. width: parent.width
  60. height: parent.height
  61. }
  62. }
  63. Item
  64. {
  65. anchors.verticalCenter: parent.verticalCenter
  66. height: Math.round(18 * screenScaleFactor) // TODO: Theme!
  67. width: UM.Theme.getSize("monitor_column").width
  68. Rectangle
  69. {
  70. color: UM.Theme.getColor("monitor_skeleton_loading")
  71. width: Math.round(parent.width / 3)
  72. height: parent.height
  73. visible: !printJob
  74. radius: 2 * screenScaleFactor // TODO: Theme!
  75. }
  76. UM.Label
  77. {
  78. text: printJob ? OutputDevice.formatDuration(printJob.timeTotal) : ""
  79. elide: Text.ElideRight
  80. font: UM.Theme.getFont("medium") // 14pt, regular
  81. visible: printJob
  82. // FIXED-LINE-HEIGHT:
  83. height: Math.round(18 * screenScaleFactor) // TODO: Theme!
  84. }
  85. }
  86. Item
  87. {
  88. anchors.verticalCenter: parent.verticalCenter
  89. height: Math.round(18 * screenScaleFactor) // TODO: This should be childrenRect.height but QML throws warnings
  90. width: childrenRect.width
  91. Rectangle
  92. {
  93. color: UM.Theme.getColor("monitor_skeleton_loading")
  94. width: Math.round(72 * screenScaleFactor) // TODO: Theme!
  95. height: parent.height
  96. visible: !printJob
  97. radius: 2 * screenScaleFactor // TODO: Theme!
  98. }
  99. UM.Label
  100. {
  101. id: printerAssignmentLabel
  102. anchors.verticalCenter: parent.verticalCenter
  103. elide: Text.ElideRight
  104. font: UM.Theme.getFont("medium") // 14pt, regular
  105. text: {
  106. if (printJob !== null)
  107. {
  108. if (printJob.assignedPrinter == null)
  109. {
  110. if (printJob.state == "error")
  111. {
  112. return catalog.i18nc("@label", "Unavailable printer");
  113. }
  114. return catalog.i18nc("@label", "First available");
  115. }
  116. return printJob.assignedPrinter.name;
  117. }
  118. return "";
  119. }
  120. visible: printJob
  121. width: Math.round(120 * screenScaleFactor) // TODO: Theme!
  122. // FIXED-LINE-HEIGHT:
  123. height: parent.height
  124. }
  125. Row
  126. {
  127. id: printerFamilyPills
  128. anchors
  129. {
  130. left: printerAssignmentLabel.right;
  131. leftMargin: Math.round(12 * screenScaleFactor) // TODO: Theme!
  132. verticalCenter: parent.verticalCenter
  133. }
  134. height: childrenRect.height
  135. spacing: Math.round(6 * screenScaleFactor) // TODO: Theme!
  136. visible: printJob
  137. MonitorPrinterPill
  138. {
  139. text: printJob ? printJob.configuration.printerType : ""
  140. }
  141. }
  142. }
  143. }
  144. drawerItem: Row
  145. {
  146. anchors
  147. {
  148. left: parent.left
  149. leftMargin: Math.round(74 * screenScaleFactor) // TODO: Theme!
  150. }
  151. height: Math.round(108 * screenScaleFactor) // TODO: Theme!
  152. spacing: Math.round(18 * screenScaleFactor) // TODO: Theme!
  153. MonitorPrinterConfiguration
  154. {
  155. id: printerConfiguration
  156. anchors.verticalCenter: parent.verticalCenter
  157. buildplate: {
  158. switch (printJob.assignedPrinter.buildplate) {
  159. case "glass":
  160. return catalog.i18nc("@label", "Glass");
  161. default:
  162. return null
  163. }
  164. }
  165. configurations: base.printJob ? base.printJob.configuration.extruderConfigurations : null
  166. height: Math.round(72 * screenScaleFactor) // TODO: Theme!
  167. }
  168. UM.Label
  169. {
  170. text: printJob && printJob.owner ? printJob.owner : ""
  171. elide: Text.ElideRight
  172. font: UM.Theme.getFont("medium") // 14pt, regular
  173. anchors.top: printerConfiguration.top
  174. // FIXED-LINE-HEIGHT:
  175. height: Math.round(18 * screenScaleFactor) // TODO: Theme!
  176. }
  177. }
  178. }
  179. MonitorContextMenuButton
  180. {
  181. id: contextMenuButton
  182. anchors
  183. {
  184. right: parent.right
  185. rightMargin: Math.round(8 * screenScaleFactor) // TODO: Theme!
  186. top: parent.top
  187. topMargin: Math.round(8 * screenScaleFactor) // TODO: Theme!
  188. }
  189. width: Math.round(32 * screenScaleFactor) // TODO: Theme!
  190. height: Math.round(32 * screenScaleFactor) // TODO: Theme!
  191. enabled: OutputDevice.supportsPrintJobActions
  192. onClicked: enabled ? contextMenu.switchPopupState() : {}
  193. visible:
  194. {
  195. if(!printJob)
  196. {
  197. return false;
  198. }
  199. if(!contextMenu.hasItems)
  200. {
  201. return false;
  202. }
  203. var states = ["queued", "error", "sent_to_printer", "pre_print", "printing", "pausing", "paused", "resuming"];
  204. return states.indexOf(printJob.state) !== -1;
  205. }
  206. }
  207. MonitorContextMenu
  208. {
  209. id: contextMenu
  210. printJob: base.printJob ? base.printJob : null
  211. target: contextMenuButton
  212. }
  213. // For cloud printing, add this mouse area over the disabled contextButton to indicate that it's not available
  214. MouseArea
  215. {
  216. id: contextMenuDisabledButtonArea
  217. anchors.fill: contextMenuButton
  218. hoverEnabled: contextMenuButton.visible && !contextMenuButton.enabled
  219. onEntered: contextMenuDisabledInfo.open()
  220. onExited: contextMenuDisabledInfo.close()
  221. enabled: !contextMenuButton.enabled
  222. }
  223. MonitorInfoBlurb
  224. {
  225. id: contextMenuDisabledInfo
  226. text: catalog.i18nc("@info", "Please update your printer's firmware to manage the queue remotely.")
  227. target: contextMenuButton
  228. }
  229. }