Initial commit
[ubi] / qml / ubi / PageStack.qml
1 import QtQuick 1.0
2
3 /* copyright (C) 2010-2012 Stuart Howarth */
4
5 Item {
6     id: root
7
8     property alias initialPage: initalPage.source
9     property Item currentPage: pageView.currentItem.item
10     property int index: pageView.currentIndex
11
12     function prevPage() {
13         return pageModel.children[pageView.currentIndex-1].item;
14     }
15
16     function push(item, immediate) {
17         var loader = pageModel.children[pageView.currentIndex + 1];
18         loader.source = item;
19         if (immediate) {
20             pageView.highlightMoveDuration = 0;
21         }
22         else {
23             pageView.highlightMoveDuration = 200;
24         }
25         pageView.incrementCurrentIndex();
26     }
27
28     function pop(immediate) {
29         var i = pageView.currentIndex;
30         if (immediate) {
31             pageView.highlightMoveDuration = 0;
32         }
33         else {
34             pageView.highlightMoveDuration = 300;
35         }
36         pageView.decrementCurrentIndex();
37         pageModel.children[i].source = "";
38         taskBar.close();
39         root.currentPage.reloadMenu();
40         //mask.state = "idle";
41     }
42
43     function clear(immediate) {
44         if (immediate) {
45             pageView.highlightMoveDuration = 0;
46         }
47         else {
48             pageView.highlightMoveDuration = 300;
49         }
50         pageView.currentIndex = 0;
51         for (var i = 1; i < pageModel.children.length; i++) {
52             pageModel.children[i].source = "";
53         }
54     }
55
56     function replace(item, immediate) {
57         root.pop(true);
58         root.push(item, immediate);
59     }
60
61     function dim() {
62         root.state = "dim";
63     }
64
65     function undim() {
66         root.state = "";
67     }
68
69     anchors.fill: parent
70
71     VisualItemModel {
72         id: pageModel
73
74         Loader {
75             id: initalPage
76
77             width: mainWindow.width
78             height: mainWindow.height
79             opacity: index == pageView.currentIndex ? 1 : 0
80         }
81
82         Loader {
83             width: mainWindow.width
84             height: mainWindow.height
85             opacity: index == pageView.currentIndex ? 1 : 0
86         }
87
88         Loader {
89             width: mainWindow.width
90             height: mainWindow.height
91             opacity: index == pageView.currentIndex ? 1 : 0
92         }
93
94         Loader {
95             width: mainWindow.width
96             height: mainWindow.height
97             opacity: index == pageView.currentIndex ? 1 : 0
98         }
99
100         Loader {
101             width: mainWindow.width
102             height: mainWindow.height
103             opacity: index == pageView.currentIndex ? 1 : 0
104         }
105
106         Loader {
107             width: mainWindow.width
108             height: mainWindow.height
109             opacity: index == pageView.currentIndex ? 1 : 0
110         }
111
112         Loader {
113             width: mainWindow.width
114             height: mainWindow.height
115             opacity: index == pageView.currentIndex ? 1 : 0
116         }
117
118         Loader {
119             width: mainWindow.width
120             height: mainWindow.height
121             opacity: index == pageView.currentIndex ? 1 : 0
122         }
123
124         Loader {
125             width: mainWindow.width
126             height: mainWindow.height
127             opacity: index == pageView.currentIndex ? 1 : 0
128         }
129
130         Loader {
131             width: mainWindow.width
132             height: mainWindow.height
133             opacity: index == pageView.currentIndex ? 1 : 0
134         }
135
136         Loader {
137             width: mainWindow.width
138             height: mainWindow.height
139             opacity: index == pageView.currentIndex ? 1 : 0
140         }
141
142         Loader {
143             width: mainWindow.width
144             height: mainWindow.height
145             opacity: index == pageView.currentIndex ? 1 : 0
146         }
147
148         Loader {
149             width: mainWindow.width
150             height: mainWindow.height
151             opacity: index == pageView.currentIndex ? 1 : 0
152         }
153
154         Loader {
155             width: mainWindow.width
156             height: mainWindow.height
157             opacity: index == pageView.currentIndex ? 1 : 0
158         }
159
160         Loader {
161             width: mainWindow.width
162             height: mainWindow.height
163             opacity: index == pageView.currentIndex ? 1 : 0
164         }
165
166         Loader {
167             width: mainWindow.width
168             height: mainWindow.height
169             opacity: index == pageView.currentIndex ? 1 : 0
170         }
171
172         Loader {
173             width: mainWindow.width
174             height: mainWindow.height
175             opacity: index == pageView.currentIndex ? 1 : 0
176         }
177
178         Loader {
179             width: mainWindow.width
180             height: mainWindow.height
181             opacity: index == pageView.currentIndex ? 1 : 0
182         }
183
184         Loader {
185             width: mainWindow.width
186             height: mainWindow.height
187             opacity: index == pageView.currentIndex ? 1 : 0
188         }
189
190         Loader {
191             width: mainWindow.width
192             height: mainWindow.height
193             opacity: index == pageView.currentIndex ? 1 : 0
194         }
195
196         Loader {
197             width: mainWindow.width
198             height: mainWindow.height
199             opacity: index == pageView.currentIndex ? 1 : 0
200         }
201
202         Loader {
203             width: mainWindow.width
204             height: mainWindow.height
205             opacity: index == pageView.currentIndex ? 1 : 0
206         }
207
208         Loader {
209             width: mainWindow.width
210             height: mainWindow.height
211             opacity: index == pageView.currentIndex ? 1 : 0
212         }
213
214         Loader {
215             width: mainWindow.width
216             height: mainWindow.height
217             opacity: index == pageView.currentIndex ? 1 : 0
218         }
219
220         Loader {
221             width: mainWindow.width
222             height: mainWindow.height
223             opacity: index == pageView.currentIndex ? 1 : 0
224         }
225
226         Loader {
227             width: mainWindow.width
228             height: mainWindow.height
229             opacity: index == pageView.currentIndex ? 1 : 0
230         }
231
232         Loader {
233             width: mainWindow.width
234             height: mainWindow.height
235             opacity: index == pageView.currentIndex ? 1 : 0
236         }
237
238         Loader {
239             width: mainWindow.width
240             height: mainWindow.height
241             opacity: index == pageView.currentIndex ? 1 : 0
242         }
243
244         Loader {
245             width: mainWindow.width
246             height: mainWindow.height
247             opacity: index == pageView.currentIndex ? 1 : 0
248         }
249
250         Loader {
251             width: mainWindow.width
252             height: mainWindow.height
253             opacity: index == pageView.currentIndex ? 1 : 0
254         }
255
256         Loader {
257             width: mainWindow.width
258             height: mainWindow.height
259             opacity: index == pageView.currentIndex ? 1 : 0
260         }
261     }
262
263     ListView {
264         id: pageView
265         anchors.fill: parent
266         model: pageModel
267         orientation: ListView.Horizontal
268         interactive: false
269         highlightMoveDuration: 100
270     }
271
272     states: State {
273         name: "dim"
274         PropertyChanges { target: root; opacity: 0.1 }
275     }
276
277     transitions: Transition {
278         PropertyAnimation { target: root; properties: "opacity"; duration: 300 }
279     }
280 }
281