PrinterCardProgressBar.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (c) 2018 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. ProgressBar {
  8. property var progress: {
  9. if (!printer || printer.activePrintJob == null) {
  10. return 0;
  11. }
  12. var result = printer.activePrintJob.timeElapsed / printer.activePrintJob.timeTotal;
  13. if (result > 1.0) {
  14. result = 1.0;
  15. }
  16. return result;
  17. }
  18. style: ProgressBarStyle {
  19. property var remainingTime: {
  20. if (!printer || printer.activePrintJob == null) {
  21. return 0;
  22. }
  23. /* Sometimes total minus elapsed is less than 0. Use Math.max() to prevent remaining
  24. time from ever being less than 0. Negative durations cause strange behavior such
  25. as displaying "-1h -1m". */
  26. return Math.max(printer.activePrintJob.timeTotal - printer.activePrintJob.timeElapsed, 0);
  27. }
  28. property var progressText: {
  29. if (printer === null ) {
  30. return "";
  31. }
  32. switch (printer.activePrintJob.state) {
  33. case "wait_cleanup":
  34. if (printer.activePrintJob.timeTotal > printer.activePrintJob.timeElapsed) {
  35. return catalog.i18nc("@label:status", "Aborted");
  36. }
  37. return catalog.i18nc("@label:status", "Finished");
  38. case "pre_print":
  39. case "sent_to_printer":
  40. return catalog.i18nc("@label:status", "Preparing");
  41. case "aborted":
  42. return catalog.i18nc("@label:status", "Aborted");
  43. case "wait_user_action":
  44. return catalog.i18nc("@label:status", "Aborted");
  45. case "pausing":
  46. return catalog.i18nc("@label:status", "Pausing");
  47. case "paused":
  48. return OutputDevice.formatDuration( remainingTime );
  49. case "resuming":
  50. return catalog.i18nc("@label:status", "Resuming");
  51. case "queued":
  52. return catalog.i18nc("@label:status", "Action required");
  53. default:
  54. return OutputDevice.formatDuration( remainingTime );
  55. }
  56. }
  57. background: Rectangle {
  58. color: UM.Theme.getColor("monitor_progress_background");
  59. implicitHeight: visible ? 24 : 0;
  60. implicitWidth: 100;
  61. }
  62. progress: Rectangle {
  63. id: progressItem;
  64. color: {
  65. if (! printer || !printer.activePrintJob) {
  66. return "black";
  67. }
  68. var state = printer.activePrintJob.state
  69. var inactiveStates = [
  70. "pausing",
  71. "paused",
  72. "resuming",
  73. "wait_cleanup"
  74. ];
  75. if (inactiveStates.indexOf(state) > -1 && remainingTime > 0) {
  76. return UM.Theme.getColor("monitor_progress_fill_inactive");
  77. } else {
  78. return UM.Theme.getColor("monitor_progress_fill");
  79. }
  80. }
  81. Label {
  82. id: progressLabel;
  83. anchors {
  84. left: parent.left;
  85. leftMargin: getTextOffset();
  86. }
  87. text: progressText;
  88. anchors.verticalCenter: parent.verticalCenter;
  89. color: progressItem.width + progressLabel.width < control.width ? UM.Theme.getColor("text") : UM.Theme.getColor("monitor_progress_fill_text");
  90. width: contentWidth;
  91. font: UM.Theme.getFont("default");
  92. }
  93. function getTextOffset() {
  94. if (progressItem.width + progressLabel.width + 16 < control.width) {
  95. return progressItem.width + UM.Theme.getSize("default_margin").width;
  96. } else {
  97. return progressItem.width - progressLabel.width - UM.Theme.getSize("default_margin").width;
  98. }
  99. }
  100. }
  101. }
  102. value: progress;
  103. width: parent.width;
  104. }