aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick3d/LightmapperOutputWindow.qml
blob: 75c9f1349d6e606d01c88e3088eb9004a392037b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Pane {
    id: root
    anchors.fill: parent

    property double totalProgress: 0
    property double totalTimeRemaining: 0
    property double totalTimeElapsed: 0

    function clearText() {
        textArea.clear();
    }

    function update(payload) {
        if (payload["message"]) {
            textArea.insert(textArea.length, payload["message"] + "\n")
        }
        if (payload["totalProgress"]) {
            root.totalProgress = payload["totalProgress"];
        }
        if (payload["totalTimeRemaining"]) {
            root.totalTimeRemaining = payload["totalTimeRemaining"];
        }
        if (payload["totalTimeElapsed"]) {
            root.totalTimeElapsed = payload["totalTimeElapsed"]
        }
    }

    function formatDuration(milliseconds, showMilliseconds = true) {
        if (milliseconds < 0)
            return " Estimating..."
        const partSeconds = Math.floor(milliseconds / 1000) % 60;
        const partMinutes = Math.floor(milliseconds / 60000) % 60;
        const partHours = Math.floor(milliseconds / 3600000) % 60;

        if (partHours > 0) {
            return partHours + "h " + partMinutes + "m " + partSeconds + "s";
        }
        if (partMinutes > 0) {
            return partMinutes + "m " + partSeconds + "s";
        }
        if (partSeconds > 0) {
            return partSeconds + "s";
        }
        return "0s";
    }

    ColumnLayout {
        anchors.fill: parent

        ScrollView {
            Layout.fillWidth: true
            Layout.fillHeight: true
            TextArea {
                id: textArea
                readOnly: true
                placeholderText: qsTr("Qt Lightmapper")
                font.pixelSize: 12
                wrapMode: Text.WordWrap
            }
        }

        ProgressBar {
            Layout.fillWidth: true
            Layout.preferredHeight: 25
            value: root.totalProgress
        }

        RowLayout {
            //Layout.fillWidth: true
            Item {
                Layout.preferredWidth: 10
            }
            Label {
                text: (root.totalProgress * 100).toFixed(0) + "% complete"
            }
            Item {
                Layout.fillWidth: true
            }
            Label {
                text: "Remaining: " + root.formatDuration(root.totalTimeRemaining)
            }
            Item {
                Layout.fillWidth: true
            }
            Label {
                Layout.alignment: Qt.AlignRight
                text: "Elapsed: " + root.formatDuration(root.totalTimeElapsed)
            }
            Item {
                Layout.preferredWidth: 10
            }
        }

        Button {
            objectName: "cancelButton"
            Layout.fillWidth: true
            text: "Cancel"
        }
    }
}