psa: using 2 flickables
[feedingit] / psa_harmattan / feedingit / qml / Articles.qml
1 import Qt 4.7
2 import com.nokia.meego 1.0
3 import QtWebKit 1.0
4
5 Item {
6     id: articlePage
7     property int buffer: 60
8     property string feedid: parent.feedid
9     property bool zoomEnabled: false
10     property bool vertPanningEnabled: true
11     width: parent.width; height: parent.height;
12     property int webviewFontSize: settings.webviewFontSize
13
14     function next() {
15         if (flickableFront.state == "visible") {
16             flickableBack.moveFromRight();
17         } else {
18             flickableFront.moveFromRight();
19         }
20     }
21
22     function prev() {
23         if (flickableFront.state == "visible") {
24             flickableBack.moveFromLeft();
25         } else {
26             flickableFront.moveFromLeft();
27         }
28     }
29
30     Component.onCompleted: {
31         webViewFront.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
32     }
33
34     Flickable {
35         id: flickableFront
36         //anchors.fill: screen;
37         height: articlePage.height;
38         width: articlePage.width;
39         contentWidth: boundsRecFront.width
40         contentHeight: boundsRecFront.height
41         boundsBehavior: Flickable.StopAtBounds
42         //contentWidth: childrenRect.width; contentHeight: childrenRect.height
43         //interactive: parent.vertPanningEnabled;
44
45         flickDeceleration: 5000;
46         //flickableDirection: Flickable.VerticalFlick
47
48         property bool contentIsReady: false
49         Rectangle {
50             id: boundsRecFront
51             color: "white"
52             width: webViewFront.html == "" ? articlePage.width : webViewFront.width*webViewFront.scale + 2*buffer
53             height: Math.max(articlePage.height,webViewFront.height*webViewFront.scale)
54
55             WebView {
56                 id: webViewFront
57                 anchors.horizontalCenter: parent.horizontalCenter
58                 //url: flipItem.url;
59                 preferredWidth: articlePage.width
60                 //preferredHeight: articleView.height
61                 //scale: 1.25;
62                 transformOrigin: Item.TopLeft
63                 //scale: slider.value;
64                 settings.defaultFontSize: articlePage.webviewFontSize
65
66                 onLoadFinished: {
67                     flickableFront.contentX = buffer
68                     controller.setEntryRead(articlePage.feedid, articlePage.mainArticleId)
69                      //flickable.width/2
70                     flickableFront.contentIsReady = true
71                 }
72
73
74             }
75
76         }
77
78         state: "visible"
79
80         states: [ State {
81                 name: "visible";
82                 PropertyChanges { target: flickableFront; x: 0; }
83             }, State {
84                 name: "toRight";
85                 PropertyChanges { target: flickableFront; x: boundsRecBack.width; }
86             }, State {
87                 name: "toLeft";
88                 PropertyChanges { target: flickableFront; x: -boundsRecFront.width; }
89             }
90         ]
91
92         transitions: [
93             Transition {
94                 from: "visible";
95                 PropertyAnimation { target: flickableFront
96                   easing.type: Easing.InOutSine
97                   properties: "x"; duration: 1000 }
98             },
99             Transition {
100                 to: "visible";
101                 PropertyAnimation { target: flickableFront
102                 easing.type: Easing.InOutSine
103                 properties: "x"; duration: 1000 }
104             }
105         ]
106
107         function moveFromLeft() {
108             flickableFront.contentIsReady = false
109             articlePage.mainArticleId = controller.getPreviousId(articlePage.feedid,articlePage.mainArticleId)
110             webViewFront.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
111             state = "toLeft"
112             state = "visible"
113             flickableBack.state = "toRight"
114         }
115
116         function moveFromRight() {
117             flickableFront.contentIsReady = false
118             articlePage.mainArticleId = controller.getNextId(articlePage.feedid,articlePage.mainArticleId)
119             webViewFront.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
120             state = "toRight"
121             state = "visible"
122             flickableBack.state = "toLeft"
123         }
124
125         Behavior on contentX {
126             id: contentXBehavior
127             enabled: flickableFront.contentIsReady
128             NumberAnimation { duration: 200 }
129         }
130         onMovingHorizontallyChanged: {
131             if (!movingHorizontally && (!atXBeginning || !atXEnd)) {
132                 flickableFront.contentX = buffer //flickable.width/2
133             }
134         }
135
136         onAtXBeginningChanged: {
137             if (atXBeginning && contentIsReady) {
138                 flickableBack.moveFromLeft()
139             }
140         }
141
142         onAtXEndChanged: {
143             if (atXEnd && contentIsReady) {
144                 //console.log("next")
145                 flickableBack.moveFromRight()
146             }
147         }
148
149     }
150
151
152     Flickable {
153         id: flickableBack
154         //anchors.fill: screen;
155         height: articlePage.height;
156         width: articlePage.width;
157         contentWidth: boundsRecBack.width
158         contentHeight: boundsRecBack.height
159         boundsBehavior: Flickable.StopAtBounds
160
161         //contentWidth: childrenRect.width; contentHeight: childrenRect.height
162         //interactive: parent.vertPanningEnabled;
163
164         flickDeceleration: 5000;
165         //flickableDirection: Flickable.VerticalFlick
166
167         property bool contentIsReady: false
168         Rectangle {
169             id: boundsRecBack
170             color: "white"
171             width: webViewBack.html == "" ? articlePage.width : webViewBack.width*webViewBack.scale + 2*buffer // flickable.width
172             height: Math.max(articlePage.height,webViewBack.height*webViewBack.scale)
173
174             WebView {
175                 id: webViewBack
176                 anchors.horizontalCenter: parent.horizontalCenter
177                 //url: flipItem.url;
178                 //html: controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
179                 preferredWidth: articlePage.width
180                 //preferredHeight: articleView.height
181                 //scale: 1.25;
182                 transformOrigin: Item.TopLeft
183                 //scale: slider.value;
184                 settings.defaultFontSize: articlePage.webviewFontSize
185
186                 onLoadFinished: {
187                     flickableBack.contentX = buffer
188                     controller.setEntryRead(articlePage.feedid, articlePage.mainArticleId)
189                     flickableBack.contentIsReady = true
190                 }
191             }
192         }
193
194         state: "toRight"
195
196         states: [ State {
197                 name: "visible";
198                 PropertyChanges { target: flickableBack; x: 0; }
199             }, State {
200                 name: "toRight";
201                 PropertyChanges { target: flickableBack; x: boundsRecFront.width; }
202             }, State {
203                 name: "toLeft";
204                 PropertyChanges { target: flickableBack; x: -boundsRecBack.width; }
205             }
206         ]
207
208         transitions: [
209             Transition {
210                 from: "visible";
211                 PropertyAnimation { target: flickableBack
212                   easing.type: Easing.InOutSine
213                   properties: "x"; duration: 1000 }
214             },
215             Transition {
216                 to: "visible";
217                 PropertyAnimation { target: flickableBack
218                 easing.type: Easing.InOutSine
219                 properties: "x"; duration: 1000 }
220             }
221         ]
222
223         function moveFromLeft() {
224             flickableBack.contentIsReady = false
225             articlePage.mainArticleId = controller.getPreviousId(articlePage.feedid,articlePage.mainArticleId)
226             webViewBack.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
227             state = "toLeft"
228             state = "visible"
229             flickableFront.state = "toRight"
230         }
231
232         function moveFromRight() {
233             flickableBack.contentIsReady = false
234             articlePage.mainArticleId = controller.getNextId(articlePage.feedid,articlePage.mainArticleId)
235             webViewBack.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
236             state = "toRight"
237             state = "visible"
238             flickableFront.state = "toLeft"
239         }
240
241         Behavior on contentX {
242             id: contentXBehaviorBack
243             enabled: flickableBack.contentIsReady
244             NumberAnimation { duration: 200 }
245         }
246
247         onMovingHorizontallyChanged: {
248             if (!movingHorizontally && (!atXBeginning || !atXEnd)) {
249                 flickableBack.contentX = buffer //flickable.width/2
250             }
251         }
252
253         onAtXBeginningChanged: {
254             if (atXBeginning && contentIsReady) {
255                 flickableFront.moveFromLeft()
256             }
257         }
258
259         onAtXEndChanged: {
260             if (atXEnd && contentIsReady) {
261                 flickableFront.moveFromRight()
262             }
263         }
264     }
265
266     ProgressBar {
267         id: updateBarArticles
268         minimumValue: 0
269         maximumValue: 100
270         value: window.updateProgressValue
271         visible: window.isUpdateInProgress
272         width: parent.width
273         anchors.bottom: parent.bottom
274     }
275
276     ListModel {
277         id: articlesModel
278
279
280
281     }
282 }