summaryrefslogtreecommitdiffstats
path: root/AnimatedPresentation.qml
blob: 0b1462be1864418eb035732ca16baff7f8dadf1c (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
import QtQuick 2.0
import Qt.labs.presentation 1.0

Presentation {

    id: deck

    width: 600
    height: 400


    property bool inTransition: false;

    property variant fromSlide;
    property variant toSlide;

    property int transitionTime: 2000;

    BackgroundSwirls {}

    ShaderEffectItem {
        id: effect
        anchors.fill: parent
        visible: deck.inTransition
        property variant source: ShaderEffectSource {
            sourceItem: fromSlide;
            smooth: true
            sourceRect: Qt.rect(-fromSlide.x, -fromSlide.y, parent.width, parent.height);
        }
        property real ratio: 0
        property real alpha: Math.pow(1 - ratio, 5);
        property real amplitude: 0.1 * ratio
        property real frequency: 20
        property real time: 0
        NumberAnimation on time { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 3000 }
        fragmentShader:
            "uniform highp float amplitude;" +
            "uniform highp float frequency;" +
            "uniform highp float time;" +
            "uniform lowp float ratio;" +
            "uniform lowp float alpha;" +
            "uniform sampler2D source;" +
            "varying highp vec2 qt_TexCoord0;" +
            "void main() {" +
            "    highp vec2 p = sin(time + frequency * qt_TexCoord0);" +
            "    gl_FragColor = texture2D(source, qt_TexCoord0 + amplitude * vec2(p.y, -p.x)) * alpha;" +
            "}"
    }

    SequentialAnimation {
        id: transition
        ScriptAction { script: {
                deck.inTransition = true
                fromSlide.opacity = 0
                toSlide.visible = true
            }
        }

        ParallelAnimation {
            NumberAnimation { target: effect; property: "ratio"; from: 0; to: 1; duration: deck.transitionTime; easing.type: Easing.InQuad }
            NumberAnimation { target: toSlide; property: "opacity"; from: 0; to: 1; duration: deck.transitionTime; easing.type: Easing.InQuart }
        }

        ScriptAction { script: {
                deck.inTransition = false
                fromSlide.visible = false
                fromSlide.opacity = 0
                toSlide.opacity = 1
            }
        }
    }

    function switchSlides(from, to)
    {
        if (deck.inTransition)
            return false

        deck.fromSlide = from
        deck.toSlide = to

        transition.running = true;

        return true
    }
}