forked from papyros/qml-material
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropdown.qml
More file actions
193 lines (159 loc) · 5.41 KB
/
Copy pathDropdown.qml
File metadata and controls
193 lines (159 loc) · 5.41 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
/*
* QML Material - An application framework implementing Material Design.
*
* Copyright (C) 2015-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.Window 2.2
import Material 0.3
import Material.Extras 0.1
/*!
\qmltype Dropdown
\inqmlmodule Material
\brief Represents a dropdown menu that can display a variety of content.
*/
PopupBase {
id: dropdown
default property alias data: view.data
property int anchor: Item.TopRight
property alias internalView: view
visible: view.opacity > 0
closeOnResize: true
function open(caller, offsetX, offsetY) {
__lastFocusedItem = Window.activeFocusItem
parent = Utils.findRootChild(dropdown, overlayLayer)
if (!parent.enabled)
return
if (parent.currentOverlay)
parent.currentOverlay.close()
if(typeof offsetX === "undefined")
offsetX = 0
if(typeof offsetY === "undefined")
offsetY = 0
var position = caller.mapToItem(dropdown.parent, 0, 0)
// Check to make sure we are within the window bounds, move if we need to
var globalPos = caller.mapToItem(null, 0, 0)
var root = Utils.findRoot(dropdown)
if (__internal.left) {
dropdown.x = position.x
} else if (__internal.center) {
dropdown.x = caller.width / 2 - dropdown.width / 2
} else {
dropdown.x = position.x + caller.width - dropdown.width
}
if (__internal.top) {
dropdown.y = position.y
} else if (__internal.center) {
dropdown.y = caller.height / 2 - dropdown.height / 2
} else {
dropdown.y = position.y + caller.height - dropdown.height
}
dropdown.x += offsetX
dropdown.y += offsetY
if(dropdown.y + height > root.height)
dropdown.y += -((dropdown.y + height + 16 * Units.dp) - root.height)
if(dropdown.x + width > root.width)
dropdown.x += -((dropdown.x + width + 16 * Units.dp) - root.width)
showing = true
parent.currentOverlay = dropdown
opened()
}
QtObject {
id: __internal
property bool left: dropdown.anchor == Item.Left || dropdown.anchor == Item.TopLeft ||
dropdown.anchor == Item.BottomLeft
property bool right: dropdown.anchor == Item.Right || dropdown.anchor == Item.TopRight ||
dropdown.anchor == Item.BottomRight
property bool top: dropdown.anchor == Item.Top || dropdown.anchor == Item.TopLeft ||
dropdown.anchor == Item.TopRight
property bool bottom: dropdown.anchor == Item.Bottom ||
dropdown.anchor == Item.BottomLeft ||
dropdown.anchor == Item.BottomRight
property bool center: dropdown.anchor == Item.Center
}
View {
id: view
elevation: 2
radius: 2 * Units.dp
anchors.left: __internal.left ? parent.left : undefined
anchors.right: __internal.right ? parent.right : undefined
anchors.top: __internal.top ? parent.top : undefined
anchors.bottom: __internal.bottom ? parent.bottom : undefined
anchors.horizontalCenter: __internal.center ? parent.horizontalCenter : undefined
anchors.verticalCenter: __internal.center ? parent.verticalCenter : undefined
}
state: showing ? "open" : "closed"
states: [
State {
name: "closed"
PropertyChanges {
target: view
opacity: 0
}
},
State {
name: "open"
PropertyChanges {
target: view
opacity: 1
width: dropdown.width
height: dropdown.height
}
}
]
transitions: [
Transition {
from: "open"
to: "closed"
NumberAnimation {
target: internalView
property: "opacity"
duration: 400
easing.type: Easing.InOutQuad
}
SequentialAnimation {
PauseAnimation {
duration: 200
}
NumberAnimation {
target: internalView
property: "width"
duration: 200
easing.type: Easing.InOutQuad
}
}
NumberAnimation {
target: internalView
property: "height"
duration: 400
easing.type: Easing.InOutQuad
}
},
Transition {
from: "closed"
to: "open"
NumberAnimation {
target: internalView
property: "opacity"
duration: 400
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: internalView
property: "width"
duration: 200
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: internalView
property: "height"
duration: 400
easing.type: Easing.InOutQuad
}
}
]
}