Stop video playback when we lose policy resources
[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 1.1
24 import com.nokia.meego 1.1
25 import "CameraToolBar.js" as Layout
26
27 Rectangle {
28     id: tools
29     property bool expanded: false
30     property list<Item> items
31     property int targetWidth: parent.width - (2 * anchors.leftMargin)
32     property alias menuWidth: menu.width
33     property bool manualBack: false
34     property bool hideBack: false
35     signal clicked
36
37     height: menu.height
38     width: expanded ? targetWidth : menu.width
39     color: expanded ? "black" : width == menu.width ? "transparent" : "black"
40     border.color: expanded ? "gray" : width == menu.width ? "transparent" : "gray"
41     radius: 20
42
43     Behavior on width {
44         PropertyAnimation { duration: 100 }
45     }
46
47     ToolIcon {
48         property bool __isMenu: true
49         visible: !parent.hideBack
50         id: menu
51         anchors.verticalCenter: parent.verticalCenter
52         iconSource: "image://theme/icon-m-toolbar-back-white"
53         onClicked: {
54             if (tools.manualBack) {
55                 tools.clicked()
56                 return
57             }
58
59             if (!expanded) {
60                 expanded = true
61             } else if (Layout.stack.length == 1) {
62                 expanded = false
63             } else {
64                 Layout.pop()
65             }
66         }
67
68         anchors.left: parent.left
69         rotation: 180
70     }
71
72     onExpandedChanged: {
73         if (tools.expanded) {
74             tools.push(tools.items)
75         } else {
76             tools.pop()
77         }
78     }
79
80     onWidthChanged: Layout.layout()
81     onTargetWidthChanged: Layout.layout()
82
83     function push(items) {
84         return Layout.push(items)
85     }
86
87     function pop() {
88         return Layout.pop()
89     }
90
91     state: "collapsed"
92     states: [
93         State {
94             name: "expanded"
95             when: tools.expanded
96         },
97         State {
98             name: "collapsed"
99             when: !tools.expanded
100         }
101     ]
102
103     transitions: [
104         Transition {
105             from: "expanded"
106             to: "collapsed"
107
108             PropertyAnimation {
109                 property: "rotation"
110                 target: menu
111                 from: 0
112                 to: 180
113                 duration: 500
114             }
115         },
116         Transition {
117             from: "collapsed"
118             to: "expanded"
119             PropertyAnimation {
120                 property: "rotation"
121                 target: menu
122                 from: 180
123                 to: 360
124                 duration: 500
125             }
126         }
127     ]
128 }