Skip to content

Commit

Permalink
ProjectPlayer: Add loading progress indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
adazem009 committed Dec 9, 2023
1 parent 9712c99 commit 3bf773f
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions ScratchCPPGui/ProjectPlayer.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import ScratchCPPGui

ProjectScene {
Expand All @@ -9,18 +11,30 @@ ProjectScene {
property alias turboMode: loader.turboMode
property alias cloneLimit: loader.cloneLimit
property alias spriteFencing: loader.spriteFencing
property bool showLoadingProgress: true
readonly property bool loading: priv.loading
readonly property int downloadedAssets: loader.downloadedAssets
readonly property int assetCount: loader.assetCount
signal loaded()
signal failedToLoad()

id: root
clip: true
onFileNameChanged: priv.loading = true;

QtObject {
id: priv
property bool loading: false
}

ProjectLoader {
id: loader
fileName: root.fileName
stageWidth: parent.width
stageHeight: parent.height
onLoadingFinished: {
priv.loading = false;

if(loadStatus)
loaded();
else
Expand Down Expand Up @@ -55,4 +69,44 @@ ProjectScene {
Component.onCompleted: modelData.renderedTarget = this
}
}

Loader {
anchors.fill: parent
active: showLoadingProgress && loading

sourceComponent: ColumnLayout {
anchors.fill: parent

Item { Layout.fillHeight: true }

BusyIndicator {
Layout.fillWidth: true
Layout.maximumWidth: 100
Layout.alignment: Qt.AlignHCenter
running: true
}

Label {
Layout.alignment: Qt.AlignHCenter
font.bold: true
font.pointSize: 12
text: {
if(loading)
return assetCount == downloadedAssets ? qsTr("Loading project...") : qsTr("Downloading assets... (%1 of %2)").arg(downloadedAssets).arg(assetCount);
else
return "";
}
}

ProgressBar {
Layout.fillWidth: true
from: 0
to: assetCount
value: downloadedAssets
indeterminate: assetCount == downloadedAssets
}

Item { Layout.fillHeight: true }
}
}
}

0 comments on commit 3bf773f

Please sign in to comment.