2022-09-14 05:01:10 +00:00
|
|
|
import QtQuick
|
2022-04-14 10:22:00 +00:00
|
|
|
import "../skin-bank.js" as SkinBank
|
|
|
|
|
|
|
|
Item {
|
2022-04-30 07:27:56 +00:00
|
|
|
property string source: ""
|
|
|
|
property int currentFrame: 0
|
|
|
|
property alias interval: timer.interval
|
|
|
|
property int loadedFrameCount: 0
|
|
|
|
property bool autoStart: false
|
|
|
|
property bool loop: false
|
2023-01-29 10:11:41 +00:00
|
|
|
property bool keepAtStop: false
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
signal loaded()
|
|
|
|
signal started()
|
|
|
|
signal finished()
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
id: root
|
|
|
|
width: childrenRect.width
|
|
|
|
height: childrenRect.height
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2023-02-21 05:44:24 +00:00
|
|
|
property string folder: source
|
2023-01-03 15:37:14 +00:00
|
|
|
property int fileModel
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
Repeater {
|
|
|
|
id: frames
|
|
|
|
model: fileModel
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
Image {
|
2023-02-21 05:44:24 +00:00
|
|
|
source: root.source + "/" + index
|
2022-04-30 07:27:56 +00:00
|
|
|
visible: false
|
|
|
|
onStatusChanged: {
|
|
|
|
if (status == Image.Ready) {
|
|
|
|
loadedFrameCount++;
|
2023-01-03 15:37:14 +00:00
|
|
|
if (loadedFrameCount == fileModel)
|
2022-04-30 07:27:56 +00:00
|
|
|
root.loaded();
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
onLoaded: {
|
2023-01-29 10:11:41 +00:00
|
|
|
if (autoStart) {
|
|
|
|
root.started();
|
2022-04-30 07:27:56 +00:00
|
|
|
timer.start();
|
2023-01-29 10:11:41 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
interval: 50
|
|
|
|
repeat: true
|
|
|
|
onTriggered: {
|
2023-01-03 15:37:14 +00:00
|
|
|
if (currentFrame >= fileModel) {
|
2023-01-29 10:11:41 +00:00
|
|
|
if (!keepAtStop) {
|
|
|
|
frames.itemAt(fileModel - 1).visible = false;
|
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
if (loop) {
|
|
|
|
currentFrame = 0;
|
|
|
|
} else {
|
|
|
|
timer.stop();
|
|
|
|
root.finished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
if (currentFrame > 0)
|
|
|
|
frames.itemAt(currentFrame - 1).visible = false;
|
|
|
|
frames.itemAt(currentFrame).visible = true;
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
currentFrame++;
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function start()
|
|
|
|
{
|
2023-01-03 15:37:14 +00:00
|
|
|
if (loadedFrameCount == fileModel) {
|
2023-01-29 10:11:41 +00:00
|
|
|
root.started();
|
2022-04-30 07:27:56 +00:00
|
|
|
timer.start();
|
|
|
|
} else {
|
2023-01-29 10:11:41 +00:00
|
|
|
root.loaded.connect(() => {
|
|
|
|
root.started();
|
2022-04-30 07:27:56 +00:00
|
|
|
timer.start();
|
|
|
|
});
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|
2022-04-30 07:27:56 +00:00
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
|
2022-04-30 07:27:56 +00:00
|
|
|
function stop()
|
|
|
|
{
|
|
|
|
timer.stop();
|
|
|
|
}
|
2023-01-03 15:37:14 +00:00
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
fileModel = Backend.ls(folder).length;
|
|
|
|
}
|
2022-04-14 10:22:00 +00:00
|
|
|
}
|