Fluid 1.3.0
Material Design for QtQuick and Qml
Loading...
Searching...
No Matches
SmoothFadeLoader.qml
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2018 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
2// SPDX-License-Identifier: MPL-2.0
3
4import QtQuick
5
42Item {
43 id: root
44 Accessible.ignored: true
50 property url source
51
56 property int fadeDuration: 250
57
61 readonly property bool running: animation.running
62 onSourceChanged: {
63 animation.running = false;
64
65 if (__priv.currentLoader == loader1) {
66 __priv.currentLoader = loader2;
67 __priv.nextLoader = loader1;
68 } else {
69 __priv.currentLoader = loader1;
70 __priv.nextLoader = loader2;
71 }
72
73 __priv.currentLoader.source = sourceUrl;
74 __priv.currentLoader.opacity = 0;
75 __priv.currentLoader.z = 1;
76 __priv.nextLoader.z = 0;
77
78 if (__priv.firstTime) {
79 __priv.currentLoader.opacity = 1.0;
80 __priv.nextLoader.opacity = 0.0;
81 __priv.firstTime = false;
82 } else {
83 animation.running = true;
84 }
85 }
86
87 QtObject {
88 id: __priv
89
90 property bool firstTime: true
91 property Loader currentLoader: loader1
92 property Loader nextLoader: loader2
93 }
94
95 SequentialAnimation {
96 id: animation
97 running: false
98
99 NumberAnimation {
100 target: __priv.currentLoader
101 properties: "opacity"
102 from: 0.0
103 to: 1.0
104 duration: root.fadeDuration
105 easing.type: Easing.OutQuad
106 }
107
108 ScriptAction {
109 script: {
110 __priv.nextLoader.opacity = 0;
111 //__priv.nextLoader.source = "";
112 }
113 }
114 }
115
116 Loader {
117 id: loader1
118 anchors.fill: parent
119 z: 1
120 }
121
122 Loader {
123 id: loader2
124 anchors.fill: parent
125 z: 0
126 }
127}