aboutsummaryrefslogtreecommitdiffstats
path: root/examples
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
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')
-rw-r--r--examples/demos/tweetsearch/content/FlipBar.qml77
-rw-r--r--examples/demos/tweetsearch/content/ListFooter.qml15
-rw-r--r--examples/demos/tweetsearch/content/SearchDelegate.qml1
-rw-r--r--examples/demos/tweetsearch/content/TweetDelegate.qml49
-rw-r--r--examples/demos/tweetsearch/content/tweetsearch.js1
-rw-r--r--examples/demos/tweetsearch/tweetsearch.qml1
6 files changed, 69 insertions, 75 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;
}"
diff --git a/examples/demos/tweetsearch/content/ListFooter.qml b/examples/demos/tweetsearch/content/ListFooter.qml
index fab40bd885..685acba7d5 100644
--- a/examples/demos/tweetsearch/content/ListFooter.qml
+++ b/examples/demos/tweetsearch/content/ListFooter.qml
@@ -45,6 +45,21 @@ Rectangle {
width: parent.width
height: childrenRect.height
z: 2
+ Connections {
+ target: mainListView
+ onAutoSearch: {
+ if (type == 'tag') {
+ tagSearch.open()
+ tagSearch.searchText = str
+ } else if (type == 'user'){
+ userSearch.open()
+ userSearch.searchText = str
+ } else {
+ wordSearch.open()
+ wordSearch.searchText = str
+ }
+ }
+ }
Column {
width: parent.width
diff --git a/examples/demos/tweetsearch/content/SearchDelegate.qml b/examples/demos/tweetsearch/content/SearchDelegate.qml
index 8c6ad40eac..c590592bb1 100644
--- a/examples/demos/tweetsearch/content/SearchDelegate.qml
+++ b/examples/demos/tweetsearch/content/SearchDelegate.qml
@@ -96,7 +96,6 @@ FlipBar {
font.pixelSize: 18
color: "#ffffff"
}
-
}
back: FocusScope {
diff --git a/examples/demos/tweetsearch/content/TweetDelegate.qml b/examples/demos/tweetsearch/content/TweetDelegate.qml
index f67685c172..ba047733b8 100644
--- a/examples/demos/tweetsearch/content/TweetDelegate.qml
+++ b/examples/demos/tweetsearch/content/TweetDelegate.qml
@@ -67,8 +67,6 @@ Item {
property bool flipped: false
delta: startRotation
-// wiggleDuration: 120
-// wiggleRoom: 2
anchors.bottom: parent.bottom
width: container.ListView.view ? container.ListView.view.width : 0
@@ -88,10 +86,19 @@ Item {
x: 10; y: 9
visible: avatar.status != Image.Ready
}
+
Image {
id: avatar
source: model.userImage
anchors.fill: placeHolder
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ onClicked: {
+ flipBar.flipUp()
+ flipBar.flipped = true
+ }
+ }
}
Text {
@@ -113,19 +120,23 @@ Item {
font.bold: false
color: "#adebff"
linkColor: "white"
- }
-
- MouseArea {
- id: mouseArea
- anchors.fill: parent
- onClicked: {
- if (!flipBar.flipped) {
- flipBar.flipUp()
- flipBar.flipped = true
- } else {
- flipBar.flipDown()
- flipBar.flipped = false
- }
+ onLinkActivated: {
+ var tag = link.split("http://search.twitter.com/search?q=%23")
+ var user = link.split("https://twitter.com/")
+ if (tag[1] != undefined) {
+ mainListView.positionViewAtBeginning()
+ mainListView.clear()
+ mainListView.autoSearch('tag', tag[1])
+ tweetsModel.from = ""
+ tweetsModel.phrase = "#" + tag[1]
+ } else if (user[1] != undefined) {
+ mainListView.positionViewAtBeginning()
+ mainListView.clear()
+ mainListView.autoSearch('user', user[1])
+ tweetsModel.phrase = ""
+ tweetsModel.from = user[1]
+ } else
+ Qt.openUrlExternally(link)
}
}
}
@@ -144,6 +155,13 @@ Item {
anchors.right: parent.right
anchors.rightMargin: 10
y: 9
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ flipBar.flipDown()
+ flipBar.flipped = false
+ }
+ }
}
Text {
@@ -165,7 +183,6 @@ Item {
color: "#ffc2ad"
linkColor: "white"
onLinkActivated: Qt.openUrlExternally(link);
-
}
}
}
diff --git a/examples/demos/tweetsearch/content/tweetsearch.js b/examples/demos/tweetsearch/content/tweetsearch.js
index 78c58c0625..9b8638f69e 100644
--- a/examples/demos/tweetsearch/content/tweetsearch.js
+++ b/examples/demos/tweetsearch/content/tweetsearch.js
@@ -17,4 +17,3 @@ function formatDate(date)
var da = new Date(date)
return da.toDateString()
}
-
diff --git a/examples/demos/tweetsearch/tweetsearch.qml b/examples/demos/tweetsearch/tweetsearch.qml
index 754dcac513..38de10c97f 100644
--- a/examples/demos/tweetsearch/tweetsearch.qml
+++ b/examples/demos/tweetsearch/tweetsearch.qml
@@ -124,5 +124,6 @@ Rectangle {
model.insert(0, obj)
}
+ signal autoSearch(string type, string str) // To communicate with Footer instance
}
}