MonitorPrintJobCard.qml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. configurations: base.printJob ? base.printJob.configuration.extruderConfigurations : null
  158. height: Math.round(72 * screenScaleFactor) // TODO: Theme!
  159. }
  160. UM.Label
  161. {
  162. text: printJob && printJob.owner ? printJob.owner : ""
  163. elide: Text.ElideRight
  164. font: UM.Theme.getFont("medium") // 14pt, regular
  165. anchors.top: printerConfiguration.top
  166. // FIXED-LINE-HEIGHT:
  167. height: Math.round(18 * screenScaleFactor) // TODO: Theme!
  168. }
  169. }
  170. }
  171. MonitorContextMenuButton
  172. {
  173. id: contextMenuButton
  174. anchors
  175. {
  176. right: parent.right
  177. rightMargin: Math.round(8 * screenScaleFactor) // TODO: Theme!
  178. top: parent.top
  179. topMargin: Math.round(8 * screenScaleFactor) // TODO: Theme!
  180. }
  181. width: Math.round(32 * screenScaleFactor) // TODO: Theme!
  182. height: Math.round(32 * screenScaleFactor) // TODO: Theme!
  183. enabled: OutputDevice.supportsPrintJobActions
  184. onClicked: enabled ? contextMenu.switchPopupState() : {}
  185. visible:
  186. {
  187. if(!printJob)
  188. {
  189. return false;
  190. }
  191. if(!contextMenu.hasItems)
  192. {
  193. return false;
  194. }
  195. var states = ["queued", "error", "sent_to_printer", "pre_print", "printing", "pausing", "paused", "resuming"];
  196. return states.indexOf(printJob.state) !== -1;
  197. }
  198. }
  199. MonitorContextMenu
  200. {
  201. id: contextMenu
  202. printJob: base.printJob ? base.printJob : null
  203. target: contextMenuButton
  204. }
  205. // For cloud printing, add this mouse area over the disabled contextButton to indicate that it's not available
  206. MouseArea
  207. {
  208. id: contextMenuDisabledButtonArea
  209. anchors.fill: contextMenuButton
  210. hoverEnabled: contextMenuButton.visible && !contextMenuButton.enabled
  211. onEntered: contextMenuDisabledInfo.open()
  212. onExited: contextMenuDisabledInfo.close()
  213. enabled: !contextMenuButton.enabled
  214. }
  215. MonitorInfoBlurb
  216. {
  217. id: contextMenuDisabledInfo
  218. text: catalog.i18nc("@info", "Please update your printer's firmware to manage the queue remotely.")
  219. target: contextMenuButton
  220. }
  221. }