Make capture buttons always visible even if we use zoom keys for capturing
[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(tools) {
26     if (stack.length >= 1) {
27         hide(stack[stack.length - 1]);
28     }
29
30     var container = createContainer(tools);
31     stack.push(container);
32
33     return container;
34 }
35
36 function push(tools) {
37     var container = __push(tools);
38     return container.tools;
39 }
40
41 function pop() {
42     if (stack.length == 0) {
43         return null;
44     }
45
46     var container = stack.pop();
47     hide(container);
48     destroyContainer(container);
49
50     if (stack.length == 0) {
51         return null;
52     }
53
54     container = stack[stack.length - 1];
55     show(container);
56
57     return container.tools;
58 }
59
60 function show(container) {
61     container.tools.width = dock.width;
62     container.tools.height = dock.height;
63     container.tools.visible = true;
64 }
65
66 function hide(container) {
67     container.tools.visible = false;
68 }
69
70 function createContainer(tools) {
71     var container = toolsContainer.createObject(dock);
72     container.tools = tools;
73     container.owner = tools.parent;
74     container.tools.parent = dock;
75
76     return container;
77 }
78
79 function destroyContainer(container) {
80     container.tools.parent = container.owner;
81     container.tools = null;
82     container.owner = null;
83     container.destroy();
84 }
85
86 function pushAndShow(tools) {
87     var container = __push(tools);
88     show(container);
89     return container.tools;
90 }
91
92 function clear() {
93     while (stack.length > 0) {
94         pop();
95     }
96 }
97
98 function depth() {
99     return stack.length;
100 }
101
102 function isEmpty() {
103     return stack.length == 0 ? true : false;
104 }
105
106 function showLast() {
107     show(stack[stack.length - 1])
108 }
109
110 function hideLast() {
111     hide(stack[stack.length - 1])
112 }
113
114 function calculateChildrenWidth(children) {
115     var totalWidth = 0;
116
117     for (var x = 0; x < children.length; x++) {
118         if (children[x].visible) {
119             totalWidth += children[x].width;
120         }
121     }
122
123     return totalWidth;
124 }
125
126 function countVisibleChildren(children) {
127     var total = 0;
128
129     for (var x = 0; x < children.length; x++) {
130         if (children[x].visible) {
131             ++total;
132         }
133     }
134
135     return total;
136 }