Merge branch 'master' into refactor
[profile/ivi/qtdeclarative.git] / examples / declarative / twitter / twitter.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 import QtQuick 2.0
43 import "TwitterCore" 2.0 as Twitter
44
45 Item {
46     id: screen; width: 320; height: 480
47     property bool userView : false
48     property variant tmpStr
49     function setUser(str){hack.running = true; tmpStr = str}
50     function reallySetUser(){rssModel.from = tmpStr;rssModel.to = ""; rssModel.phrase = ""}
51     state:"searchquery"
52     //Workaround for bug 260266
53     Timer{ interval: 1; running: false; repeat: false; onTriggered: screen.reallySetUser(); id:hack }
54     Keys.onEscapePressed: screen.state="searchquery"
55     Keys.onBacktabPressed: screen.state="searchquery"
56     Rectangle {
57         id: background
58         anchors.fill: parent; color: "#343434";
59
60         state:"searchquery"
61         Image { source: "TwitterCore/images/stripes.png"; fillMode: Image.Tile; anchors.fill: parent; opacity: 0.3 }
62
63         MouseArea {
64             anchors.fill: parent
65             onClicked: screen.focus = false;
66         }
67
68         Twitter.RssModel { id: rssModel }
69         Twitter.Loading { anchors.centerIn: parent; visible: rssModel.status==XmlListModel.Loading && state!='unauthed'}
70         Text {
71             width: 180
72             text: "Could not access twitter using this screen name and password pair.";
73             color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrapMode: Text.WordWrap
74             visible: rssModel.status==XmlListModel.Error; anchors.centerIn: parent
75         }
76
77         Item {
78             id: views
79             x: 2; width: parent.width - 4
80             y:60 //Below the title bars
81             height: parent.height - 100
82
83             Text {
84                 id:title
85                 text: "Search Twitter"
86                 anchors.horizontalCenter: parent.horizontalCenter
87                 font.pixelSize: 20; font.bold: true; color: "#bbb"; style: Text.Raised; styleColor: "black"
88                 opacity:0
89             }
90
91             Twitter.SearchView{
92                 id: searchView
93                 anchors.verticalCenter: parent.verticalCenter
94                 width: parent.width; height: parent.height-60;
95                 x: -(screen.width * 1.5)
96             }
97
98             Twitter.FatDelegate { id: fatDelegate }
99             ListView {
100                 id: mainView; model: rssModel.model; delegate: fatDelegate;
101                 width: parent.width; height: parent.height; x: 0; cacheBuffer: 100;
102             }
103         }
104
105         Twitter.MultiTitleBar { id: titleBar; width: parent.width }
106         Twitter.ToolBar { id: toolBar; height: 40;
107             //anchors.bottom: parent.bottom;
108             //TODO: Use anchor changes instead of hard coding
109             y: screen.height - 40
110             width: parent.width; opacity: 0.9
111             button1Label: "New Search"
112             button2Label: "Update"
113             onButton1Clicked:
114             {
115                 screen.state="searchquery"
116             }
117             onButton2Clicked: rssModel.reload();
118         }
119     }
120     states: [
121         State {
122             name: "searchquery";
123             PropertyChanges { target: searchView; x: 0; focus:true}
124             PropertyChanges { target: mainView; x: -(parent.width * 1.5) }
125             PropertyChanges { target: titleBar; y: -80 }
126             PropertyChanges { target: toolBar; y: screen.height }
127             PropertyChanges { target: toolBar }
128             PropertyChanges { target: title; opacity:1}
129         }
130     ]
131     transitions: [
132         Transition { NumberAnimation { properties: "x,y,opacity"; duration: 500; easing.type: Easing.InOutQuad } }
133     ]
134 }