X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=blobdiff_plain;f=qml%2FCameraToolBar.js;h=b57a4a49ae9119ed25050ffee9c4c003b30959d1;hp=8ecb835d79dbfd53533628550946fae0ab1a1cda;hb=695e8f4f85218b41a7f27af281fcebe8238a33b7;hpb=4f831d7cd8e1a6072c057bf32e25ac7c3ac3a3d5 diff --git a/qml/CameraToolBar.js b/qml/CameraToolBar.js index 8ecb835..b57a4a4 100644 --- a/qml/CameraToolBar.js +++ b/qml/CameraToolBar.js @@ -22,79 +22,115 @@ 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 depth() { + return stack.length; +} + +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; }