Show/hide UI elements for setting resolution and aspect ratio
[harmattan/cameraplus] / qml / CameraToolBar.qml
1 // -*- qml -*-
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 import QtQuick 2.0
24 import "CameraToolBar.js" as Layout
25
26 Rectangle {
27     id: toolBar
28
29     property bool expanded: true
30     property real targetWidth: parent.width - anchors.leftMargin - anchors.rightMargin
31     property bool manualBack: false
32     property bool hideBack: false
33     signal clicked
34
35     property CameraToolBarTools tools
36     property CameraToolBarTools __currentTools
37
38     function push(tools) {
39         if (expanded) {
40             __currentTools = Layout.pushAndShow(tools)
41         }
42         else {
43             __currentTools = Layout.push(tools)
44         }
45     }
46
47     function pop() {
48         __currentTools = Layout.pop();
49     }
50
51     onToolsChanged: {
52         push(tools)
53     }
54
55     onExpandedChanged: {
56         if (Layout.isEmpty()) {
57             return
58         }
59
60         if (expanded) {
61             Layout.showLast()
62         }
63         else {
64             Layout.hideLast()
65         }
66     }
67
68     Component.onDestruction: Layout.clear()
69
70     width: expanded ? targetWidth : menu.width
71     height: menu.height
72     color: "black"
73     border.color: "gray"
74     radius: 20
75
76     states: [
77         State {
78             name: "expanded"
79             when: expanded
80         },
81         State {
82             name: "collapsed"
83             when: !expanded
84         }
85     ]
86
87     transitions: [
88         Transition {
89             from: "expanded"
90             to: "collapsed"
91
92             PropertyAnimation {
93                 property: "rotation"
94                 target: menu
95                 from: 0
96                 to: 180
97                 duration: 250
98             }
99         },
100         Transition {
101             from: "collapsed"
102             to: "expanded"
103             PropertyAnimation {
104                 property: "rotation"
105                 target: menu
106                 from: 180
107                 to: 360
108                 duration: 250
109             }
110         }
111     ]
112
113     Behavior on width {
114         PropertyAnimation { duration: 100 }
115     }
116
117     CameraToolIcon {
118         visible: !parent.hideBack
119         id: menu
120         anchors.verticalCenter: parent.verticalCenter
121         iconId: cameraTheme.cameraToolBarMenuIcon
122         anchors.left: parent.left
123         anchors.top: parent.top
124         anchors.bottom: parent.bottom
125
126         onClicked: {
127             if (parent.manualBack) {
128                 parent.clicked()
129             } else if (!parent.expanded) {
130                 parent.expanded = true
131             } else if (Layout.stack.length == 1) {
132                 expanded = false
133             } else {
134                 __currentTools = Layout.pop()
135             }
136         }
137     }
138
139     Rectangle {
140         id: dock
141         property real menuWidth: parent.hideBack ? 0 : menu.width
142         property real leftMargin: (parent.width - __currentTools.childrenWidth - menuWidth) / __currentTools.childrenLen
143         color: "transparent"
144         anchors.top: parent.top
145         anchors.bottom: parent.bottom
146         anchors.right: parent.right
147         anchors.left: parent.hideBack ? parent.left : menu.right
148         anchors.leftMargin: parent.hideBack ? 0 : leftMargin
149     }
150
151     Component {
152         id: toolsContainer
153         Item {
154             property Item tools
155             property Item owner
156         }
157     }
158 }