LightmapperOutputWindow.qml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright (C) 2023 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
  3. pragma ComponentBehavior: Bound
  4. import QtQuick
  5. import QtQuick.Controls
  6. import QtQuick.Layouts
  7. Pane {
  8. id: root
  9. anchors.fill: parent
  10. property double totalProgress: 0
  11. property int totalTimeRemaining: -1
  12. property string stage : "Preparing..."
  13. function clearText() {
  14. textArea.clear();
  15. }
  16. function update(payload) {
  17. if ("message" in payload && typeof payload.message === "string" && payload.message) {
  18. textArea.insert(textArea.length, payload.message + "\n");
  19. }
  20. if ("totalProgress" in payload && typeof payload.totalProgress === "number") {
  21. root.totalProgress = payload.totalProgress;
  22. }
  23. if ("totalTimeRemaining" in payload && typeof payload.totalTimeRemaining === "number") {
  24. root.totalTimeRemaining = payload.totalTimeRemaining;
  25. }
  26. if ("stage" in payload && typeof payload.stage === "string") {
  27. root.stage = payload.stage;
  28. }
  29. }
  30. function formatDuration(milliseconds, showMilliseconds = true) {
  31. if (milliseconds < 0)
  32. return " Estimating..."
  33. const partSeconds = Math.floor(milliseconds / 1000) % 60;
  34. const partMinutes = Math.floor(milliseconds / 60000) % 60;
  35. const partHours = Math.floor(milliseconds / 3600000) % 60;
  36. if (partHours > 0) {
  37. return partHours + "h " + partMinutes + "m " + partSeconds + "s";
  38. }
  39. if (partMinutes > 0) {
  40. return partMinutes + "m " + partSeconds + "s";
  41. }
  42. if (partSeconds > 0) {
  43. return partSeconds + "s";
  44. }
  45. return "0s";
  46. }
  47. ColumnLayout {
  48. anchors.fill: parent
  49. RowLayout {
  50. Label {
  51. padding: 0
  52. text: root.stage
  53. }
  54. Item {
  55. Layout.fillWidth: true
  56. }
  57. Label {
  58. padding: 0
  59. text: (root.totalProgress * 100).toFixed(0) + "%"
  60. }
  61. }
  62. ProgressBar {
  63. Layout.fillWidth: true
  64. value: root.totalProgress
  65. }
  66. RowLayout {
  67. Label {
  68. padding: 0
  69. text: totalTimeRemaining > 0 ? "Remaining: " + root.formatDuration(root.totalTimeRemaining) : ""
  70. }
  71. Item {
  72. Layout.fillWidth: true
  73. }
  74. }
  75. Frame {
  76. Layout.fillWidth: true
  77. Layout.fillHeight: true
  78. ScrollView {
  79. width: parent.width
  80. height: parent.height
  81. id: scroll
  82. TextArea {
  83. id: textArea
  84. width: parent.width
  85. height: parent.height
  86. readOnly: true
  87. placeholderText: qsTr("Qt Lightmapper")
  88. font.pixelSize: 12
  89. wrapMode: Text.WordWrap
  90. }
  91. }
  92. }
  93. Button {
  94. objectName: "cancelButton"
  95. Layout.fillWidth: true
  96. text: "Cancel"
  97. }
  98. }
  99. }