diff options
Diffstat (limited to 'examples/quick/demos/tweetsearch')
18 files changed, 1122 insertions, 0 deletions
diff --git a/examples/quick/demos/tweetsearch/content/FlipBar.qml b/examples/quick/demos/tweetsearch/content/FlipBar.qml new file mode 100644 index 0000000000..06aebcacb1 --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/FlipBar.qml @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: container + property int animDuration: 300 + 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 + + function swap() { + var tmp = front; + front = back; + back = tmp; + resync(); + } + + width: cur.width + 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 + } + + function flipUp(start) { + effect.visible = true; + effect.sourceA = effect.source1 + effect.sourceB = effect.source2 + if (start == undefined) + start = 1.0; + deltaAnim.from = start; + deltaAnim.to = 0.0 + dAnim.start(); + frontShown = false; + } + + function flipDown(start) { + effect.visible = true; + effect.sourceA = effect.source1 + effect.sourceB = effect.source2 + if (start == undefined) + start = 0.0; + deltaAnim.from = start; + deltaAnim.to = 1.0 + dAnim.start(); + frontShown = true; + } + + ShaderEffect { + id: effect + width: cur.width + height: cur.height + property real factor: container.factor * width + property real delta: 1.0 + + mesh: GridMesh { resolution: Qt.size(8,2) } + + SequentialAnimation on delta { + id: dAnim + running: false + NumberAnimation { + id: deltaAnim + duration: animDuration//expose anim + } + } + + 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 + } + + fragmentShader: " + uniform lowp float qt_Opacity; + uniform sampler2D sourceA; + uniform sampler2D sourceB; + uniform highp float delta; + varying highp vec2 qt_TexCoord0; + void main() { + 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); + } else { + col = texture2D(sourceB, tex.zw) * (1.5 - shade); + col.w = 1.0; + } + gl_FragColor = col * qt_Opacity; + } + " + property real h: height + vertexShader: " + uniform highp float delta; + uniform highp float factor; + uniform highp float h; + uniform highp mat4 qt_Matrix; + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + varying highp vec2 qt_TexCoord0; + void main() { + highp vec4 pos = qt_Vertex; + if (qt_MultiTexCoord0.y == 0.0) + 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 + pos.y = delta * h; + gl_Position = qt_Matrix * pos; + qt_TexCoord0 = qt_MultiTexCoord0; + }" + + } +} diff --git a/examples/quick/demos/tweetsearch/content/LineInput.qml b/examples/quick/demos/tweetsearch/content/LineInput.qml new file mode 100644 index 0000000000..368293e961 --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/LineInput.qml @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +FocusScope { + id: wrapper + + property alias text: input.text + property alias hint: hint.text + property alias prefix: prefix.text + + signal accepted + + Rectangle { + anchors.fill: parent + border.color: "#707070" + color: "#c1c1c1" + radius: 4 + + Text { + id: hint + anchors { fill: parent; leftMargin: 14 } + verticalAlignment: Text.AlignVCenter + text: "Enter word" + font.pixelSize: 18 + color: "#707070" + opacity: input.length ? 0 : 1 + } + + Text { + id: prefix + anchors { left: parent.left; leftMargin: 14; verticalCenter: parent.verticalCenter } + verticalAlignment: Text.AlignVCenter + font.pixelSize: 18 + color: "#707070" + opacity: !hint.opacity + } + + TextInput { + id: input + focus: true + anchors { left: prefix.right; right: parent.right; top: parent.top; bottom: parent.bottom } + verticalAlignment: Text.AlignVCenter + font.pixelSize: 18 + color: "#707070" + onAccepted: wrapper.accepted() + } + + Image { + source: "resources/icon-search.png" + anchors.right: parent.right + anchors.rightMargin: 12 + anchors.verticalCenter: parent.verticalCenter + MouseArea { + anchors { fill: parent; margins: -10 } + onClicked: wrapper.accepted() + } + } + } +} diff --git a/examples/quick/demos/tweetsearch/content/ListFooter.qml b/examples/quick/demos/tweetsearch/content/ListFooter.qml new file mode 100644 index 0000000000..91c1c8b331 --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/ListFooter.qml @@ -0,0 +1,154 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + color: "#d6d6d6" + 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 + + SearchDelegate { + id: wordSearch + label: "Search word..." + placeHolder: "Enter word" + onHasOpened: { + tagSearch.close() + userSearch.close() + } + onOk: { + mainListView.positionViewAtBeginning() + mainListView.clear() + tweetsModel.from = "" + tweetsModel.phrase = searchText + } + } + + SearchDelegate { + id: userSearch + label: "From user..." + placeHolder: "@username" + prefix: "@" + onHasOpened:{ + tagSearch.close() + wordSearch.close() + } + onOk: { + mainListView.positionViewAtBeginning() + mainListView.clear() + tweetsModel.phrase = "" + tweetsModel.from = searchText + } + } + + SearchDelegate { + id: tagSearch + label: "Search hashtag..." + placeHolder: "#hashtag" + prefix: "#" + onHasOpened:{ + userSearch.close() + wordSearch.close() + } + onOk: { + mainListView.positionViewAtBeginning() + mainListView.clear() + tweetsModel.from = "" + tweetsModel.phrase = "#" + searchText + } + } + + SpriteSequence { + id: sprite + anchors.horizontalCenter: parent.horizontalCenter + width: 320 + height: 300 + running: true + interpolate: false + Sprite { + name: "bird" + source: "resources/bird-anim-sprites.png" + frameCount: 1 + frameRate: 1 + frameWidth: 320 + frameHeight: 300 + to: { "bird":10, "trill":1, "blink":1 } + } + Sprite { + name: "trill" + source: "resources/bird-anim-sprites.png" + frameCount: 5 + frameRate: 3 + frameWidth: 320 + frameHeight: 300 + to: {"bird":1} + } + Sprite { + name: "blink" + source: "resources/bird-anim-sprites.png" + frameCount: 1 + frameRate: 3 + frameWidth: 320 + frameHeight: 300 + frameX: 1600 + to: {"bird":1} + } + } + } +} diff --git a/examples/quick/demos/tweetsearch/content/ListHeader.qml b/examples/quick/demos/tweetsearch/content/ListHeader.qml new file mode 100644 index 0000000000..2fb673dc7c --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/ListHeader.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + height: 60 + width: parent.width + + property bool refresh: state == "pulled" ? true : false + + Row { + spacing: 6 + height: childrenRect.height + anchors.centerIn: parent + + Image { + id: arrow + source: "resources/icon-refresh.png" + transformOrigin: Item.Center + Behavior on rotation { NumberAnimation { duration: 200 } } + } + + Text { + id: label + anchors.verticalCenter: arrow.verticalCenter + text: "Pull to refresh... " + font.pixelSize: 18 + color: "#999999" + } + } + + states: [ + State { + name: "base"; when: mainListView.contentY >= -120 + PropertyChanges { target: arrow; rotation: 180 } + }, + State { + name: "pulled"; when: mainListView.contentY < -120 + PropertyChanges { target: label; text: "Release to refresh..." } + PropertyChanges { target: arrow; rotation: 0 } + } + ] +} diff --git a/examples/quick/demos/tweetsearch/content/SearchDelegate.qml b/examples/quick/demos/tweetsearch/content/SearchDelegate.qml new file mode 100644 index 0000000000..fc0ee0b655 --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/SearchDelegate.qml @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +FlipBar { + id: flipBar + animDuration: 250 + property string label: "" + property string placeHolder: "" + property alias searchText: lineInput.text + property alias prefix: lineInput.prefix + property bool opened: false + signal ok + signal hasOpened + + height: 60 + width: parent.width + + function open() { + flipBar.flipUp() + flipBar.opened = true + lineInput.forceActiveFocus() + flipBar.hasOpened() + } + + function close() { + if (opened) { + flipBar.flipDown() + flipBar.opened = false + } + } + + front: Rectangle { + height: 60 + width: parent.width + color: "#999999" + + Rectangle { color: "#c1c1c1"; width: parent.width; height: 1 } + Rectangle { color: "#707070"; width: parent.width; height: 1; anchors.bottom: parent.bottom } + + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: { + if (!flipBar.opened) + open() + else if (!lineInput.activeFocus) + lineInput.forceActiveFocus() + else + close() + } + } + + Text { + text: flipBar.label + anchors { left: parent.left; leftMargin: 20 } + anchors.verticalCenter: parent.verticalCenter + font.pixelSize: 18 + color: "#ffffff" + } + } + + back: FocusScope { + height: 60 + width: parent.width + Rectangle { + anchors.fill: parent + color: "#999999" + + Rectangle { color: "#c1c1c1"; width: parent.width; height: 1 } + Rectangle { color: "#707070"; width: parent.width; height: 1; anchors.bottom: parent.bottom } + + LineInput { + id: lineInput + hint: flipBar.placeHolder + focus: flipBar.opened + anchors { fill: parent; margins: 6 } + onAccepted: flipBar.ok() + } + } + } + +} diff --git a/examples/quick/demos/tweetsearch/content/TweetDelegate.qml b/examples/quick/demos/tweetsearch/content/TweetDelegate.qml new file mode 100644 index 0000000000..c336ae6f8a --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/TweetDelegate.qml @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "tweetsearch.js" as Helper + +Item { + id: container + property real hm: 1.0 + property int appear: -1 + property real startRotation: 1 + + onAppearChanged: { + container.startRotation = 0.5 + flipBar.animDuration = appear; + delayedAnim.start(); + } + + SequentialAnimation { + id: delayedAnim + PauseAnimation { duration: 50 } + ScriptAction { script: flipBar.flipDown(startRotation); } + } + + width: 320 + height: flipBar.height * hm + + FlipBar { + id: flipBar + + property bool flipped: false + delta: startRotation + + anchors.bottom: parent.bottom + width: container.ListView.view ? container.ListView.view.width : 0 + height: Math.max(72, tweet.y + tweet.height + 10) + + front: Rectangle { + width: container.ListView.view ? container.ListView.view.width : 0 + height: Math.max(72, tweet.y + tweet.height + 10) + color: "#2699bf" + + Rectangle { color: "#33ccff"; width: parent.width; height: 1 } + Rectangle { color: "#1a6680"; width: parent.width; height: 1; anchors.bottom: parent.bottom } + + Image { + id: placeHolder + source: "resources/anonymous.png" + 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 { + id: name + text: Helper.realName(model.name) + anchors { left: avatar.right; leftMargin: 10; top: avatar.top; topMargin: -3 } + font.pixelSize: 12 + font.bold: true + color: "white" + linkColor: "white" + } + + Text { + id: tweet + text: model.statusText + anchors { left: avatar.right; leftMargin: 10; top: name.bottom; topMargin: 0; right: parent.right; rightMargin: 10 } + wrapMode: Text.WordWrap + font.pixelSize: 12 + font.bold: false + color: "#adebff" + linkColor: "white" + 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) + } + } + } + + back: Rectangle { + width: container.ListView.view ? container.ListView.view.width : 0 + height: Math.max(72, tweet.y + tweet.height + 10) + color: "#be4a25" + + Rectangle { color: "#ff6633"; width: parent.width; height: 1 } + Rectangle { color: "#80341a"; width: parent.width; height: 1; anchors.bottom: parent.bottom } + + Image { + id: avatar2 + source: model.userImage + anchors.right: parent.right + anchors.rightMargin: 10 + y: 9 + MouseArea { + anchors.fill: parent + onClicked: { + flipBar.flipDown() + flipBar.flipped = false + } + } + } + + Text { + id: username + text: Helper.twitterName(model.name) + x: 10; anchors { top: avatar2.top; topMargin: -3 } + font.pixelSize: 12 + font.bold: true + color: "white" + linkColor: "white" + } + + Text { + text: model.source + "<br>" + Helper.formatDate(model.published) + "<br>" + model.uri + x: 10; anchors { top: username.bottom; topMargin: 0 } + wrapMode: Text.WordWrap + font.pixelSize: 12 + font.bold: false + color: "#ffc2ad" + linkColor: "white" + onLinkActivated: Qt.openUrlExternally(link); + } + } + } +} diff --git a/examples/quick/demos/tweetsearch/content/TweetsModel.qml b/examples/quick/demos/tweetsearch/content/TweetsModel.qml new file mode 100644 index 0000000000..df6ecdcd7f --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/TweetsModel.qml @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.XmlListModel 2.0 + +Item { + id: wrapper + + property variant model: xmlModel + property string from : "" + property string phrase : "" + + property string mode : "everyone" + property int status: xmlModel.status + + function reload() { xmlModel.reload(); } + + property bool isLoading: status == XmlListModel.Loading + property bool wasLoading: false + signal isLoaded + + XmlListModel { + id: xmlModel + + onStatusChanged: { + if (status == XmlListModel.Ready && wasLoading == true) + wrapper.isLoaded() + if (status == XmlListModel.Loading) + wasLoading = true; + else + wasLoading = false; + } + + function encodePhrase(x) { return encodeURIComponent(x); } + + source: (from == "" && phrase == "") ? "" : + 'http://search.twitter.com/search.atom?from='+from+"&rpp=10&phrase="+encodePhrase(phrase) + + namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom'; " + + "declare namespace twitter=\"http://api.twitter.com/\";"; + + query: "/feed/entry" + + XmlRole { name: "id"; query: "id/string()" } + XmlRole { name: "content"; query: "content/string()" } + XmlRole { name: "published"; query: "published/string()" } + XmlRole { name: "source"; query: "twitter:source/string()" } + XmlRole { name: "name"; query: "author/name/string()" } + XmlRole { name: "uri"; query: "author/uri/string()" } + XmlRole { name: "image"; query: "link[@rel = 'image']/@href/string()" } + + } +} diff --git a/examples/quick/demos/tweetsearch/content/resources/anonymous.png b/examples/quick/demos/tweetsearch/content/resources/anonymous.png Binary files differnew file mode 100644 index 0000000000..88fba26e90 --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/resources/anonymous.png diff --git a/examples/quick/demos/tweetsearch/content/resources/bird-anim-sprites.png b/examples/quick/demos/tweetsearch/content/resources/bird-anim-sprites.png Binary files differnew file mode 100644 index 0000000000..4e8d7e6116 --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/resources/bird-anim-sprites.png diff --git a/examples/quick/demos/tweetsearch/content/resources/icon-clear.png b/examples/quick/demos/tweetsearch/content/resources/icon-clear.png Binary files differnew file mode 100644 index 0000000000..75672f64c7 --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/resources/icon-clear.png diff --git a/examples/quick/demos/tweetsearch/content/resources/icon-loading.png b/examples/quick/demos/tweetsearch/content/resources/icon-loading.png Binary files differnew file mode 100644 index 0000000000..8dbff8b70f --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/resources/icon-loading.png diff --git a/examples/quick/demos/tweetsearch/content/resources/icon-refresh.png b/examples/quick/demos/tweetsearch/content/resources/icon-refresh.png Binary files differnew file mode 100644 index 0000000000..b639a638fe --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/resources/icon-refresh.png diff --git a/examples/quick/demos/tweetsearch/content/resources/icon-search.png b/examples/quick/demos/tweetsearch/content/resources/icon-search.png Binary files differnew file mode 100644 index 0000000000..e41935a6c1 --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/resources/icon-search.png diff --git a/examples/quick/demos/tweetsearch/content/tweetsearch.js b/examples/quick/demos/tweetsearch/content/tweetsearch.js new file mode 100644 index 0000000000..9b8638f69e --- /dev/null +++ b/examples/quick/demos/tweetsearch/content/tweetsearch.js @@ -0,0 +1,19 @@ +.pragma library + +function twitterName(str) +{ + var s = str.split("(") + return s[0] +} + +function realName(str) +{ + var s = str.split("(") + return s[1].substring(0, s[1].length-1) +} + +function formatDate(date) +{ + var da = new Date(date) + return da.toDateString() +} diff --git a/examples/quick/demos/tweetsearch/main.cpp b/examples/quick/demos/tweetsearch/main.cpp new file mode 100644 index 0000000000..8b1d59679c --- /dev/null +++ b/examples/quick/demos/tweetsearch/main.cpp @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "../../shared/shared.h" +DECLARATIVE_EXAMPLE_MAIN(tweetsearch) diff --git a/examples/quick/demos/tweetsearch/tweetsearch.pro b/examples/quick/demos/tweetsearch/tweetsearch.pro new file mode 100644 index 0000000000..887c05af88 --- /dev/null +++ b/examples/quick/demos/tweetsearch/tweetsearch.pro @@ -0,0 +1,9 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/quick/demos/tweetsearch +qml.files = tweetsearch.qml content +qml.path = $$[QT_INSTALL_EXAMPLES]/quick/demos/tweetsearch +INSTALLS += target qml diff --git a/examples/quick/demos/tweetsearch/tweetsearch.qml b/examples/quick/demos/tweetsearch/tweetsearch.qml new file mode 100644 index 0000000000..961ffce36b --- /dev/null +++ b/examples/quick/demos/tweetsearch/tweetsearch.qml @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "content" + +Rectangle { + id: main + width: 320 + height: 480 + color: "#d6d6d6" + + property string searchTerms: "" + property int inAnimDur: 250 + property int counter: 0 + property alias isLoading: tweetsModel.isLoading + property var idx + property var ids + + Component.onCompleted: ids = new Array() + + function idInModel(id) + { + for (var j = 0; j < ids.length; j++) + if (ids[j] === id) + return 1 + return 0 + } + + TweetsModel { + id: tweetsModel + onIsLoaded: { + console.debug("Reload") + idx = new Array() + for (var i = 0; i < tweetsModel.model.count; i++) { + var id = tweetsModel.model.get(i).id + if (!idInModel(id)) + idx.push(i) + } + console.debug(idx.length + " new tweets") + main.counter = idx.length + } + } + + Timer { + id: timer + interval: 500; running: main.counter; repeat: true + onTriggered: { + main.counter--; + var id = tweetsModel.model.get(idx[main.counter]).id + mainListView.add( { "statusText": tweetsModel.model.get(main.counter).content, + "name": tweetsModel.model.get(main.counter).name, + "userImage": tweetsModel.model.get(main.counter).image, + "source": tweetsModel.model.get(main.counter).source, + "id": id, + "uri": tweetsModel.model.get(main.counter).uri, + "published": tweetsModel.model.get(main.counter).published } ); + ids.push(id) + } + } + + ListView { + id: mainListView + anchors.fill: parent + delegate: TweetDelegate { } + model: ListModel { id: finalModel } + + add: Transition { + NumberAnimation { property: "hm"; from: 0; to: 1.0; duration: 300; easing.type: Easing.OutQuad } + PropertyAction { property: "appear"; value: 250 } + } + + onDragEnded: if (header.refresh) { tweetsModel.model.reload() } + + ListHeader { + id: header + y: -mainListView.contentY - height + } + + footer: ListFooter { } + + function clear() { + ids = new Array() + model.clear() + } + + function add(obj) { + model.insert(0, obj) + } + + signal autoSearch(string type, string str) // To communicate with Footer instance + } +} diff --git a/examples/quick/demos/tweetsearch/tweetsearch.qmlproject b/examples/quick/demos/tweetsearch/tweetsearch.qmlproject new file mode 100644 index 0000000000..5a0f31117b --- /dev/null +++ b/examples/quick/demos/tweetsearch/tweetsearch.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.1 + +Project { + mainFile: "tweetsearch.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } +} |