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