psa: Removed some debug messages.
[feedingit] / psa_harmattan / feedingit / deb_dist / feedingit-0.1.0 / 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     function setNextId() {
31         articlePage.mainArticleId = controller.getNextId(articlePage.feedid,articlePage.mainArticleId, settings.hideReadArticles)
32     }
33
34     function setPreviousId() {
35         articlePage.mainArticleId = controller.getPreviousId(articlePage.feedid,articlePage.mainArticleId, settings.hideReadArticles)
36     }
37
38     Component.onCompleted: {
39         webViewFront.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
40     }
41
42     Flickable {
43         id: flickableFront
44         //anchors.fill: screen;
45         height: articlePage.height;
46         width: articlePage.width;
47         contentWidth: boundsRecFront.width
48         contentHeight: boundsRecFront.height
49         boundsBehavior: Flickable.StopAtBounds
50         //contentWidth: childrenRect.width; contentHeight: childrenRect.height
51         //interactive: parent.vertPanningEnabled;
52
53         flickDeceleration: 5000;
54         //flickableDirection: Flickable.VerticalFlick
55
56         property bool contentIsReady: false
57         property bool isSwitchable: false
58         Rectangle {
59             id: boundsRecFront
60             color: "white"
61             width: webViewFront.html == "" ? articlePage.width : webViewFront.width*webViewFront.scale + 2*buffer
62             height: Math.max(articlePage.height,webViewFront.height*webViewFront.scale)
63
64             WebView {
65                 id: webViewFront
66                 anchors.horizontalCenter: parent.horizontalCenter
67                 //url: flipItem.url;
68                 preferredWidth: articlePage.width
69                 //preferredHeight: articleView.height
70                 //scale: 1.25;
71                 transformOrigin: Item.TopLeft
72                 //scale: slider.value;
73                 settings.defaultFontSize: articlePage.webviewFontSize
74
75                 onLoadFinished: {
76                     flickableFront.contentX = buffer
77                     controller.setEntryRead(articlePage.feedid, articlePage.mainArticleId)
78                      //flickable.width/2
79                     flickableFront.contentIsReady = true
80                     switchableTimer.start()
81                 }
82
83             }
84         }
85
86         state: "visible"
87
88         states: [ State {
89                 name: "visible";
90                 PropertyChanges { target: flickableFront; x: 0; }
91             }, State {
92                 name: "toRight";
93                 PropertyChanges { target: flickableFront; x: boundsRecBack.width; }
94             }, State {
95                 name: "toLeft";
96                 PropertyChanges { target: flickableFront; x: -boundsRecFront.width; }
97             }
98         ]
99
100         transitions: [
101             Transition {
102                 from: "visible";
103                 SequentialAnimation {
104                     ScriptAction { script: flickableFront.isSwitchable=false; }
105                     PropertyAnimation { target: flickableFront
106                       easing.type: Easing.InOutSine
107                       properties: "x"; duration: 1000 }
108                     ScriptAction { script: flickableFront.isSwitchable=true; }
109                 }
110             },
111             Transition {
112                 to: "visible";
113                 SequentialAnimation {
114                     ScriptAction { script: flickableFront.isSwitchable=false; }
115                     PropertyAnimation { target: flickableFront
116                     easing.type: Easing.InOutSine
117                     properties: "x"; duration: 1000 }
118                     ScriptAction { script: flickableFront.isSwitchable=true; }
119                 }
120             }
121
122         ]
123
124         Timer {
125             // Disable animations/page shifting for 400ms, to give time to the page to setup properly
126             id: switchableTimer
127             interval: 400
128             running: false
129             repeat: false
130             onTriggered: flickableFront.isSwitchable=true;
131         }
132
133         function moveFromLeft() {
134             flickableFront.contentIsReady = false
135             setPreviousId()
136             //articlePage.mainArticleId = controller.getPreviousId(articlePage.feedid,articlePage.mainArticleId)
137             webViewFront.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
138             state = "toLeft"
139             state = "visible"
140             flickableBack.state = "toRight"
141         }
142
143         function moveFromRight() {
144             flickableFront.contentIsReady = false
145             setNextId()
146             //articlePage.mainArticleId = controller.getNextId(articlePage.feedid,articlePage.mainArticleId)
147             webViewFront.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
148             state = "toRight"
149             state = "visible"
150             flickableBack.state = "toLeft"
151         }
152
153         Behavior on contentX {
154             id: contentXBehavior
155             enabled: flickableFront.contentIsReady
156             NumberAnimation { duration: 200 }
157         }
158         onMovingHorizontallyChanged: {
159             if (flickableFront.isSwitchable) {
160                 if (!movingHorizontally && (!atXBeginning || !atXEnd)) {
161                     flickableFront.contentX = buffer //flickable.width/2
162                 }
163             }
164         }
165
166         onAtXBeginningChanged: {
167             if (flickableFront.isSwitchable) {
168                 if (atXBeginning && contentIsReady) {
169                     flickableBack.moveFromLeft()
170                 }
171             }
172         }
173
174         onAtXEndChanged: {
175             if (flickableFront.isSwitchable) {
176                 if (atXEnd && contentIsReady) {
177                     flickableBack.moveFromRight()
178                 }
179             }
180         }
181
182     }
183
184
185     Flickable {
186         id: flickableBack
187         //anchors.fill: screen;
188         height: articlePage.height;
189         width: articlePage.width;
190         contentWidth: boundsRecBack.width
191         contentHeight: boundsRecBack.height
192         boundsBehavior: Flickable.StopAtBounds
193
194         //contentWidth: childrenRect.width; contentHeight: childrenRect.height
195         //interactive: parent.vertPanningEnabled;
196
197         flickDeceleration: 5000;
198         //flickableDirection: Flickable.VerticalFlick
199
200         property bool contentIsReady: false
201         property bool isSwitchable: false
202         Rectangle {
203             id: boundsRecBack
204             color: "white"
205             width: webViewBack.html == "" ? articlePage.width : webViewBack.width*webViewBack.scale + 2*buffer // flickable.width
206             height: Math.max(articlePage.height,webViewBack.height*webViewBack.scale)
207
208             WebView {
209                 id: webViewBack
210                 anchors.horizontalCenter: parent.horizontalCenter
211                 //url: flipItem.url;
212                 //html: controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
213                 preferredWidth: articlePage.width
214                 //preferredHeight: articleView.height
215                 //scale: 1.25;
216                 transformOrigin: Item.TopLeft
217                 //scale: slider.value;
218                 settings.defaultFontSize: articlePage.webviewFontSize
219
220                 onLoadFinished: {
221                     flickableBack.contentX = buffer
222                     controller.setEntryRead(articlePage.feedid, articlePage.mainArticleId)
223                     flickableBack.contentIsReady = true
224                 }
225             }
226         }
227
228         state: "toRight"
229
230         states: [ State {
231                 name: "visible";
232                 PropertyChanges { target: flickableBack; x: 0; }
233             }, State {
234                 name: "toRight";
235                 PropertyChanges { target: flickableBack; x: boundsRecFront.width; }
236             }, State {
237                 name: "toLeft";
238                 PropertyChanges { target: flickableBack; x: -boundsRecBack.width; }
239             }
240         ]
241
242         transitions: [
243             Transition {
244                 from: "visible";
245                 SequentialAnimation {
246                     ScriptAction { script: flickableBack.isSwitchable=false; }
247                     PropertyAnimation { target: flickableBack
248                       easing.type: Easing.InOutSine
249                       properties: "x"; duration: 1000 }
250                     ScriptAction { script: flickableBack.isSwitchable=true; }
251                 }
252             },
253             Transition {
254                 to: "visible";
255                 SequentialAnimation {
256                     ScriptAction { script: flickableBack.isSwitchable=false; }
257                     PropertyAnimation { target: flickableBack
258                     easing.type: Easing.InOutSine
259                     properties: "x"; duration: 1000 }
260                     ScriptAction { script: flickableBack.isSwitchable=true; }
261                 }
262             }
263         ]
264
265         function moveFromLeft() {
266             flickableBack.contentIsReady = false
267             setPreviousId()
268             //articlePage.mainArticleId = controller.getPreviousId(articlePage.feedid,articlePage.mainArticleId)
269             webViewBack.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
270             state = "toLeft"
271             state = "visible"
272             flickableFront.state = "toRight"
273         }
274
275         function moveFromRight() {
276             flickableBack.contentIsReady = false
277             setNextId()
278             //articlePage.mainArticleId = controller.getNextId(articlePage.feedid,articlePage.mainArticleId)
279             webViewBack.html = controller.getArticle(articlePage.feedid, articlePage.mainArticleId);
280             state = "toRight"
281             state = "visible"
282             flickableFront.state = "toLeft"
283         }
284
285         Behavior on contentX {
286             id: contentXBehaviorBack
287             enabled: flickableBack.contentIsReady
288             NumberAnimation { duration: 200 }
289         }
290
291         onMovingHorizontallyChanged: {
292             if (flickableBack.isSwitchable) {
293                 if (!movingHorizontally && (!atXBeginning || !atXEnd)) {
294                     flickableBack.contentX = buffer //flickable.width/2
295                 }
296             }
297         }
298
299         onAtXBeginningChanged: {
300             if (flickableBack.isSwitchable) {
301                 if (atXBeginning && contentIsReady) {
302                     flickableFront.moveFromLeft()
303                 }
304             }
305         }
306
307         onAtXEndChanged: {
308             if (flickableBack.isSwitchable) {
309                 if (atXEnd && contentIsReady) {
310                     flickableFront.moveFromRight()
311                 }
312             }
313         }
314     }
315
316     ProgressBar {
317         id: updateBarArticles
318         minimumValue: 0
319         maximumValue: 100
320         value: window.updateProgressValue
321         visible: window.isUpdateInProgress
322         width: parent.width
323         anchors.bottom: parent.bottom
324     }
325
326     ListModel {
327         id: articlesModel
328
329
330
331     }
332 }