Declarative ROI can now report unnormalized ROI coordinates using the normalize property
[harmattan/cameraplus] / qml / CameraToolBar.js
1 // -*- js -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 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 spacing = (tools.width - width - tools.menuWidth) / len;
60
61     for (var x = 0; x < len; x++) {
62         var child = items[x];
63
64         if (x != 0) {
65             var prev = items[x - 1];
66             child.x = prev.x + prev.width + spacing;
67         }
68         else {
69             child.x = spacing + 80;
70         }
71
72         child.parent = tools;
73         child.visible = true;
74         child.y = 0;
75     }
76 }
77
78 function layout() {
79     if (stack.length == 0) {
80         return;
81     }
82
83     var items = stack[stack.length - 1];
84     var len = items.length;
85
86     if (!tools.expanded) {
87         hide(items);
88     }
89     else if (tools.width == tools.targetWidth) {
90         show(items);
91     }
92 }