Reworked CameraToolBar
[harmattan/cameraplus] / qml / CameraToolBar.js
index 8ecb835..36b716b 100644 (file)
 
 var stack = new Array();
 
-function push(items) {
+function __push(tools) {
     if (stack.length >= 1) {
        hide(stack[stack.length - 1]);
     }
 
-    stack.push(items);
+    var container = createContainer(tools);
+    stack.push(container);
 
-    layout();
+    return container;
 }
 
-function pop() {
-    var items = stack[stack.length - 1];
-    hide(items);
-    stack.pop();
-    layout();
+function push(tools) {
+    var container = __push(tools);
+    return container.tools;
 }
 
-function hide(items) {
-    var len = items.length;
+function pop() {
+    if (stack.length == 0) {
+       return null;
+    }
+
+    var container = stack.pop();
+    hide(container);
+    destroyContainer(container);
 
-    for (var x = 0; x < len; x++) {
-        var item = items[x];
-        item.visible = false;
+    if (stack.length == 0) {
+       return null;
     }
+
+    container = stack[stack.length - 1];
+    show(container);
+
+    return container.tools;
 }
 
-function show(items) {
-    var len = items.length;
+function show(container) {
+    container.tools.width = dock.width;
+    container.tools.height = dock.height;
+    container.tools.visible = true;
+}
 
-    var width = 0;
-    for (var x = 0; x < len; x++) {
-       width += items[x].width;
-    }
+function hide(container) {
+    container.tools.visible = false;
+}
 
-    var totalWidth = tools.width - width;
-    if (tools.hideBack) {
-       len -= 1;
-    } else {
-       totalWidth -= tools.menuWidth;
-    }
+function createContainer(tools) {
+    var container = toolsContainer.createObject(dock);
+    container.tools = tools;
+    container.owner = tools.parent;
+    container.tools.parent = dock;
 
-    var spacing = totalWidth / len;
+    return container;
+}
 
-    for (var x = 0; x < items.length; x++) {
-       var child = items[x];
+function destroyContainer(container) {
+    container.tools.parent = container.owner;
+    container.tools = null;
+    container.owner = null;
+    container.destroy();
+}
 
-       if (x != 0) {
-           var prev = items[x - 1];
-           child.x = prev.x + prev.width + spacing;
-       } else if (tools.hideBack) {
-           child.x = 0;
-       } else {
-           child.x = spacing + 80;
-       }
+function pushAndShow(tools) {
+    var container = __push(tools);
+    show(container);
+    return container.tools;
+}
 
-       child.parent = tools;
-       child.visible = true;
-       child.y = 0;
+function clear() {
+    while (stack.length > 0) {
+       pop();
     }
 }
 
-function layout() {
-    if (stack.length == 0) {
-       return;
-    }
+function isEmpty() {
+    return stack.length == 0 ? true : false;
+}
+
+function showLast() {
+    show(stack[stack.length - 1])
+}
+
+function hideLast() {
+    hide(stack[stack.length - 1])
+}
 
-    var items = stack[stack.length - 1];
-    var len = items.length;
+function calculateChildrenWidth(children) {
+    var totalWidth = 0;
 
-    if (!tools.expanded) {
-       hide(items);
+    for (var x = 0; x < children.length; x++) {
+       if (children[x].visible) {
+           totalWidth += children[x].width;
+       }
     }
-    else if (tools.width == tools.targetWidth) {
-       show(items);
+
+    return totalWidth;
+}
+
+function countVisibleChildren(children) {
+    var total = 0;
+
+    for (var x = 0; x < children.length; x++) {
+       if (children[x].visible) {
+           ++total;
+       }
     }
+
+    return total;
 }