psa: implemented settings
[feedingit] / psa_harmattan / feedingit / deb_dist / feedingit-0.1.0 / debian / feedingit / usr / share / feedingit / qml / ArticleViewer.qml
1 import Qt 4.7
2
3 Item {
4     id: articleViewer
5     //width: 480; height: 360;
6     width: parent.width; height: parent.height;
7     property string feedid: parent.feedid
8     //property string feedid: "61ac1458d761423344998dc76770e36e" //articlesItem.feedid;
9     //property string hideReadArticles: "";
10     property alias articleShown: articleView.visible;
11     property bool zoomEnabled: false;
12     property bool vertPanningEnabled: true
13
14     function modulo(x,y) {
15         // Fixes modulo for negative numbers
16         return ((x%y)+y)%y;
17     }
18
19     function reload() {
20         articles.xml = articleViewer.feedid == "" ? "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml></xml>" : controller.getArticlesXml(articleViewer.feedid);
21         articles.reload()
22     }
23
24     function next() {
25         if (articleView.visible) {
26             //articleView.positionViewAtIndex(modulo(articleView.currentIndex+1, articleView.count), ListView.Contain);
27             articleView.incrementCurrentIndex();
28         }
29     }
30
31     function prev() {
32         if (articleView.visible) {
33             //articleView.positionViewAtIndex(modulo(articleView.currentIndex-1, articleView.count), ListView.Contain);
34             articleView.decrementCurrentIndex();
35         }
36     }
37
38     function markAllAsRead() {
39         if (feedid!="") {
40             controller.markAllAsRead(feedid)
41             articles.reload();
42         }
43     }
44
45     function viewArticle(articleid) {
46         var index = 0;
47         for (var i=0; i<articleList.count; ++i) {
48             if (articles.get(0).articleid==articleid) {
49                 index = i;
50             }
51         }
52         articleView.positionViewAtIndex(index, ListView.Contain); articleView.visible = true;
53     }
54
55     ListView {
56         id: articleList; /*model: visualModel.parts.list;*/ z: 6
57         model: articles
58         delegate: listing
59         width: parent.width; height: parent.height; /*x: 0;*/
60         cacheBuffer: 100;
61         flickDeceleration: 1500
62     }
63
64     ListView {
65         id: articleView;
66         model: articles;
67         delegate: viewer
68         orientation: ListView.Horizontal
69         width: parent.width; height: parent.height; visible: false; z:8
70         //onCurrentIndexChanged: photosGridView.positionViewAtIndex(currentIndex, GridView.Contain)
71         highlightRangeMode: ListView.StrictlyEnforceRange; snapMode: ListView.SnapOneItem
72         //cacheBuffer: 5;
73         onMovementStarted: articleViewer.vertPanningEnabled=false;
74         onMovementEnded: articleViewer.vertPanningEnabled=true;
75         highlightMoveDuration: 300;
76     }
77
78     Rectangle {
79         id: noArticle
80         //width: parent.width; height: parent.height;
81         //color: "#000000"
82         anchors.centerIn: parent;
83         visible: false;
84         z:8;
85         Text { id: noText; color: "#ffffff"; anchors.centerIn: parent; text: qsTr("No articles available"); }
86         Image { id: loadingImage; anchors.centerIn: parent; source: "common/images/loading.png";
87             height: 96; width: 96;
88             NumberAnimation on rotation {
89                 from: 0; to: 360; running: (loadingImage.visible == true); loops: Animation.Infinite; duration: 900
90             }
91         }
92
93         states: [ State {
94             name: "noArticle"; when: articles.count==0 && articles.status==XmlListModel.Ready
95             PropertyChanges { target: noArticle; visible: true; }
96             PropertyChanges { target: loadingImage; visible: false; }
97             PropertyChanges { target: noText; visible: true; }
98             }, State {
99             name: "loading"; when: articles.count==0 && articles.status != XmlListModel.Ready
100             PropertyChanges { target: noArticle; visible: true; }
101             PropertyChanges { target: noText; visible: false; }
102             PropertyChanges { target: loadingImage; visible: true; }
103             }
104         ]
105     }
106
107     Component {
108             id: listing;
109
110             Item {
111                 width: articleViewer.width; height: backRect.height + 3
112                 id: listItem
113
114                 Rectangle {
115                     id: backRect; color: settings.backColour; opacity: index % 2 ? 0.2 : 0.4;
116                     height: articleText.height + 22; width: listItem.width;
117                     y: 1
118                 }
119                 Text {
120                     id: articleText
121                     anchors.verticalCenter: backRect.verticalCenter
122                     x: 3
123                     width: listItem.width - 6;
124
125                     anchors.margins: 5
126                     verticalAlignment: Text.AlignVCenter; text: title;
127                     color: (unread=="True") ? settings.mainTextColour : settings.secondaryTextColour;
128
129                      wrapMode: Text.WordWrap; font.bold: false;
130                     font.pointSize: 18
131                 }
132                 MouseArea { anchors.fill: listItem;
133                     onClicked: { articleView.positionViewAtIndex(index, ListView.Contain); articleView.visible = true; }
134                 }
135             }
136
137     }
138
139     Component {
140         id: viewer
141         Item {
142             id: flipItem;
143             width: articleViewer.width; height: articleViewer.height;
144
145             property string url: (articleView.visible && Math.abs(articleView.currentIndex-index)<2) ? path: "";
146             property string html: controller.getArticle(articleViewer.feedid, articleid)
147             ArticleDisplay {
148                 zoomEnabled: articleViewer.zoomEnabled;
149                 property bool vertPanningEnabled: articleViewer.vertPanningEnabled;
150
151                 states: [ State {
152                         name: 'articleIsRead';
153                     when: articleView.visible && articleView.currentIndex == index;
154                     StateChangeScript {
155                         name: "myScript"
156                         script: {
157                             flipItem.url=path;
158                             controller.setEntryRead(articleViewer.feedid, articleid)
159                         }
160                     }
161                     }, State {
162                         name: 'articleIsClose'; when: articleView.visible && Math.abs(articleView.currentIndex-index)<2;
163                         StateChangeScript {
164                             script: { flipItem.url=path; }
165                         }
166                     }
167                 ]
168             }
169         }
170     }
171
172     XmlListModel {
173         id: articles
174
175         //source: articleViewer.feedid == "" ? "" : "http://localhost:8000/articles/" + feedid + "?onlyUnread=" + hideReadArticles
176         xml: articleViewer.feedid == "" ? "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml></xml>" : controller.getArticlesXml(articleViewer.feedid)
177         query: "/xml/article"
178
179         XmlRole { name: "title"; query: "title/string()" }
180         XmlRole { name: "articleid"; query: "articleid/string()"; isKey: true }
181         XmlRole { name: "path"; query: "path/string()" }
182         XmlRole { name: "unread"; query: "unread/string()"; isKey: true}
183     }
184
185
186 }