aboutsummaryrefslogtreecommitdiffstats
path: root/examples/demos/tweetsearch/content/FlipBar.qml
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2012-06-14 14:40:00 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-23 15:45:08 +0200
commitec0ad9abc684604e7fbb9eb25899e95b58c0f7ad (patch)
tree40d9a1722c344e6c51e61ae23372de5068be0c4e /examples/demos/tweetsearch/content/FlipBar.qml
parent546bf9b5f7629ca702beddf6e65d589a1cff06a5 (diff)
Cleanup/simplify tweetsearch example
Also make it possible to click on links Change-Id: I51c2abef12662f415ae0abdde5a52f857bcdb68b Reviewed-by: Alan Alpert <alan.alpert@nokia.com> Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
Diffstat (limited to 'examples/demos/tweetsearch/content/FlipBar.qml')
-rw-r--r--examples/demos/tweetsearch/content/FlipBar.qml77
1 files changed, 20 insertions, 57 deletions
diff --git a/examples/demos/tweetsearch/content/FlipBar.qml b/examples/demos/tweetsearch/content/FlipBar.qml
index ea149ec277..65c2a3dc6b 100644
--- a/examples/demos/tweetsearch/content/FlipBar.qml
+++ b/examples/demos/tweetsearch/content/FlipBar.qml
@@ -43,17 +43,13 @@ import QtQuick 2.0
Item {
id: container
property int animDuration: 300
- property int wiggleDuration: 0 // 2x time spent each side to wiggle away before shrinking in
- property real wiggleRoom: 0 // Size on each side it moves away before shrinking during the transition
- property real squeezeFactor: 0.1 // More give a greater squeeze during transition (0.0 for none)
- property Item above: Item {}
property Item front: Item {}
property Item back: Item {}
property real factor: 0.1 // amount the edges fold in for the 3D effect
property alias delta: effect.delta
-
property Item cur: frontShown ? front : back
- property Item noncur:frontShown ? back : front
+ property Item noncur: frontShown ? back : front
+
function swap() {
var tmp = front;
front = back;
@@ -65,16 +61,25 @@ Item {
height: cur.height
onFrontChanged: resync();
onBackChanged: resync();
+
function resync() {//TODO: Are the items ever actually visible?
back.parent = container;
front.parent = container;
frontShown ? back.visible = false : front.visible = false;
}
+
property bool frontShown: true
+
+ onFrontShownChanged: {
+ back.visible = !frontShown
+ front.visible = frontShown
+ }
+
Rectangle {
anchors.fill: parent
color: "white"
}
+
function flipUp(start) {
effect.visible = true;
effect.sourceA = effect.source1
@@ -85,8 +90,8 @@ Item {
deltaAnim.to = 0.0
dAnim.start();
frontShown = false;
- sizeAnim.start();
}
+
function flipDown(start) {
effect.visible = true;
effect.sourceA = effect.source1
@@ -97,60 +102,33 @@ Item {
deltaAnim.to = 1.0
dAnim.start();
frontShown = true;
- sizeAnim.start();
- }
- SequentialAnimation on height {
- id: sizeAnim
- running: false
- //Note: front has already swapped around when we start
- NumberAnimation {
- duration: wiggleDuration
- to: noncur.height + wiggleRoom
- }
- NumberAnimation {
- duration: animDuration/2
- to: noncur.height - wiggleRoom * 2
- }
- NumberAnimation {
- duration: animDuration/2
- to: cur.height + wiggleRoom
- }
- NumberAnimation {
- duration: wiggleDuration
- to: cur.height
- }
- }
- Binding {
- target: above
- property: "y"
- value: -(container.height - effect.height) / 2
}
+
ShaderEffect {
id: effect
- //Magic is a quadratic coefficient so that we get a down pointed parabola based on delta with value +1.0 for delta 0 and 1
- //property real magic_x: delta - 0.5
- //property real magic: (magic_x * magic_x) * 2 + 0.5
width: cur.width
- height: cur.height// * magic*squeezeFactor
+ height: cur.height
property real factor: container.factor * width
property real delta: 1.0
- mesh: GridMesh { resolution: Qt.size(8,2) }//1x2 is all that's needed for the rect, but proper contents interpolation wants more
+
+ mesh: GridMesh { resolution: Qt.size(8,2) }
+
SequentialAnimation on delta {
id: dAnim
running: false
- PauseAnimation { duration: wiggleDuration }
NumberAnimation {
id: deltaAnim
duration: animDuration//expose anim
- //easing.type: Easing.OutQuart
}
}
+
property variant sourceA: source1
property variant sourceB: source1
property variant source1: ShaderEffectSource {
sourceItem: front
hideSource: effect.visible
}
+
property variant source2: ShaderEffectSource {
sourceItem: back
hideSource: effect.visible
@@ -163,25 +141,11 @@ Item {
uniform highp float delta;
varying highp vec2 qt_TexCoord0;
void main() {
- /* Pre-Vertex
- highp vec4 tex = vec4(qt_TexCoord0.x, qt_TexCoord0.y / delta, qt_TexCoord0.x, (qt_TexCoord0.y-delta)/(1.0-delta));
- //highp float shade = (1.0 - qt_TexCoord0.y) * delta;
- //highp float shade = (1.0 - tex.w) * delta;
- highp float shade = vec4(delta,delta,delta,0.0) ;
- highp vec4 col;
- if (delta > qt_TexCoord0.y)
- col = texture2D(sourceA, tex.xy);
- else
- col = texture2D(sourceB, tex.zw) * (vec4(1.0,1.0,1.0,1.0) - shade);
- gl_FragColor = vec4(col.x, col.y, col.z, 1.0) * qt_Opacity;
- //gl_FragColor = vec4(0.0,1.0,delta,1.0) * qt_Opacity;
- */
highp vec4 tex = vec4(qt_TexCoord0.x, qt_TexCoord0.y * 2.0, qt_TexCoord0.x, (qt_TexCoord0.y-0.5) * 2.0);
highp float shade = clamp(delta*2.0, 0.5, 1.0);
highp vec4 col;
if (qt_TexCoord0.y < 0.5) {
col = texture2D(sourceA, tex.xy) * (shade);
- //w governed by shade
} else {
col = texture2D(sourceB, tex.zw) * (1.5 - shade);
col.w = 1.0;
@@ -204,10 +168,9 @@ Item {
pos.x += factor * (1. - delta) * (qt_MultiTexCoord0.x * -2.0 + 1.0);
else if (qt_MultiTexCoord0.y == 1.0)
pos.x += factor * (delta) * (qt_MultiTexCoord0.x * -2.0 + 1.0);
- else // (qt_MultiTexCoord0.y == 0.5 )
+ else
pos.y = delta * h;
gl_Position = qt_Matrix * pos;
- //highp vec2 tex = qt_MultiTexCoord0;
qt_TexCoord0 = qt_MultiTexCoord0;
}"