MonitorPrinterCard.qml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.3
  4. import QtQuick.Controls 2.0
  5. import QtQuick.Dialogs 1.1
  6. import UM 1.3 as UM
  7. import Cura 1.0 as Cura
  8. /**
  9. * A Printer Card is has two main components: the printer portion and the print job portion, the latter being paired in
  10. * the UI when a print job is paired a printer in-cluster.
  11. *
  12. * NOTE: For most labels, a fixed height with vertical alignment is used to make layouts more deterministic (like the
  13. * fixed-size textboxes used in original 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 printer which all printer data is derived from
  20. property var printer: null
  21. property var borderSize: 1 * screenScaleFactor // TODO: Theme, and remove from here
  22. // If the printer card's controls are enabled. This is used by the carousel to prevent opening the context menu or
  23. // camera while the printer card is not "in focus"
  24. property var enabled: true
  25. // If the printer is a cloud printer or not. Other items base their enabled state off of this boolean. In the future
  26. // they might not need to though.
  27. property bool cloudConnection: Cura.MachineManager.activeMachineIsUsingCloudConnection
  28. width: 834 * screenScaleFactor // TODO: Theme!
  29. height: childrenRect.height
  30. Rectangle
  31. {
  32. id: background
  33. anchors.fill: parent
  34. color: UM.Theme.getColor("monitor_card_background")
  35. border
  36. {
  37. color: UM.Theme.getColor("monitor_card_border")
  38. width: borderSize // TODO: Remove once themed
  39. }
  40. radius: 2 * screenScaleFactor // TODO: Theme!
  41. }
  42. // Printer portion
  43. Item
  44. {
  45. id: printerInfo
  46. width: parent.width
  47. height: 144 * screenScaleFactor // TODO: Theme!
  48. Row
  49. {
  50. anchors
  51. {
  52. left: parent.left
  53. leftMargin: 36 * screenScaleFactor // TODO: Theme!
  54. verticalCenter: parent.verticalCenter
  55. }
  56. spacing: 18 * screenScaleFactor // TODO: Theme!
  57. Rectangle
  58. {
  59. id: printerImage
  60. width: 108 * screenScaleFactor // TODO: Theme!
  61. height: 108 * screenScaleFactor // TODO: Theme!
  62. color: printer ? "transparent" : UM.Theme.getColor("monitor_skeleton_loading")
  63. radius: 8 // TODO: Theme!
  64. Image
  65. {
  66. anchors.fill: parent
  67. fillMode: Image.PreserveAspectFit
  68. source: printer ? "../png/" + printer.type + ".png" : ""
  69. mipmap: true
  70. }
  71. }
  72. Item
  73. {
  74. anchors
  75. {
  76. verticalCenter: parent.verticalCenter
  77. }
  78. width: 180 * screenScaleFactor // TODO: Theme!
  79. height: childrenRect.height
  80. Rectangle
  81. {
  82. id: printerNameLabel
  83. color: printer ? "transparent" : UM.Theme.getColor("monitor_skeleton_loading")
  84. height: 18 * screenScaleFactor // TODO: Theme!
  85. width: parent.width
  86. radius: 2 * screenScaleFactor // TODO: Theme!
  87. Label
  88. {
  89. text: printer && printer.name ? printer.name : ""
  90. color: UM.Theme.getColor("text")
  91. elide: Text.ElideRight
  92. font: UM.Theme.getFont("large") // 16pt, bold
  93. width: parent.width
  94. visible: printer
  95. // FIXED-LINE-HEIGHT:
  96. height: parent.height
  97. verticalAlignment: Text.AlignVCenter
  98. renderType: Text.NativeRendering
  99. }
  100. }
  101. Rectangle
  102. {
  103. color: UM.Theme.getColor("monitor_skeleton_loading")
  104. height: 18 * screenScaleFactor // TODO: Theme!
  105. radius: 2 * screenScaleFactor // TODO: Theme!
  106. visible: !printer
  107. width: 48 * screenScaleFactor // TODO: Theme!
  108. }
  109. MonitorPrinterPill
  110. {
  111. id: printerFamilyPill
  112. anchors
  113. {
  114. top: printerNameLabel.bottom
  115. topMargin: UM.Theme.getSize("narrow_margin").height
  116. left: printerNameLabel.left
  117. }
  118. text: printer ? printer.type : ""
  119. }
  120. Item
  121. {
  122. id: managePrinterLink
  123. anchors {
  124. top: printerFamilyPill.bottom
  125. topMargin: UM.Theme.getSize("narrow_margin").height
  126. }
  127. height: 18 * screenScaleFactor // TODO: Theme!
  128. width: childrenRect.width
  129. Label
  130. {
  131. id: managePrinterText
  132. anchors.verticalCenter: managePrinterLink.verticalCenter
  133. color: UM.Theme.getColor("text_link")
  134. font: UM.Theme.getFont("default")
  135. text: catalog.i18nc("@label link to Connect and Cloud interfaces", "Manage printer")
  136. renderType: Text.NativeRendering
  137. }
  138. UM.RecolorImage
  139. {
  140. id: externalLinkIcon
  141. anchors
  142. {
  143. left: managePrinterText.right
  144. leftMargin: UM.Theme.getSize("narrow_margin").width
  145. verticalCenter: managePrinterText.verticalCenter
  146. }
  147. color: UM.Theme.getColor("text_link")
  148. source: UM.Theme.getIcon("LinkExternal")
  149. width: 12 * screenScaleFactor
  150. height: 12 * screenScaleFactor
  151. }
  152. }
  153. MouseArea
  154. {
  155. anchors.fill: managePrinterLink
  156. onClicked: OutputDevice.openPrinterControlPanel()
  157. onEntered:
  158. {
  159. manageQueueText.font.underline = true
  160. }
  161. onExited:
  162. {
  163. manageQueueText.font.underline = false
  164. }
  165. }
  166. }
  167. MonitorPrinterConfiguration
  168. {
  169. id: printerConfiguration
  170. anchors.verticalCenter: parent.verticalCenter
  171. buildplate: printer ? catalog.i18nc("@label", "Glass") : null // 'Glass' as a default
  172. configurations:
  173. {
  174. var configs = []
  175. if (printer)
  176. {
  177. configs = configs.concat(printer.printerConfiguration.extruderConfigurations)
  178. }
  179. else
  180. {
  181. configs.push(null, null)
  182. }
  183. return configs
  184. }
  185. height: 72 * screenScaleFactor // TODO: Theme!te theRect's x property
  186. }
  187. }
  188. MonitorContextMenuButton
  189. {
  190. id: contextMenuButton
  191. anchors
  192. {
  193. right: parent.right
  194. rightMargin: 12 * screenScaleFactor // TODO: Theme!
  195. top: parent.top
  196. topMargin: 12 * screenScaleFactor // TODO: Theme!
  197. }
  198. width: 36 * screenScaleFactor // TODO: Theme!
  199. height: 36 * screenScaleFactor // TODO: Theme!
  200. enabled: OutputDevice.supportsPrintJobActions
  201. onClicked: enabled ? contextMenu.switchPopupState() : {}
  202. visible:
  203. {
  204. if (!printer || !printer.activePrintJob) {
  205. return false
  206. }
  207. var states = ["queued", "error", "sent_to_printer", "pre_print", "printing", "pausing", "paused", "resuming"]
  208. return states.indexOf(printer.activePrintJob.state) !== -1
  209. }
  210. }
  211. MonitorContextMenu
  212. {
  213. id: contextMenu
  214. printJob: printer ? printer.activePrintJob : null
  215. target: contextMenuButton
  216. }
  217. // For cloud printing, add this mouse area over the disabled contextButton to indicate that it's not available
  218. MouseArea
  219. {
  220. id: contextMenuDisabledButtonArea
  221. anchors.fill: contextMenuButton
  222. hoverEnabled: contextMenuButton.visible && !contextMenuButton.enabled
  223. onEntered: contextMenuDisabledInfo.open()
  224. onExited: contextMenuDisabledInfo.close()
  225. enabled: !contextMenuButton.enabled
  226. }
  227. MonitorInfoBlurb
  228. {
  229. id: contextMenuDisabledInfo
  230. text: catalog.i18nc("@info", "Please update your printer's firmware to manage the queue remotely.")
  231. target: contextMenuButton
  232. }
  233. CameraButton
  234. {
  235. id: cameraButton
  236. anchors
  237. {
  238. right: parent.right
  239. rightMargin: 20 * screenScaleFactor // TODO: Theme!
  240. bottom: parent.bottom
  241. bottomMargin: 20 * screenScaleFactor // TODO: Theme!
  242. }
  243. iconSource: "../svg/icons/CameraPhoto.svg"
  244. enabled: !cloudConnection
  245. visible: printer
  246. }
  247. // For cloud printing, add this mouse area over the disabled cameraButton to indicate that it's not available
  248. // Fix CURA-7637 to allow camera connections via cloud.
  249. MouseArea
  250. {
  251. id: cameraDisabledButtonArea
  252. anchors.fill: cameraButton
  253. hoverEnabled: cameraButton.visible && !cameraButton.enabled
  254. onEntered: cameraDisabledInfo.open()
  255. onExited: cameraDisabledInfo.close()
  256. enabled: !cameraButton.enabled
  257. }
  258. MonitorInfoBlurb
  259. {
  260. id: cameraDisabledInfo
  261. text: catalog.i18nc("@info", "Webcam feeds for cloud printers cannot be viewed from Ultimaker Cura." +
  262. " Click \"Manage printer\" to visit Ultimaker Digital Factory and view this webcam.")
  263. target: cameraButton
  264. }
  265. }
  266. // Divider
  267. Rectangle
  268. {
  269. anchors
  270. {
  271. top: printJobInfo.top
  272. left: printJobInfo.left
  273. right: printJobInfo.right
  274. }
  275. height: borderSize // Remove once themed
  276. color: background.border.color
  277. }
  278. // Print job portion
  279. Rectangle
  280. {
  281. id: printJobInfo
  282. anchors
  283. {
  284. top: printerInfo.bottom
  285. topMargin: -borderSize * screenScaleFactor // TODO: Theme!
  286. }
  287. border
  288. {
  289. color: printer && printer.activePrintJob && printer.activePrintJob.configurationChanges.length > 0 ? UM.Theme.getColor("warning") : "transparent" // TODO: Theme!
  290. width: borderSize // TODO: Remove once themed
  291. }
  292. color: "transparent" // TODO: Theme!
  293. height: 84 * screenScaleFactor + borderSize // TODO: Remove once themed
  294. width: parent.width
  295. Row
  296. {
  297. anchors
  298. {
  299. fill: parent
  300. topMargin: 12 * screenScaleFactor + borderSize // TODO: Theme!
  301. bottomMargin: 12 * screenScaleFactor // TODO: Theme!
  302. leftMargin: 36 * screenScaleFactor // TODO: Theme!
  303. }
  304. height: childrenRect.height
  305. spacing: 18 * screenScaleFactor // TODO: Theme!
  306. Label
  307. {
  308. id: printerStatus
  309. anchors
  310. {
  311. verticalCenter: parent.verticalCenter
  312. }
  313. color: printer ? UM.Theme.getColor("text") : UM.Theme.getColor("monitor_text_disabled")
  314. font: UM.Theme.getFont("large_bold") // 16pt, bold
  315. text: {
  316. if (!printer) {
  317. return catalog.i18nc("@label:status", "Loading...")
  318. }
  319. if (printer.state == "disabled")
  320. {
  321. return catalog.i18nc("@label:status", "Unavailable")
  322. }
  323. if (printer.state == "unreachable")
  324. {
  325. return catalog.i18nc("@label:status", "Unreachable")
  326. }
  327. if (!printer.activePrintJob && printer.state == "idle")
  328. {
  329. return catalog.i18nc("@label:status", "Idle")
  330. }
  331. if (!printer.activePrintJob && printer.state == "pre_print")
  332. {
  333. return catalog.i18nc("@label:status", "Preparing...")
  334. }
  335. if (!printer.activePrintJob && printer.state == "printing")
  336. {
  337. // The print job isn't quite updated yet.
  338. return catalog.i18nc("@label:status", "Printing")
  339. }
  340. return ""
  341. }
  342. visible: text !== ""
  343. renderType: Text.NativeRendering
  344. }
  345. Item
  346. {
  347. anchors
  348. {
  349. verticalCenter: parent.verticalCenter
  350. }
  351. width: printerImage.width
  352. height: 60 * screenScaleFactor // TODO: Theme!
  353. MonitorPrintJobPreview
  354. {
  355. anchors.centerIn: parent
  356. printJob: printer ? printer.activePrintJob : null
  357. size: parent.height
  358. }
  359. visible: printer && printer.activePrintJob && !printerStatus.visible
  360. }
  361. Item
  362. {
  363. anchors
  364. {
  365. verticalCenter: parent.verticalCenter
  366. }
  367. width: 180 * screenScaleFactor // TODO: Theme!
  368. height: printerNameLabel.height + printerFamilyPill.height + 6 * screenScaleFactor // TODO: Theme!
  369. visible: printer && printer.activePrintJob && !printerStatus.visible
  370. Label
  371. {
  372. id: printerJobNameLabel
  373. color: printer && printer.activePrintJob && printer.activePrintJob.isActive ? UM.Theme.getColor("text") : UM.Theme.getColor("monitor_text_disabled")
  374. elide: Text.ElideRight
  375. font: UM.Theme.getFont("large") // 16pt, bold
  376. text: printer && printer.activePrintJob ? printer.activePrintJob.name : catalog.i18nc("@label", "Untitled")
  377. width: parent.width
  378. // FIXED-LINE-HEIGHT:
  379. height: 18 * screenScaleFactor // TODO: Theme!
  380. verticalAlignment: Text.AlignVCenter
  381. renderType: Text.NativeRendering
  382. }
  383. Label
  384. {
  385. id: printerJobOwnerLabel
  386. anchors
  387. {
  388. top: printerJobNameLabel.bottom
  389. topMargin: UM.Theme.getSize("narrow_margin").height
  390. left: printerJobNameLabel.left
  391. }
  392. color: printer && printer.activePrintJob && printer.activePrintJob.isActive ? UM.Theme.getColor("text") : UM.Theme.getColor("monitor_text_disabled")
  393. elide: Text.ElideRight
  394. font: UM.Theme.getFont("default") // 12pt, regular
  395. text: printer && printer.activePrintJob ? printer.activePrintJob.owner : catalog.i18nc("@label", "Anonymous")
  396. width: parent.width
  397. // FIXED-LINE-HEIGHT:
  398. height: 18 * screenScaleFactor // TODO: Theme!
  399. verticalAlignment: Text.AlignVCenter
  400. renderType: Text.NativeRendering
  401. }
  402. }
  403. MonitorPrintJobProgressBar
  404. {
  405. anchors
  406. {
  407. verticalCenter: parent.verticalCenter
  408. }
  409. printJob: printer && printer.activePrintJob
  410. visible: printer && printer.activePrintJob && printer.activePrintJob.configurationChanges.length === 0 && !printerStatus.visible
  411. }
  412. Label
  413. {
  414. anchors
  415. {
  416. verticalCenter: parent.verticalCenter
  417. }
  418. font: UM.Theme.getFont("default")
  419. text: catalog.i18nc("@label:status", "Requires configuration changes")
  420. visible: printer && printer.activePrintJob && printer.activePrintJob.configurationChanges.length > 0 && !printerStatus.visible
  421. color: UM.Theme.getColor("text")
  422. // FIXED-LINE-HEIGHT:
  423. height: 18 * screenScaleFactor // TODO: Theme!
  424. verticalAlignment: Text.AlignVCenter
  425. renderType: Text.NativeRendering
  426. }
  427. }
  428. Button
  429. {
  430. id: detailsButton
  431. anchors
  432. {
  433. verticalCenter: parent.verticalCenter
  434. right: parent.right
  435. rightMargin: 18 * screenScaleFactor // TODO: Theme!
  436. }
  437. background: Rectangle
  438. {
  439. color: UM.Theme.getColor("monitor_secondary_button_shadow")
  440. radius: 2 * screenScaleFactor // Todo: Theme!
  441. Rectangle
  442. {
  443. anchors.fill: parent
  444. anchors.bottomMargin: 2 * screenScaleFactor // TODO: Theme!
  445. color: detailsButton.hovered ? UM.Theme.getColor("monitor_secondary_button_hover") : UM.Theme.getColor("monitor_secondary_button")
  446. radius: 2 * screenScaleFactor // Todo: Theme!
  447. }
  448. }
  449. contentItem: Label
  450. {
  451. anchors.fill: parent
  452. anchors.bottomMargin: 2 * screenScaleFactor // TODO: Theme!
  453. color: UM.Theme.getColor("monitor_secondary_button_text")
  454. font: UM.Theme.getFont("medium") // 14pt, regular
  455. text: catalog.i18nc("@action:button", "Details");
  456. verticalAlignment: Text.AlignVCenter
  457. horizontalAlignment: Text.AlignHCenter
  458. height: 18 * screenScaleFactor // TODO: Theme!
  459. renderType: Text.NativeRendering
  460. }
  461. implicitHeight: 32 * screenScaleFactor // TODO: Theme!
  462. implicitWidth: 96 * screenScaleFactor // TODO: Theme!
  463. visible: printer && printer.activePrintJob && printer.activePrintJob.configurationChanges.length > 0 && !printerStatus.visible
  464. onClicked: base.enabled ? overrideConfirmationDialog.open() : {}
  465. enabled: OutputDevice.supportsPrintJobActions
  466. }
  467. // For cloud printing, add this mouse area over the disabled details button to indicate that it's not available
  468. MouseArea
  469. {
  470. id: detailsButtonDisabledButtonArea
  471. anchors.fill: detailsButton
  472. hoverEnabled: detailsButton.visible && !detailsButton.enabled
  473. onEntered: overrideButtonDisabledInfo.open()
  474. onExited: overrideButtonDisabledInfo.close()
  475. enabled: !detailsButton.enabled
  476. }
  477. MonitorInfoBlurb
  478. {
  479. id: overrideButtonDisabledInfo
  480. text: catalog.i18nc("@info", "Please update your printer's firmware to manage the queue remotely.")
  481. target: detailsButton
  482. }
  483. }
  484. MonitorConfigOverrideDialog
  485. {
  486. id: overrideConfirmationDialog
  487. printer: base.printer
  488. }
  489. }