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
|
/*
* Copyright 2015 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 QtQuick.Layouts 1.2
import QtGraphicalEffects 1.0
import org.kde.plasma.mobilecomponents 0.2
MouseArea {
id: button
property alias iconSource: icon.source
Layout.minimumWidth: Units.iconSizes.large
Layout.maximumWidth: Layout.minimumWidth
implicitWidth: Units.iconSizes.large
implicitHeight: width
drag {
target: button
axis: Drag.XAxis
minimumX: contextDrawer ? 0 : parent.width/2 - width/2
maximumX: globalDrawer ? parent.width : parent.width/2 - width/2
}
function toggle() {
showAnimation.running = false;
if (transform[0].y < button.height) {
showAnimation.to = button.height;
} else {
showAnimation.to = 0;
}
showAnimation.running = true;
}
transform: Translate {}
onReleased: {
if (globalDrawer && x > Math.min(parent.width/4*3, parent.width/2 + globalDrawer.contentItem.width/2)) {
globalDrawer.open();
contextDrawer.close();
} else if (contextDrawer && x < Math.max(parent.width/4, parent.width/2 - contextDrawer.contentItem.width/2)) {
if (contextDrawer) {
contextDrawer.open();
}
if (globalDrawer) {
globalDrawer.close();
}
} else {
if (globalDrawer) {
globalDrawer.close();
}
if (contextDrawer) {
contextDrawer.close();
}
}
}
Connections {
target: globalDrawer
onPositionChanged: {
if (!button.pressed) {
button.x = globalDrawer.contentItem.width * globalDrawer.position + button.parent.width/2 - button.width/2;
}
}
}
Connections {
target: contextDrawer
onPositionChanged: {
if (!button.pressed) {
button.x = button.parent.width/2 - button.width/2 - contextDrawer.contentItem.width * contextDrawer.position;
}
}
}
Connections {
target: button.parent
onWidthChanged: button.x = button.parent.width/2 - button.width/2
}
onXChanged: {
if (button.pressed) {
if (globalDrawer) {
globalDrawer.position = Math.min(1, Math.max(0, (x - button.parent.width/2 + button.width/2)/globalDrawer.contentItem.width));
}
if (contextDrawer) {
contextDrawer.position = Math.min(1, Math.max(0, (button.parent.width/2 - button.width/2 - x)/contextDrawer.contentItem.width));
}
}
}
NumberAnimation {
id: showAnimation
target: button.transform[0]
properties: "y"
duration: Units.longDuration
easing.type: Easing.InOutQuad
}
Item {
id: background
anchors {
fill: parent
leftMargin: -Units.gridUnit
rightMargin: -Units.gridUnit
}
Rectangle {
radius: width/2
anchors.centerIn: parent
height: parent.height - Units.smallSpacing*2
width: height
color: button.pressed ? Theme.highlightColor : Theme.backgroundColor
Icon {
id: icon
anchors {
fill: parent
margins: Units.smallSpacing
}
}
ActionButtonArrow {
anchors {
right: parent.left
rightMargin: Units.smallSpacing
}
visible: contextDrawer && contextDrawer.enabled
inverted: true
}
ActionButtonArrow {
anchors {
left: parent.right
leftMargin: Units.smallSpacing
}
visible: globalDrawer && globalDrawer.enabled
}
Behavior on color {
ColorAnimation {
duration: Units.longDuration
easing.type: Easing.InOutQuad
}
}
Behavior on x {
NumberAnimation {
duration: Units.longDuration
easing.type: Easing.InOutQuad
}
}
}
}
DropShadow {
anchors.fill: background
horizontalOffset: 0
verticalOffset: Units.smallSpacing/3
radius: Units.gridUnit / 3.5
samples: 16
color: button.pressed ? "transparent" : Qt.rgba(0, 0, 0, 0.5)
source: background
}
}
|