forked from papyros/qml-material
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolbar.qml
More file actions
239 lines (189 loc) · 6.75 KB
/
Copy pathToolbar.qml
File metadata and controls
239 lines (189 loc) · 6.75 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* QML Material - An application framework implementing Material Design.
*
* Copyright (C) 2014-2016 Michael Spencer <sonrisesoftware@gmail.com>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import QtQuick 2.4
import QtQuick.Controls 1.3 as Controls
import QtQuick.Layouts 1.1
import Material 0.3
/*!
\qmltype Toolbar
\inqmlmodule Material
\brief Provides the container used to hold the action bar of pages.
*/
View {
id: toolbar
anchors {
top: parent.top
left: parent.left
right: parent.right
}
property int actionBarHeight: {
if (!page || page.actionBar.hidden)
return 0
var height = implicitHeight + page.actionBar.extendedHeight
if (page.rightSidebar && page.rightSidebar.showing) {
var sidebarHeight = implicitHeight + page.rightSidebar.actionBar.extendedHeight
height = Math.max(height, sidebarHeight)
}
return height
}
property int targetHeight: actionBarHeight
property int maxActionCount: Device.type === Device.desktop
? 5 : Device.type === Device.tablet ? 4 : 3
property bool clientSideDecorations: false
property string color: "white"
property var page
property bool showBackButton
property color decorationColor: page && page.actionBar
? page.actionBar.decorationColor
: Theme.primaryDarkColor
opacity: page && page.actionBar.hidden ? 0 : 1
backgroundColor: page ? page.actionBar.backgroundColor.a === 0
? page.backgroundColor : page.actionBar.backgroundColor
: Theme.primaryColor
implicitHeight: 1 * Device.gridUnit * Units.dp
height: targetHeight
elevation: backgroundColor === page.color ? 0 : page.actionBar.elevation
fullWidth: true
clipContent: true
Behavior on decorationColor {
ColorAnimation { duration: MaterialAnimation.pageTransitionDuration }
}
Behavior on height {
NumberAnimation { duration: MaterialAnimation.pageTransitionDuration }
}
Behavior on opacity {
NumberAnimation { duration: MaterialAnimation.pageTransitionDuration }
}
function pop(page) {
stack.pop(page.actionBar)
if (page.rightSidebar && page.rightSidebar.actionBar)
rightSidebarStack.pop(page.rightSidebar.actionBar)
else
rightSidebarStack.pop(emptyRightSidebar)
toolbar.page = page
}
function push(page) {
stack.push(page.actionBar)
page.actionBar.toolbar = toolbar
toolbar.page = page
if (page.rightSidebar && page.rightSidebar.actionBar)
rightSidebarStack.push(page.rightSidebar.actionBar)
else
rightSidebarStack.push(emptyRightSidebar)
}
function replace(page) {
page.actionBar.maxActionCount = Qt.binding(function() { return toolbar.maxActionCount })
toolbar.page = page
stack.replace(page.actionBar)
if (page.rightSidebar && page.rightSidebar.actionBar)
rightSidebarStack.replace(page.rightSidebar.actionBar)
else
rightSidebarStack.replace(emptyRightSidebar)
}
Rectangle {
anchors.fill: rightSidebarStack
color: page.rightSidebar && page.rightSidebar.actionBar.backgroundColor
? Qt.darker(page.rightSidebar.actionBar.backgroundColor,1).a === 0
? page.rightSidebar.color
: page.rightSidebar.actionBar.backgroundColor
: Theme.primaryColor
}
Controls.StackView {
id: stack
height: actionBarHeight
Behavior on height {
NumberAnimation { duration: MaterialAnimation.pageTransitionDuration }
}
anchors {
left: parent.left
right: page && page.rightSidebar
? rightSidebarStack.left
: clientSideDecorations ? windowControls.left : parent.right
rightMargin: 0
}
delegate: toolbarDelegate
}
Controls.StackView {
id: rightSidebarStack
height: actionBarHeight
width: page && page.rightSidebar
? page.rightSidebar.width
: 0
Behavior on height {
NumberAnimation { duration: MaterialAnimation.pageTransitionDuration }
}
anchors {
right: clientSideDecorations ? windowControls.left : parent.right
rightMargin: page.rightSidebar ? page.rightSidebar.anchors.rightMargin : 0
}
delegate: toolbarDelegate
}
Controls.StackViewDelegate {
id: toolbarDelegate
pushTransition: Controls.StackViewTransition {
SequentialAnimation {
id: actionBarShowAnimation
ParallelAnimation {
NumberAnimation {
duration: MaterialAnimation.pageTransitionDuration
target: enterItem
property: "opacity"
from: 0
to: 1
}
NumberAnimation {
duration: MaterialAnimation.pageTransitionDuration
target: enterItem
property: "y"
from: enterItem.height
to: 0
}
}
}
SequentialAnimation {
id: previousHideAnimation
ParallelAnimation {
NumberAnimation {
duration: MaterialAnimation.pageTransitionDuration
target: exitItem
property: "opacity"
to: 0
}
NumberAnimation {
duration: MaterialAnimation.pageTransitionDuration
target: exitItem
property: "y"
to: exitItem ? -exitItem.height : 0
}
}
}
}
}
Row {
id: windowControls
visible: clientSideDecorations
anchors {
verticalCenter: stack.verticalCenter
right: parent.right
rightMargin: 16 * Units.dp
}
spacing: 24 * Units.dp
IconButton {
iconName: "navigation/close"
color: Theme.lightDark(toolbar.backgroundColor, Theme.light.textColor,
Theme.dark.textColor)
onClicked: Qt.quit()
}
}
Component {
id: emptyRightSidebar
Item {}
}
}