Drop unneeded CameraOverlay.qml
[harmattan/cameraplus] / qml / CameraToolBar.js
1 // -*- js -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 var stack = new Array();
24
25 function push(items) {
26     if (stack.length >= 1) {
27         hide(stack[stack.length - 1]);
28     }
29
30     stack.push(items);
31
32     layout();
33 }
34
35 function pop() {
36     var items = stack[stack.length - 1];
37     hide(items);
38     stack.pop();
39     layout();
40 }
41
42 function hide(items) {
43     var len = items.length;
44
45     for (var x = 0; x < len; x++) {
46         var item = items[x];
47         item.visible = false;
48     }
49 }
50
51 function show(items) {
52     var len = items.length;
53
54     var width = 0;
55     for (var x = 0; x < len; x++) {
56         width += items[x].width;
57     }
58
59     var totalWidth = tools.width - width;
60     if (tools.hideBack) {
61         len -= 1;
62     } else {
63         totalWidth -= tools.menuWidth;
64     }
65
66     var spacing = totalWidth / len;
67
68     for (var x = 0; x < items.length; x++) {
69         var child = items[x];
70
71         if (x != 0) {
72             var prev = items[x - 1];
73             child.x = prev.x + prev.width + spacing;
74         } else if (tools.hideBack) {
75             child.x = 0;
76         } else {
77             child.x = spacing + 80;
78         }
79
80         child.parent = tools;
81         child.visible = true;
82         child.y = 0;
83     }
84 }
85
86 function layout() {
87     if (stack.length == 0) {
88         return;
89     }
90
91     var items = stack[stack.length - 1];
92     var len = items.length;
93
94     if (!tools.expanded) {
95         hide(items);
96     }
97     else if (tools.width == tools.targetWidth) {
98         show(items);
99     }
100 }