Added full rotation support to QML interface
[feedingit] / src / qml / FeedingIt.qml
1 import Qt 4.7
2 import "common" as Common
3 // Depends on qt4-declarative-qmlviewer
4
5 Item {
6     width: 480
7     height: 640
8     id: screen
9
10     Rectangle {
11         id: container
12         /*anchors.fill: parent;*/ color: "#343434";
13         anchors.centerIn: parent
14         transformOrigin: Item.Center
15
16         function categoryClicked(catid) {
17             feedsItem.catid = catid;
18             categoriesItem.isShown = false;
19             feedsItem.visible = true;
20         }
21
22         function feedClicked(feedid) {
23             flipper.feedid = feedid;
24             flipper.visible = true;
25         }
26
27 //        function articleClicked(articleid, index) {
28 //            // Assign the articleId for the current, next and previous article to the associated variables
29 //            // Note the modulo, so it goes around
30 //            //articleDisplay.articleindex = modulo(index,articlesItem.count)
31 //            //articleDisplay.nextArticle = articlesItem.getArticleid(modulo(index+1,articlesItem.count))
32 //            //articleDisplay.prevArticle = articlesItem.getArticleid(modulo(index-1,articlesItem.count))
33 //            //articleDisplay.articleid = articleid
34 //            //flipper.model = articlesItem.articles
35 //            flipper.visible = true;
36 //        }
37
38         function backClicked() {
39             if (flipper.visible && flipper.articleShown) {
40                 // We're viewing an article, and going back to article listing
41                 flipper.articleShown = false;
42                 flipper.reload()
43                 //flipper.articleid = "";
44                 //flipper.value = 1;
45                 //articlesItem.reload()
46                 return;
47             }
48             if (flipper.visible) {
49                 feedsItem.reload();
50                 flipper.visible = false;
51                 flipper.feedid = "";
52                 return;
53             }
54
55 //            if (articlesItem.visible) {
56 //                // Viewing articles, going back to feeds
57 //                //articlesItem.feedid = "";
58 //                feedsItem.reload();
59 //                articlesItem.visible = false;
60 //                //articlesItem.reload();
61 //                return;
62 //            }
63             if (feedsItem.visible) {
64                 // Viewing feeds, going back to categories
65                 //feedsItem.catid = "";
66                 feedsItem.visible = false;
67                 //feedsItem.reload();
68                 categoriesItem.isShown = true;
69                 return;
70             }
71             if (!feedsItem.visible) {
72                 // Viewing categories, quitting
73                 Qt.quit();
74             }
75         }
76
77         Common.Menu {
78             id: config
79             z: 5
80             property string hideReadFeeds : "False"
81             property string hideReadArticles : "False"
82
83             property bool isShown: false;
84
85             //width: parent.width; height: parent.height;
86
87             //height: 0
88             states: State {
89                 name: "shown"; when: config.isShown == true
90                 PropertyChanges { target: config; y: 66 }
91             }
92
93             transitions: Transition {
94                 NumberAnimation { properties: "y"; duration: 300; easing.type: "InOutQuad" }
95             }
96
97         }
98
99         Common.ConfirmationMessage {
100             id: confirmationMessage;
101             visible: false
102             onOkClicked: { var doc = new XMLHttpRequest();
103                 console.log(articlesItem.url+"&markAllAsRead=True")
104                 var url = articlesItem.url+"&markAllAsRead=True"
105                 console.log(url)
106                 doc.open("GET", url);
107                 doc.send();
108                 var xmlDoc=doc.responseXML;
109                 articlesItem.reload();
110                 feedsItem.reload()
111                 visible=false
112             }
113             onCancelClicked: visible=false
114         }
115
116         Common.ToolBar {
117             id: toolBar; z: 7
118             height: 66; anchors.top: parent.top; width: parent.width; opacity: 0.9
119             menuLabel: qsTr("Config"); backLabel: qsTr("Back")
120             nextLabel: qsTr("Next"); prevLabel: qsTr("Previous")
121             markAllLabel: qsTr("Mark All As Read"); zoomLabel: qsTr("Zoom")
122             taskSwitcherLabel: qsTr("Task Switch")
123             onMenuClicked: config.isShown = !config.isShown;
124             onBackClicked: container.backClicked()
125             onPrevClicked: flipper.prev();
126             onNextClicked: flipper.next();
127             onMarkAllClicked: {
128                 confirmationMessage.text = qsTr("Do you want to mark all items as read?");
129                 confirmationMessage.visible = true;
130             }
131             onZoomClicked: { flipper.zoomEnabled = !flipper.zoomEnabled; }
132             onTaskSwitcherClicked: {
133                 var doc = new XMLHttpRequest();
134                 var url = "http://localhost:8000/task"
135                 doc.open("GET", url);
136                 doc.send();
137                 //var xmlDoc=doc.responseXML;
138             }
139             //onRotateClicked: { container.rotation=-90; container.width=screen.height; container.height=screen.width;  }
140
141             states: [ State {
142                 name: "navButtons"; when: flipper.articleShown
143                 PropertyChanges { target: toolBar; nextVisible: !container.inPortrait; }
144                 PropertyChanges { target: toolBar; prevVisible: !container.inPortrait; }
145                 PropertyChanges { target: toolBar; zoomVisible: true; }
146             },
147                 State {
148                     name: "feedButtons"; when: (flipper.visible)&&(!flipper.articleShown)
149                     PropertyChanges { target: toolBar; markAllVisible: true; }
150                 },
151                 State {
152                     name: "quitButton"; when: (!feedsItem.visible)
153                     PropertyChanges { target: toolBar; quitVisible: true;}
154                     PropertyChanges { target: toolBar; backVisible: false; }
155                 }
156             ]
157         }
158
159         Item {
160             id: views
161             //x: 2;
162             //y:66;
163             width: parent.width // - 4
164             height: parent.height-toolBar.height;
165             anchors.top: toolBar.bottom; anchors.bottom: parent.bottom
166             y: toolBar.height;
167
168             Categories {
169                 // Loads the categoryList view and delegate
170                 id: categoriesItem
171                 property bool isShown: true;
172
173                 states: State {
174                     name: "shown"; when: categoriesItem.isShown == false
175                     PropertyChanges { target: categoriesItem; x: -screen.width }
176                 }
177
178                 transitions: Transition {
179                     NumberAnimation { properties: "x"; duration: 300; easing.type: "InOutQuad" }
180                 }
181
182             }
183
184             Feeds {
185
186                 // Loads the feedList view and delegate
187                 id: feedsItem;
188                 property string hideReadFeeds: config.hideReadFeeds
189                 visible: false;
190
191                 states: [
192                     State { name: "articlesShown"; when: flipper.visible; PropertyChanges { target: feedsItem; x: -parent.width } },
193                     State { name: "shown"; when: feedsItem.visible; PropertyChanges { target: feedsItem; x: 0 } }
194                 ]
195
196                 transitions: Transition {
197                     NumberAnimation { properties: "x"; duration: 300; easing.type: "InOutQuad" }
198                 }
199
200             }
201
202             ArticleViewer {
203                 id: flipper
204                 visible: false;
205                 property string hideReadArticles: config.hideReadArticles
206                 property string feedid: ""
207                 x: parent.width
208
209                 states: State { name: "shown"; when: flipper.visible; PropertyChanges { target: flipper; x: 0 }
210                     }
211
212                 transitions: Transition {
213                     NumberAnimation { properties: "x"; duration: 300; easing.type: "InOutQuad" }
214                 }
215             }
216         }
217
218         property bool lockRotation: false
219         property variant selectedOrientation: Orientation.UnknownOrientation
220         property variant activeOrientation: selectedOrientation == Orientation.UnknownOrientation ? runtime.orientation : selectedOrientation
221         state: "orientation " + activeOrientation
222         property bool inPortrait: (activeOrientation == Orientation.Portrait || activeOrientation == Orientation.PortraitInverted);
223
224         // rotation correction for landscape devices like N900
225         property bool landscapeWindow: screen.width > screen.height
226         property variant rotationDelta: landscapeWindow ? -90 : 0
227         rotation: rotationDelta
228
229         // initial state is portrait
230         property real baseWidth: landscapeWindow ? screen.height : screen.width
231         property real baseHeight: landscapeWindow ? screen.width : screen.height
232
233         width: baseWidth
234         height: baseHeight
235
236         function getAngle(orientation) {
237             var angle;
238             if (orientation == Orientation.Portrait) {
239                 angle = 0;
240             } else if (orientation == Orientation.Landscape) {
241                 angle = 90;
242             } else if (orientation == Orientation.PortraitInverted) {
243                 angle = 180;
244             } else if (orientation == Orientation.LandscapeInverted) {
245                 angle = 270;
246             } else {
247                 angle = 0;
248             }
249             return angle;
250         }
251
252         states: [
253             State {
254                 name: "orientation " + Orientation.Landscape
255                 PropertyChanges {
256                     target: container
257                     rotation: getAngle(Orientation.Landscape)+rotationDelta
258                     width: baseHeight
259                     height: baseWidth
260                 }
261                 StateChangeScript { script: console.log(container.width +"/"+container.height) }
262             },
263             State {
264                 name: "orientation " + Orientation.PortraitInverted
265                 PropertyChanges {
266                     target: container
267                     rotation: getAngle(Orientation.PortraitInverted)+rotationDelta
268                     width: baseWidth
269                     height: baseHeight
270                 }
271                 StateChangeScript { script: console.log(container.width +"/"+container.height) }
272             },
273             State {
274                 name: "orientation " + Orientation.LandscapeInverted
275                 PropertyChanges {
276                     target: container
277                     rotation: getAngle(Orientation.LandscapeInverted)+rotationDelta
278                     width: baseHeight
279                     height: baseWidth
280                 }
281                 StateChangeScript { script: console.log(container.width +"/"+container.height) }
282             }
283         ]
284         transitions: Transition {
285             ParallelAnimation {
286                 RotationAnimation {
287                     direction: RotationAnimation.Shortest
288                     duration: 300
289                     easing.type: Easing.InOutQuint
290                 }
291                 NumberAnimation {
292                     properties: "x,y,width,height"
293                     duration: 300
294                     easing.type: Easing.InOutQuint
295                 }
296             }
297         }
298
299     }
300 }