1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the examples of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 ** the names of its contributors may be used to endorse or promote
22 ** products derived from this software without specific prior written
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
45 property int animDuration: 300
46 property Item front: Item {}
47 property Item back: Item {}
48 property real factor: 0.1 // amount the edges fold in for the 3D effect
49 property alias delta: effect.delta
50 property Item cur: frontShown ? front : back
51 property Item noncur: frontShown ? back : front
62 onFrontChanged: resync();
63 onBackChanged: resync();
65 function resync() {//TODO: Are the items ever actually visible?
66 back.parent = container;
67 front.parent = container;
68 frontShown ? back.visible = false : front.visible = false;
71 property bool frontShown: true
73 onFrontShownChanged: {
74 back.visible = !frontShown
75 front.visible = frontShown
83 function flipUp(start) {
84 effect.visible = true;
85 effect.sourceA = effect.source1
86 effect.sourceB = effect.source2
87 if (start == undefined)
89 deltaAnim.from = start;
95 function flipDown(start) {
96 effect.visible = true;
97 effect.sourceA = effect.source1
98 effect.sourceB = effect.source2
99 if (start == undefined)
101 deltaAnim.from = start;
111 property real factor: container.factor * width
112 property real delta: 1.0
114 mesh: GridMesh { resolution: Qt.size(8,2) }
116 SequentialAnimation on delta {
121 duration: animDuration//expose anim
125 property variant sourceA: source1
126 property variant sourceB: source1
127 property variant source1: ShaderEffectSource {
129 hideSource: effect.visible
132 property variant source2: ShaderEffectSource {
134 hideSource: effect.visible
138 uniform lowp float qt_Opacity;
139 uniform sampler2D sourceA;
140 uniform sampler2D sourceB;
141 uniform highp float delta;
142 varying highp vec2 qt_TexCoord0;
144 highp vec4 tex = vec4(qt_TexCoord0.x, qt_TexCoord0.y * 2.0, qt_TexCoord0.x, (qt_TexCoord0.y-0.5) * 2.0);
145 highp float shade = clamp(delta*2.0, 0.5, 1.0);
147 if (qt_TexCoord0.y < 0.5) {
148 col = texture2D(sourceA, tex.xy) * (shade);
150 col = texture2D(sourceB, tex.zw) * (1.5 - shade);
153 gl_FragColor = col * qt_Opacity;
156 property real h: height
158 uniform highp float delta;
159 uniform highp float factor;
160 uniform highp float h;
161 uniform highp mat4 qt_Matrix;
162 attribute highp vec4 qt_Vertex;
163 attribute highp vec2 qt_MultiTexCoord0;
164 varying highp vec2 qt_TexCoord0;
166 highp vec4 pos = qt_Vertex;
167 if (qt_MultiTexCoord0.y == 0.0)
168 pos.x += factor * (1. - delta) * (qt_MultiTexCoord0.x * -2.0 + 1.0);
169 else if (qt_MultiTexCoord0.y == 1.0)
170 pos.x += factor * (delta) * (qt_MultiTexCoord0.x * -2.0 + 1.0);
173 gl_Position = qt_Matrix * pos;
174 qt_TexCoord0 = qt_MultiTexCoord0;