aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/flowview/FlowEffect.qml
blob: 08bafc00caff415d4dafa8f1241966e0399264b7 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Quick Designer Components.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.15
import QtQuick.Timeline 1.0

QtObject {
    id: root
    signal finished
    signal started
    signal reseted
    function reset() {
        /*
        if (root.duration === 0) {
            root.transitionView.__setupCurrentItem()
            return
        }*/

        /* We set the parents to the content items to apply effects */

        resetProperties()

        from.parent = transitionView.__fromContentItem
        to.parent = transitionView.__toContentItem
        root.progress = root.backwards ? 100 : 0

        enable()
        root.progress = -1
        root.progress = 0
    }

    property bool __aborted: false

    function enable() {
        timeline.enabled = true
        root.started()
    }

    function start() {
        anim.from = Math.min(root.progress, 100)
        anim.to = root.backwards ? 0 : 100
        anim.duration = root.duration * Math.abs(anim.to - anim.from) / 100

        root.__aborted = false

        anim.start()
    }

    function abort() {

        anim.from = root.progress
        anim.to = root.backwards ? 100 : 0

        anim.duration = root.duration * Math.abs(anim.from - anim.to) / 100

        root.__aborted = true
        anim.restart()

    }

    function stop() {
        anim.stop()
    }

    property Item from
    property Item to

    property Item transitionView

    property real duration: 250
    property alias easing: anim.easing

    property Timeline timeline: Timeline {

    }

    property real progress: 0

    property bool backwards: false

    property Binding timelineBinding: Binding {
        target: timeline
        property: "currentFrame"
        value: root.progress * 10
    }

    function resetProperties() {
        transitionView.__fromContentItem.opacity = 1
        transitionView.__fromContentItem.x = 0
        transitionView.__fromContentItem.y = 0
        transitionView.__fromContentItem.z = 0
        transitionView.__fromContentItem.scale = 1

        transitionView.__toContentItem.opacity = 1
        transitionView.__toContentItem.x = 0
        transitionView.__toContentItem.y = 0
        transitionView.__toContentItem.z = 0
        transitionView.__toContentItem.scale = 1
    }

    property PropertyAnimation __anim: PropertyAnimation {
        id: anim
        duration: 250
        loops: 1
        target: root
        property: "progress"
        onStopped: {
            timeline.enabled = false
            /* reset all typical properties */

            resetProperties()

            root.finished()

            if (!root.__aborted) {
                root.transitionView.__setupCurrentItem()
            } else {
                if (root.transitionView.nextItem) {
                    root.transitionView.nextItem.parent = transitionView.__stack
                    root.transitionView.nextItem = root.transitionView.currentItem
                }
                root.transitionView.__setupCurrentItem()
                root.transitionView.nextItem = null
            }

            root.progress = 0
        }
    }

}

/*##^##
Designer {
    D{i:0;autoSize:true;height:480;width:640}
}
##^##*/