psa: scrolling only right
[feedingit] / psa_harmattan / feedingit / qml / ArticleViewer.qml
1 import Qt 4.7
2 import com.nokia.meego 1.0
3
4 Item {
5     id: articleViewer
6     //width: 480; height: 360;
7     width: parent.width; height: parent.height;
8     property string feedid: parent.feedid
9     //property string feedid: "61ac1458d761423344998dc76770e36e" //articlesItem.feedid;
10     //property string hideReadArticles: "";
11     //property alias articleShown: articleView.visible;
12     property bool zoomEnabled: false;
13     property bool vertPanningEnabled: true
14
15     signal openArticle(string articleid);
16
17     function modulo(x,y) {
18         // Fixes modulo for negative numbers
19         return ((x%y)+y)%y;
20     }
21
22     function reload() {
23         articles.xml = articleViewer.feedid == "" ? "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml></xml>" : controller.getArticlesXml(articleViewer.feedid);
24         articles.reload()
25     }
26
27     function next() {
28         if (articleView.visible) {
29             //articleView.positionViewAtIndex(modulo(articleView.currentIndex+1, articleView.count), ListView.Contain);
30             articleView.incrementCurrentIndex();
31         }
32     }
33
34     function prev() {
35         if (articleView.visible) {
36             //articleView.positionViewAtIndex(modulo(articleView.currentIndex-1, articleView.count), ListView.Contain);
37             articleView.decrementCurrentIndex();
38         }
39     }
40
41     function markAllAsRead() {
42         if (feedid!="") {
43             controller.markAllAsRead(feedid)
44             articles.reload();
45         }
46     }
47
48     function getCurrentArticleId() {
49         var object = articleView.model.get(articleView.currentIndex)
50         return object.articleid
51     }
52
53     ListView {
54         id: articleList; /*model: visualModel.parts.list;*/ z: 6
55         model: articles
56         delegate: listing
57         width: parent.width;
58         height: updateBarArticles.visible? parent.height-updateBarArticles.height : parent.height;
59         /*x: 0;*/
60         cacheBuffer: 100;
61         flickDeceleration: 1500
62         visible: articles.status==XmlListModel.Ready
63         clip: true
64     }
65
66 //    ListView {
67 //        id: articleView;
68 //        property int webviewFontSize: settings.webviewFontSize
69 //        model: articles;
70 //        delegate: viewer
71 //        orientation: ListView.Horizontal
72 //        width: parent.width;
73 //        height: updateBarArticles.visible? parent.height-updateBarArticles.height : parent.height;
74 //        visible: false; z:8
75 //        onCurrentIndexChanged: articleView.positionViewAtIndex(currentIndex, ListView.Contain)
76 //        highlightRangeMode: ListView.StrictlyEnforceRange; snapMode: ListView.SnapOneItem
77 //        //cacheBuffer: 5;
78 //        onMovementStarted: articleViewer.vertPanningEnabled=false;
79 //        onMovementEnded: articleViewer.vertPanningEnabled=true;
80 //        highlightMoveDuration: 300;
81 //        clip: true
82 //    }
83
84     ProgressBar {
85         id: updateBarArticles
86         minimumValue: 0
87         maximumValue: 100
88         value: window.updateProgressValue
89         visible: window.isUpdateInProgress
90         width: parent.width
91         anchors.bottom: parent.bottom
92     }
93
94     Rectangle {
95         id: noArticle
96         //width: parent.width; height: parent.height;
97         color: "black"
98         opacity: 0.8
99
100         //anchors.centerIn: parent;
101         anchors.fill: parent
102         visible: false;
103         z:8;
104         Text {
105             id: noText; color: "#ffffff"; anchors.centerIn: parent; text: qsTr("No articles available");
106             font.pixelSize: settings.mainTextSize
107         }
108
109         BusyIndicator {
110                      id: loadingIndicator
111                      anchors.centerIn: parent;
112                      running: visible
113                      visible: false
114                      platformStyle: BusyIndicatorStyle { size: "large" }
115         }
116
117         MouseArea {
118             // Disable clicks when this item is visible
119             anchors.fill: parent
120             enabled: parent.visible
121         }
122
123         states: [ State {
124             name: "noArticle"; when: articles.count==0 && articles.status==XmlListModel.Ready
125             PropertyChanges { target: noArticle; visible: true; }
126             PropertyChanges { target: loadingImage; visible: false; }
127             PropertyChanges { target: noText; visible: true; }
128             }, State {
129             name: "loading"; when: articles.status != XmlListModel.Ready
130             PropertyChanges { target: noArticle; visible: true; }
131             PropertyChanges { target: noText; visible: false; }
132             PropertyChanges { target: loadingIndicator; visible: true; }
133             }
134         ]
135     }
136
137     Rectangle {
138         id: reloading
139         visible: articles.status != XmlListModel.Ready
140
141
142     }
143
144     Component {
145             id: listing;
146
147             Item {
148                 width: articleViewer.width; height: backRect.height + 3
149                 id: listItem
150
151                 Rectangle {
152                     id: backRect; color: settings.backColour; opacity: index % 2 ? 0.2 : 0.4;
153                     height: articleText.height + 22; width: listItem.width;
154                     y: 1
155                 }
156                 Text {
157                     id: articleText
158                     anchors.verticalCenter: backRect.verticalCenter
159                     x: 3
160                     width: listItem.width - 6;
161
162                     anchors.margins: 5
163                     verticalAlignment: Text.AlignVCenter;
164                     text: title;
165                     color: (unread=="True") ? settings.mainTextColour : settings.secondaryTextColour;
166
167                      wrapMode: Text.WordWrap; font.bold: false;
168                     font.pointSize: settings.articleListingTextSize
169                 }
170                 MouseArea { anchors.fill: listItem;
171                     onClicked: {
172                         articleViewer.openArticle(articleid)
173                         //articleView.currentIndex = index; articleView.visible = true;
174                     }
175                 }
176             }
177
178     }
179
180 //    Component {
181 //        id: viewer
182 //        Item {
183 //            id: flipItem;
184 //            width: articleDisplay.width;
185 //            height: articleView.height;
186
187 //            //property string url: (articleView.visible && Math.abs(articleView.currentIndex-index)<2) ? path: "";
188 //            property string html: controller.getArticle(articleViewer.feedid, articleid)
189 //            ArticleDisplay {
190 //                id: articleDisplay
191 //                zoomEnabled: articleViewer.zoomEnabled;
192 //                property bool vertPanningEnabled: articleViewer.vertPanningEnabled;
193
194 //                states: [ State {
195 //                        name: 'articleIsRead';
196 //                    when: articleView.visible && articleView.currentIndex == index;
197 //                    StateChangeScript {
198 //                        name: "myScript"
199 //                        script: {
200 //                            //flipItem.url=path;
201 //                            controller.setEntryRead(articleViewer.feedid, articleid)
202 //                        }
203 //                    }
204 //                    }
205 //                ]
206 //            }
207 //        }
208 //    }
209
210     XmlListModel {
211         id: articles
212
213         //source: articleViewer.feedid == "" ? "" : "http://localhost:8000/articles/" + feedid + "?onlyUnread=" + hideReadArticles
214         xml: articleViewer.feedid == "" ? "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml></xml>" : controller.getArticlesXml(articleViewer.feedid)
215         query: "/xml/article"
216
217         XmlRole { name: "title"; query: "title/string()" }
218         XmlRole { name: "articleid"; query: "articleid/string()"; isKey: true }
219         XmlRole { name: "path"; query: "path/string()" }
220         XmlRole { name: "unread"; query: "unread/string()"; isKey: true}
221     }
222
223 }