-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCameraToolBar.qml
145 lines (123 loc) · 3.69 KB
/
CameraToolBar.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// -*- qml -*-
/*!
* This file is part of CameraPlus.
*
* Copyright (C) 2012-2014 Mohammed Sameer <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
import QtQuick 2.0
import CameraPlus 1.0
import "CameraToolBar.js" as Layout
Rectangle {
id: toolBar
property bool expanded: true
property real targetWidth: parent.width - anchors.leftMargin - anchors.rightMargin
property bool manualBack
property bool hideBack
signal clicked
property CameraToolBarTools tools
property CameraToolBarTools __currentTools
function push(tools, props) {
var toolsToPush
var comp
if (typeof tools == "string") {
comp = Qt.createComponent(tools)
if (comp.status == Component.Error) {
console.log("error creating " + tools + ": " + comp.errorString())
}
if (typeof(props) === "undefined") {
toolsToPush = comp.createObject(dock)
}
else {
toolsToPush = comp.createObject(dock, props)
}
}
else {
toolsToPush = tools
}
if (expanded) {
__currentTools = Layout.pushAndShow(toolsToPush, dock, stack)
}
else {
__currentTools = Layout.push(toolsToPush, dock, stack)
}
if (comp) {
stack.peek().comp = comp
}
}
function pop() {
__currentTools = Layout.pop(dock, stack);
}
function depth() {
return stack.length
}
onToolsChanged: {
push(tools)
}
onExpandedChanged: {
if (stack.length == 0) {
return
}
if (expanded) {
Layout.showLast(dock, stack)
}
else {
Layout.hideLast(dock, stack)
}
}
Component.onDestruction: Layout.clear(dock, stack)
width: expanded ? targetWidth : menu.width
height: menu.height
color: "black"
border.color: "gray"
radius: 20
Behavior on width {
PropertyAnimation { duration: 100 }
}
CameraToolIcon {
visible: !parent.hideBack
id: menu
rotation: parent.expanded ? 0 : 90
iconSource: cameraTheme.cameraToolBarMenuIcon
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
Behavior on rotation {
NumberAnimation { duration: 250 }
}
onClicked: {
if (parent.manualBack) {
parent.clicked()
} else if (!parent.expanded) {
parent.expanded = true
} else if (stack.length == 1) {
expanded = false
} else {
__currentTools = Layout.pop(dock, stack)
}
}
}
Stack {
id: stack
}
ToolBarLayout {
id: dock
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.left: parent.hideBack ? parent.left : menu.right
}
}