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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
/*
* Copyright (C) 2013 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.4
import Ubuntu.Components 1.3
Item {
id: root
property int itemIndex: 0
property string iconName
property string name
property int count: 0
property bool countVisible: false
property int progress: -1
property bool itemRunning: false
property bool itemFocused: false
property real maxAngle: 0
property bool inverted: false
property bool alerting: false
property bool highlighted: false
property bool shortcutHintShown: false
property int surfaceCount: 1
readonly property int effectiveHeight: Math.cos(angle * Math.PI / 180) * itemHeight
readonly property real foldedHeight: Math.cos(maxAngle * Math.PI / 180) * itemHeight
readonly property alias wiggling: wiggleAnim.running
property int itemWidth
property int itemHeight
// The angle used for rotating
property real angle: 0
// This is the offset that keeps the items inside the panel
property real offset: 0
property real itemOpacity: 1
property real brightness: 0
property double maxWiggleAngle: 5.0
QtObject {
id: priv
readonly property int wiggleDuration: UbuntuAnimation.SnapDuration
property real wiggleAngle: 0
}
SequentialAnimation {
id: wiggleAnim
running: alerting
loops: 1
alwaysRunToEnd: true
NumberAnimation {
target: priv
property: "wiggleAngle"
from: 0
to: maxWiggleAngle
duration: priv.wiggleDuration
easing.type: Easing.InQuad
}
NumberAnimation {
target: priv
property: "wiggleAngle"
from: maxWiggleAngle
to: -maxWiggleAngle
duration: priv.wiggleDuration
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: priv
property: "wiggleAngle"
from: -maxWiggleAngle
to: maxWiggleAngle
duration: priv.wiggleDuration
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: priv
property: "wiggleAngle"
from: maxWiggleAngle
to: -maxWiggleAngle
duration: priv.wiggleDuration
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: priv
property: "wiggleAngle"
from: -maxWiggleAngle
to: maxWiggleAngle
duration: priv.wiggleDuration
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: priv
property: "wiggleAngle"
from: maxWiggleAngle
to: 0
duration: priv.wiggleDuration
easing.type: Easing.OutQuad
}
}
Item {
id: iconItem
width: root.width
height: parent.itemHeight + units.gu(1)
anchors.centerIn: parent
StyledItem {
styleName: "FocusShape"
anchors.fill: iconShape
activeFocusOnTab: true
StyleHints {
visible: root.highlighted
radius: units.gu(2.55)
}
}
ProportionalShape {
id: iconShape
anchors.centerIn: parent
width: root.itemWidth
aspect: UbuntuShape.DropShadow
source: Image {
id: iconImage
sourceSize.width: iconShape.width
sourceSize.height: iconShape.height
source: root.iconName
cache: false // see lpbug#1543290 why no cache
}
}
UbuntuShape {
id: countEmblem
objectName: "countEmblem"
anchors {
right: parent.right
bottom: parent.bottom
rightMargin: (iconItem.width - root.itemWidth) / 2 - units.dp(2)
margins: units.dp(5)
}
width: Math.min(root.itemWidth, Math.max(units.gu(2), countLabel.implicitWidth + units.gu(1)))
height: units.gu(2)
backgroundColor: theme.palette.normal.positive
visible: root.countVisible
aspect: UbuntuShape.Flat
Label {
id: countLabel
objectName: "countLabel"
text: root.count
anchors.centerIn: parent
width: root.itemWidth - units.gu(1)
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
color: "white"
fontSize: "x-small"
}
}
UbuntuShape {
id: progressOverlay
objectName: "progressOverlay"
anchors.centerIn: parent
width: root.itemWidth * .8
height: units.dp(3)
visible: root.progress > -1
backgroundColor: "white"
borderSource: "none"
Item {
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
}
width: Math.min(100, root.progress) / 100 * parent.width
clip: true
UbuntuShape {
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
}
backgroundColor: theme.palette.normal.activity
borderSource: "none"
width: progressOverlay.width
}
}
}
Column {
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
}
spacing: units.gu(.5)
Repeater {
objectName: "surfacePipRepeater"
model: Math.min(3, root.surfaceCount)
Rectangle {
objectName: "runningHighlight" + index
width: units.gu(0.25)
height: units.gu(.5)
color: root.alerting ? theme.palette.normal.activity : "white"
visible: root.itemRunning
}
}
}
Rectangle {
objectName: "focusedHighlight"
anchors {
right: parent.right
verticalCenter: parent.verticalCenter
}
width: units.gu(0.25)
height: units.gu(.5)
color: "white"
visible: root.itemFocused
}
UbuntuShape {
objectName: "shortcutHint"
anchors.centerIn: parent
width: units.gu(2.5)
height: width
backgroundColor: "#F2111111"
visible: root.shortcutHintShown
aspect: UbuntuShape.Flat
Label {
anchors.centerIn: parent
text: (itemIndex + 1) % 10
color: "white"
font.weight: Font.Light
}
}
}
ShaderEffect {
id: transformEffect
anchors.centerIn: parent
anchors.verticalCenterOffset: root.offset
width: iconItem.width
height: iconItem.height
property real itemOpacity: root.itemOpacity
property real brightness: Math.max(-1, root.brightness)
property real angle: root.angle
rotation: root.inverted ? 180 : 0
property variant source: ShaderEffectSource {
id: shaderEffectSource
sourceItem: iconItem
hideSource: true
}
transform: [
// The rotation about the icon's center/z-axis for the wiggle
// needs to happen here too, because there's no other way to
// align the wiggle with the icon-folding otherwise
Rotation {
axis { x: 0; y: 0; z: 1 }
origin { x: iconItem.width / 2; y: iconItem.height / 2; z: 0 }
angle: priv.wiggleAngle
},
// Rotating 3 times at top/bottom because that increases the perspective.
// This is a hack, but as QML does not support real 3D coordinates
// getting a higher perspective can only be done by a hack. This is the most
// readable/understandable one I could come up with.
Rotation {
axis { x: 1; y: 0; z: 0 }
origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
angle: root.angle * 0.7
},
Rotation {
axis { x: 1; y: 0; z: 0 }
origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
angle: root.angle * 0.7
},
Rotation {
axis { x: 1; y: 0; z: 0 }
origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
angle: root.angle * 0.7
},
// Because rotating it 3 times moves it more to the front/back, i.e. it gets
// bigger/smaller and we need a scale to compensate that again.
Scale {
xScale: 1 - (Math.abs(angle) / 500)
yScale: 1 - (Math.abs(angle) / 500)
origin { x: iconItem.width / 2; y: iconItem.height / 2}
}
]
// Using a fragment shader instead of QML's opacity and BrightnessContrast
// to be able to do both in one step which gives quite some better performance
fragmentShader: "
varying highp vec2 qt_TexCoord0;
uniform sampler2D source;
uniform lowp float brightness;
uniform lowp float itemOpacity;
void main(void)
{
highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
sourceColor.rgb = mix(sourceColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
sourceColor *= itemOpacity;
gl_FragColor = sourceColor;
}"
}
}
|