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
78 function flipUp(start) {
79 effect.visible = true;
80 effect.sourceA = effect.source1
81 effect.sourceB = effect.source2
82 if (start == undefined)
84 deltaAnim.from = start;
90 function flipDown(start) {
91 effect.visible = true;
92 effect.sourceA = effect.source1
93 effect.sourceB = effect.source2
94 if (start == undefined)
96 deltaAnim.from = start;
106 property real factor: container.factor * width
107 property real delta: 1.0
109 mesh: GridMesh { resolution: Qt.size(8,2) }
111 SequentialAnimation on delta {
116 duration: animDuration//expose anim
120 property variant sourceA: source1
121 property variant sourceB: source1
122 property variant source1: ShaderEffectSource {
124 hideSource: effect.visible
127 property variant source2: ShaderEffectSource {
129 hideSource: effect.visible
133 uniform lowp float qt_Opacity;
134 uniform sampler2D sourceA;
135 uniform sampler2D sourceB;
136 uniform highp float delta;
137 varying highp vec2 qt_TexCoord0;
139 highp vec4 tex = vec4(qt_TexCoord0.x, qt_TexCoord0.y * 2.0, qt_TexCoord0.x, (qt_TexCoord0.y-0.5) * 2.0);
140 highp float shade = clamp(delta*2.0, 0.5, 1.0);
142 if (qt_TexCoord0.y < 0.5) {
143 col = texture2D(sourceA, tex.xy) * (shade);
145 col = texture2D(sourceB, tex.zw) * (1.5 - shade);
148 gl_FragColor = col * qt_Opacity;
151 property real h: height
153 uniform highp float delta;
154 uniform highp float factor;
155 uniform highp float h;
156 uniform highp mat4 qt_Matrix;
157 attribute highp vec4 qt_Vertex;
158 attribute highp vec2 qt_MultiTexCoord0;
159 varying highp vec2 qt_TexCoord0;
161 highp vec4 pos = qt_Vertex;
162 if (qt_MultiTexCoord0.y == 0.0)
163 pos.x += factor * (1. - delta) * (qt_MultiTexCoord0.x * -2.0 + 1.0);
164 else if (qt_MultiTexCoord0.y == 1.0)
165 pos.x += factor * (delta) * (qt_MultiTexCoord0.x * -2.0 + 1.0);
168 gl_Position = qt_Matrix * pos;
169 qt_TexCoord0 = qt_MultiTexCoord0;