Added full rotation support to QML interface
[feedingit] / src / 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: "61ac1458d761423344998dc76770e36e" //articlesItem.feedid;
8     //property string hideReadArticles: "";
9     property alias articleShown: articleView.visible;
10     property bool zoomEnabled: false;
11     property bool vertPanningEnabled: true
12
13     function modulo(x,y) {
14         // Fixes modulo for negative numbers
15         return ((x%y)+y)%y;
16     }
17
18     function reload() {
19         articles.reload()
20     }
21
22     function next() {
23         if (articleView.visible) {
24             //articleView.positionViewAtIndex(modulo(articleView.currentIndex+1, articleView.count), ListView.Contain);
25             articleView.incrementCurrentIndex();
26         }
27     }
28
29     function prev() {
30         if (articleView.visible) {
31             //articleView.positionViewAtIndex(modulo(articleView.currentIndex-1, articleView.count), ListView.Contain);
32             articleView.decrementCurrentIndex();
33         }
34     }
35
36     ListView {
37         id: articleList; model: visualModel.parts.list; z: 6
38         width: parent.width; height: parent.height; /*x: 0;*/
39         cacheBuffer: 100;
40         flickDeceleration: 1500
41     }
42
43     ListView {
44         id: articleView; model: visualModel.parts.flip; orientation: ListView.Horizontal
45         width: parent.width; height: parent.height; visible: false; z:8
46         //onCurrentIndexChanged: photosGridView.positionViewAtIndex(currentIndex, GridView.Contain)
47         highlightRangeMode: ListView.StrictlyEnforceRange; snapMode: ListView.SnapOneItem
48         //cacheBuffer: 5;
49         onMovementStarted: articleViewer.vertPanningEnabled=false;
50         onMovementEnded: articleViewer.vertPanningEnabled=true;
51         highlightMoveDuration: 300;
52     }
53
54     VisualDataModel {
55         id: visualModel;
56         delegate: Package {
57                         id: packageItem
58                         Item { id: flipItem; Package.name: 'flip';  width: articleViewer.width; height: articleViewer.height;
59
60                             property string url: (articleView.visible && Math.abs(articleView.currentIndex-index)<2) ? "http://localhost:8000/html/" + articleViewer.feedid + "/" + articleid : "";
61                             ArticleDisplay {
62                                 zoomEnabled: articleViewer.zoomEnabled;
63                                 property bool vertPanningEnabled: articleViewer.vertPanningEnabled;
64
65                                 states: [ State {
66                                         name: 'articleIsRead';
67                                     when: articleView.visible && articleView.currentIndex == index;
68                                     StateChangeScript {
69                                         name: "myScript"
70                                         script: {
71                                             flipItem.url="http://localhost:8000/html/" + articleViewer.feedid + "/" + articleid;
72                                             var doc = new XMLHttpRequest();
73                                             var url = "http://localhost:8000/read/" + articleViewer.feedid + "/" + articleid;
74                                             //console.log(url)
75                                             doc.open("GET", url);
76                                             doc.send();
77                                             //var xmlDoc=doc.responseXML;
78                                         }
79                                     }
80                                     }, State {
81                                         name: 'articleIsClose'; when: articleView.visible && Math.abs(articleView.currentIndex-index)<2;
82                                         StateChangeScript {
83                                             script: { flipItem.url="http://localhost:8000/html/" + articleViewer.feedid + "/" + articleid;}
84                                         }
85                                     }
86                                 ]
87                             }
88                         }
89
90                         Item { Package.name: 'list';
91                                 id: wrapper; width: articleViewer.width; height: 86
92                                 Item {
93                                     id: moveMe
94                                     Rectangle { id: backRect; color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: 84; width: wrapper.width; y: 1 }
95                                     Text {
96                                         anchors.fill: backRect
97                                         anchors.margins: 5
98                                         verticalAlignment: Text.AlignVCenter; text: title; color: (unread=="True") ? "white" : "#7b97fd";
99                                         width: wrapper.width; wrapMode: Text.WordWrap; font.bold: false;
100                                     }
101                                 }
102                                 MouseArea { anchors.fill: wrapper;
103                                     onClicked: { articleView.positionViewAtIndex(index, ListView.Contain); articleView.visible = true; }
104                                 }
105                         }
106                     }
107         model: articles
108     }
109
110     XmlListModel {
111         id: articles
112
113         source: articleViewer.feedid == "" ? "" : "http://localhost:8000/articles/" + feedid + "?onlyUnread=" + hideReadArticles
114         query: "/xml/article"
115
116         XmlRole { name: "title"; query: "title/string()" }
117         XmlRole { name: "articleid"; query: "articleid/string()"; isKey: true }
118         XmlRole { name: "path"; query: "path/string()" }
119         XmlRole { name: "unread"; query: "unread/string()"; isKey: true}
120     }
121
122
123 }