MonitorPrintJobProgressBar.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.Styles 1.3
  5. import QtQuick.Controls 1.4
  6. import UM 1.3 as UM
  7. /**
  8. * NOTE: For most labels, a fixed height with vertical alignment is used to make
  9. * layouts more deterministic (like the fixed-size textboxes used in original
  10. * mock-ups). This is also a stand-in for CSS's 'line-height' property. Denoted
  11. * with '// FIXED-LINE-HEIGHT:'.
  12. */
  13. Item
  14. {
  15. id: base
  16. // The print job which all other information is derived from
  17. property var printJob: null
  18. width: childrenRect.width
  19. height: UM.Theme.getSize("monitor_text_line").height
  20. UM.ProgressBar
  21. {
  22. id: progressBar
  23. anchors
  24. {
  25. verticalCenter: parent.verticalCenter
  26. left: parent.left
  27. }
  28. value: printJob ? printJob.progress : 0
  29. width: UM.Theme.getSize("monitor_progress_bar").width
  30. }
  31. Label
  32. {
  33. id: percentLabel
  34. anchors
  35. {
  36. left: progressBar.right
  37. leftMargin: UM.Theme.getSize("monitor_margin").width
  38. verticalCenter: parent.verticalCenter
  39. }
  40. text: printJob ? Math.round(printJob.progress * 100) + "%" : "0%"
  41. color: printJob && printJob.isActive ? UM.Theme.getColor("text") : UM.Theme.getColor("monitor_text_disabled")
  42. width: contentWidth
  43. font: UM.Theme.getFont("default") // 12pt, regular
  44. // FIXED-LINE-HEIGHT:
  45. height: UM.Theme.getSize("monitor_text_line").height
  46. verticalAlignment: Text.AlignVCenter
  47. renderType: Text.NativeRendering
  48. }
  49. Label
  50. {
  51. id: statusLabel
  52. anchors
  53. {
  54. left: percentLabel.right
  55. leftMargin: UM.Theme.getSize("monitor_margin").width
  56. verticalCenter: parent.verticalCenter
  57. }
  58. color: UM.Theme.getColor("text")
  59. font: UM.Theme.getFont("default")
  60. text:
  61. {
  62. if (!printJob)
  63. {
  64. return "";
  65. }
  66. switch (printJob.state)
  67. {
  68. case "wait_cleanup":
  69. // This hack was removed previously. Then we found out that we don't get back 'aborted_wait_cleanup'
  70. // for the UM2+C it seems. Will communicate this to other teams, in the mean time, put this back.
  71. if (printJob.timeTotal > printJob.timeElapsed)
  72. {
  73. return catalog.i18nc("@label:status", "Aborted");
  74. }
  75. return catalog.i18nc("@label:status", "Finished");
  76. case "finished":
  77. return catalog.i18nc("@label:status", "Finished");
  78. case "sent_to_printer":
  79. return catalog.i18nc("@label:status", "Preparing...");
  80. case "pre_print":
  81. return catalog.i18nc("@label:status", "Preparing...");
  82. case "aborting": // NOTE: Doesn't exist but maybe should someday
  83. return catalog.i18nc("@label:status", "Aborting...");
  84. case "aborted": // NOTE: Unused, see above
  85. return catalog.i18nc("@label:status", "Aborted");
  86. case "aborted_post_print":
  87. return catalog.i18nc("@label:status", "Aborted");
  88. case "aborted_wait_user_action":
  89. return catalog.i18nc("@label:status", "Aborted");
  90. case "aborted_wait_cleanup":
  91. return catalog.i18nc("@label:status", "Aborted");
  92. case "failed":
  93. return catalog.i18nc("@label:status", "Failed");
  94. case "failed_post_print":
  95. return catalog.i18nc("@label:status", "Failed");
  96. case "failed_wait_user_action":
  97. return catalog.i18nc("@label:status", "Failed");
  98. case "failed_wait_cleanup":
  99. return catalog.i18nc("@label:status", "Failed");
  100. case "pausing":
  101. return catalog.i18nc("@label:status", "Pausing...");
  102. case "paused":
  103. return catalog.i18nc("@label:status", "Paused");
  104. case "resuming":
  105. return catalog.i18nc("@label:status", "Resuming...");
  106. case "queued":
  107. return catalog.i18nc("@label:status", "Action required");
  108. default:
  109. return catalog.i18nc("@label:status", "Finishes %1 at %2").arg(OutputDevice.getDateCompleted(printJob.timeRemaining)).arg(OutputDevice.getTimeCompleted(printJob.timeRemaining));
  110. }
  111. }
  112. width: contentWidth
  113. // FIXED-LINE-HEIGHT:
  114. height: UM.Theme.getSize("monitor_text_line").height
  115. verticalAlignment: Text.AlignVCenter
  116. renderType: Text.NativeRendering
  117. }
  118. }