2023-04-09 13:35:35 +08:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-09-14 13:01:10 +08:00
|
|
|
import QtQuick
|
2023-05-19 10:08:36 +08:00
|
|
|
import Fk
|
2022-04-14 18:22:00 +08:00
|
|
|
|
|
|
|
Item {
|
2022-04-30 15:27:56 +08: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 18:11:41 +08:00
|
|
|
property bool keepAtStop: false
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
signal loaded()
|
|
|
|
signal started()
|
|
|
|
signal finished()
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
id: root
|
|
|
|
width: childrenRect.width
|
|
|
|
height: childrenRect.height
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2023-02-21 13:44:24 +08:00
|
|
|
property string folder: source
|
2023-01-03 23:37:14 +08:00
|
|
|
property int fileModel
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
Repeater {
|
|
|
|
id: frames
|
|
|
|
model: fileModel
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
Image {
|
2023-02-21 13:44:24 +08:00
|
|
|
source: root.source + "/" + index
|
2022-04-30 15:27:56 +08:00
|
|
|
visible: false
|
|
|
|
onStatusChanged: {
|
|
|
|
if (status == Image.Ready) {
|
|
|
|
loadedFrameCount++;
|
2023-01-03 23:37:14 +08:00
|
|
|
if (loadedFrameCount == fileModel)
|
2022-04-30 15:27:56 +08:00
|
|
|
root.loaded();
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
onLoaded: {
|
2023-01-29 18:11:41 +08:00
|
|
|
if (autoStart) {
|
|
|
|
root.started();
|
2022-04-30 15:27:56 +08:00
|
|
|
timer.start();
|
2023-01-29 18:11:41 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
interval: 50
|
|
|
|
repeat: true
|
|
|
|
onTriggered: {
|
2023-01-03 23:37:14 +08:00
|
|
|
if (currentFrame >= fileModel) {
|
2023-01-29 18:11:41 +08:00
|
|
|
if (!keepAtStop) {
|
|
|
|
frames.itemAt(fileModel - 1).visible = false;
|
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
if (loop) {
|
|
|
|
currentFrame = 0;
|
|
|
|
} else {
|
|
|
|
timer.stop();
|
|
|
|
root.finished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
if (currentFrame > 0)
|
|
|
|
frames.itemAt(currentFrame - 1).visible = false;
|
|
|
|
frames.itemAt(currentFrame).visible = true;
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
currentFrame++;
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
function start()
|
|
|
|
{
|
2023-01-03 23:37:14 +08:00
|
|
|
if (loadedFrameCount == fileModel) {
|
2023-01-29 18:11:41 +08:00
|
|
|
root.started();
|
2022-04-30 15:27:56 +08:00
|
|
|
timer.start();
|
|
|
|
} else {
|
2023-01-29 18:11:41 +08:00
|
|
|
root.loaded.connect(() => {
|
|
|
|
root.started();
|
2022-04-30 15:27:56 +08:00
|
|
|
timer.start();
|
|
|
|
});
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|
2022-04-30 15:27:56 +08:00
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
|
2022-04-30 15:27:56 +08:00
|
|
|
function stop()
|
|
|
|
{
|
|
|
|
timer.stop();
|
|
|
|
}
|
2023-01-03 23:37:14 +08:00
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
fileModel = Backend.ls(folder).length;
|
|
|
|
}
|
2022-04-14 18:22:00 +08:00
|
|
|
}
|