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
|
/*
* Copyright 2012 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program 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 Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.1
import QtGraphicalEffects 1.0
import org.kde.plasma.mobilecomponents 0.2
import "private"
/**Documented API
Inherits:
Item
Imports:
QtQuick 2.1
Description:
Split Drawers are used to expose additional UI elements which are optional and can be used in conjunction with the main UI elements. For example the Resource Browser uses a Split Drawer to select different kinds of filters for the main view.
Properties:
bool open:
If true the drawer is open showing the contents of the "drawer" component.
Item page:
It's the default property. it's the main content of the drawer page, the part that is always shown
Item drawer:
It's the part that can be pulled in and out, will act as a sidebar.
int visibleDrawerWidth: the width of the visible portion of the drawer: it updates while dragging or animating
**/
AbstractDrawer {
id: root
anchors {
fill: parent
}
visible: true
default property alias page: mainPage.data
property Item contentItem
property alias opened: sidebar.open
property int visibleDrawerWidth: browserFrame.x
Component.onCompleted: {
mainPage.width = browserFrame.width
}
onContentItemChanged: contentItem.parent = drawerPage
MouseArea {
id: mouseEventListener
z: 200
drag.filterChildren: true
//drag.target: browserFrame
property int startMouseX
property int oldMouseX
property int startBrowserFrameX
property bool toggle: false
property string startState
anchors.fill: parent
onPressed: {
if (drawerPage.children.length == 0 || (browserFrame.state == "Closed" && mouse.x > Units.gridUnit) ||
mouse.x < browserFrame.x) {
mouse.accepted = false;
return;
}
toggle = true;
startBrowserFrameX = browserFrame.x;
oldMouseX = startMouseX = mouse.x;
startState = browserFrame.state;
browserFrame.state = "Dragging";
browserFrame.x = startBrowserFrameX;
}
onPositionChanged: {
browserFrame.x = Math.max(0, browserFrame.x + mouse.x - oldMouseX);
oldMouseX = mouse.x;
if (Math.abs(mouse.x - startMouseX) > Units.gridUnit * 2) {
toggle = false;
}
}
onReleased: {
if (toggle) {
browserFrame.state = startState == "Open" ? "Closed" : "Open"
} else if (browserFrame.x < sidebar.width / 2) {
browserFrame.state = "Closed";
} else {
browserFrame.state = "Open";
}
}
onClicked: root.clicked()
}
Rectangle {
id: browserFrame
z: 100
color: Theme.backgroundColor
state: "Closed"
onStateChanged: sidebar.open = (state != "Closed")
anchors {
top: parent.top
bottom: parent.bottom
}
width: root.width;
Item {
id: mainPage
onChildrenChanged: mainPage.children[0].anchors.fill = mainPage
anchors.fill: parent
}
Rectangle {
anchors.fill: parent
color: "black"
opacity: Math.min(0.4, 0.4 * (browserFrame.x / sidebar.width))
}
LinearGradient {
width: Units.gridUnit/2
anchors {
right: parent.left
top: parent.top
bottom: parent.bottom
rightMargin: -1
}
start: Qt.point(0, 0)
end: Qt.point(Units.gridUnit/2, 0)
gradient: Gradient {
GradientStop {
position: 0.0
color: "transparent"
}
GradientStop {
position: 0.7
color: Qt.rgba(0, 0, 0, 0.15)
}
GradientStop {
position: 1.0
color: Qt.rgba(0, 0, 0, 0.3)
}
}
}
states: [
State {
name: "Open"
PropertyChanges {
target: browserFrame
x: sidebar.width
}
},
State {
name: "Dragging"
PropertyChanges {
target: browserFrame
x: mouseEventListener.startBrowserFrameX
}
},
State {
name: "Closed"
PropertyChanges {
target: browserFrame
x: 0
}
}
]
transitions: [
Transition {
//Exclude Dragging
to: "Open,Closed,Hidden"
NumberAnimation {
properties: "x"
duration: Units.longDuration
easing.type: Easing.InOutQuad
}
}
]
}
Item {
id: sidebar
property bool open: false
onOpenChanged: {
if (drawerPage.children.length == 0) {
return;
}
if (open) {
browserFrame.state = "Open";
} else {
browserFrame.state = "Closed";
}
}
width: Math.min(parent.width/4*3, Math.max(root.contentItem ? root.contentItem.implicitWidth : 0, parent.width/4))
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
}
Item {
id: drawerPage
anchors.fill: parent
clip: false
onChildrenChanged: drawerPage.children[0].anchors.fill = drawerPage
}
}
}
|