psa: made text more readable for n950
[feedingit] / psa_harmattan / feedingit / deb_dist / feedingit-0.1.0 / 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: 86
112                 id: listItem
113                 Rectangle { id: backRect; color: "#dddddd"; opacity: index % 2 ? 0.2 : 0.4; height: 84; width: listItem.width; y: 1 }
114                 Text {
115                     anchors.fill: backRect
116                     anchors.margins: 5
117                     verticalAlignment: Text.AlignVCenter; text: title;
118                     color: (unread=="True") ? "white" : "#7b97fd";
119
120                     width: listItem.width; wrapMode: Text.WordWrap; font.bold: false;
121                     font.pointSize: 18
122                 }
123                 MouseArea { anchors.fill: listItem;
124                     onClicked: { articleView.positionViewAtIndex(index, ListView.Contain); articleView.visible = true; }
125                 }
126             }
127
128     }
129
130     Component {
131         id: viewer
132         Item {
133             id: flipItem;
134             width: articleViewer.width; height: articleViewer.height;
135
136             property string url: (articleView.visible && Math.abs(articleView.currentIndex-index)<2) ? path: "";
137             property string html: controller.getArticle(articleViewer.feedid, articleid)
138             ArticleDisplay {
139                 zoomEnabled: articleViewer.zoomEnabled;
140                 property bool vertPanningEnabled: articleViewer.vertPanningEnabled;
141
142                 states: [ State {
143                         name: 'articleIsRead';
144                     when: articleView.visible && articleView.currentIndex == index;
145                     StateChangeScript {
146                         name: "myScript"
147                         script: {
148                             flipItem.url=path;
149                             controller.setEntryRead(articleViewer.feedid, articleid)
150                         }
151                     }
152                     }, State {
153                         name: 'articleIsClose'; when: articleView.visible && Math.abs(articleView.currentIndex-index)<2;
154                         StateChangeScript {
155                             script: { flipItem.url=path; }
156                         }
157                     }
158                 ]
159             }
160         }
161     }
162
163     XmlListModel {
164         id: articles
165
166         //source: articleViewer.feedid == "" ? "" : "http://localhost:8000/articles/" + feedid + "?onlyUnread=" + hideReadArticles
167         xml: articleViewer.feedid == "" ? "<?xml version=\"1.0\" encoding=\"utf-8\"?><xml></xml>" : controller.getArticlesXml(articleViewer.feedid)
168         query: "/xml/article"
169
170         XmlRole { name: "title"; query: "title/string()" }
171         XmlRole { name: "articleid"; query: "articleid/string()"; isKey: true }
172         XmlRole { name: "path"; query: "path/string()" }
173         XmlRole { name: "unread"; query: "unread/string()"; isKey: true}
174     }
175
176
177 }