Debian Codegraph @

qml/LottieAnimation.qml

raw
1 /*
2 * Copyright (C) 2021 Michele Castellazzi
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * rlottie-qml is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QLottieFrameProvider 1.0
18 import QtMultimedia 5.12
19 import QtQuick 2.7
20
21 Item {
22 id: lottieItem
23 property alias source: frameProvider.source
24 property alias play: frameProvider.play
25 function next() {
26 frameProvider.requestFrame()
27 }
28
29 QLottieFrameProvider {
30 id: frameProvider
31 property bool play: false
32 width: videoOutput.width
33 onWidthChanged: requestFrame(play)
34 height: videoOutput.height
35 onHeightChanged: requestFrame(play)
36 onPlayChanged: if (play) { requestFrame() }
37 onFramePresented: if (play) { requestFrame() }
38 }
39
40 VideoOutput {
41 id: videoOutput
42 source: frameProvider
43 anchors.fill: parent
44 }
45
46 ShaderEffect {
47 id: removeBackground
48 anchors.fill: videoOutput
49 property variant source: ShaderEffectSource { sourceItem: videoOutput; hideSource: true }
50
51 fragmentShader: "
52 varying highp vec2 qt_TexCoord0;
53 uniform sampler2D source;
54 uniform lowp float qt_Opacity;
55 void main() {
56 lowp vec4 sourceColor = texture2D(source, qt_TexCoord0);
57 gl_FragColor = sourceColor * qt_Opacity;
58 }"
59 }
60 Component.onCompleted: frameProvider.requestFrame()
61 }