2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.3
23 property int itemIndex: 0
24 property string iconName
26 property bool countVisible: false
27 property int progress: -1
28 property bool itemRunning: false
29 property bool itemFocused: false
30 property real maxAngle: 0
31 property bool inverted: false
32 property bool alerting: false
33 property bool highlighted: false
34 property bool shortcutHintShown: false
36 readonly property int effectiveHeight: Math.cos(angle * Math.PI / 180) * itemHeight
37 readonly property real foldedHeight: Math.cos(maxAngle * Math.PI / 180) * itemHeight
38 readonly property alias wiggling: wiggleAnim.running
40 property int itemWidth
41 property int itemHeight
42 // The angle used for rotating
43 property real angle: 0
44 // This is the offset that keeps the items inside the panel
45 property real offset: 0
46 property real itemOpacity: 1
47 property real brightness: 0
48 property double maxWiggleAngle: 5.0
53 readonly property int wiggleDuration: UbuntuAnimation.SnapDuration
54 property real wiggleAngle: 0
66 property: "wiggleAngle"
69 duration: priv.wiggleDuration
70 easing.type: Easing.InQuad
75 property: "wiggleAngle"
78 duration: priv.wiggleDuration
79 easing.type: Easing.InOutQuad
84 property: "wiggleAngle"
87 duration: priv.wiggleDuration
88 easing.type: Easing.InOutQuad
93 property: "wiggleAngle"
96 duration: priv.wiggleDuration
97 easing.type: Easing.InOutQuad
102 property: "wiggleAngle"
103 from: -maxWiggleAngle
105 duration: priv.wiggleDuration
106 easing.type: Easing.InOutQuad
111 property: "wiggleAngle"
114 duration: priv.wiggleDuration
115 easing.type: Easing.OutQuad
118 UbuntuNumberAnimation {
128 height: parent.itemHeight + units.gu(1)
129 anchors.centerIn: parent
132 objectName: "focusRing"
133 anchors.centerIn: iconShape
134 height: width * 15 / 16
135 width: iconShape.width + units.gu(1)
136 source: "graphics/launcher-app-focus-ring.svg"
137 sourceSize.width: width
138 sourceSize.height: height
139 visible: root.highlighted
144 anchors.centerIn: parent
145 width: root.itemWidth
146 aspect: UbuntuShape.DropShadow
149 sourceSize.width: iconShape.width
150 sourceSize.height: iconShape.height
151 source: root.iconName
152 cache: false // see lpbug#1543290 why no cache
158 objectName: "countEmblem"
161 bottom: parent.bottom
162 rightMargin: (iconItem.width - root.itemWidth) / 2 - units.dp(2)
165 width: Math.min(root.itemWidth, Math.max(units.gu(2), countLabel.implicitWidth + units.gu(1)))
167 backgroundColor: theme.palette.normal.positive
168 visible: root.countVisible
169 aspect: UbuntuShape.Flat
173 objectName: "countLabel"
175 anchors.centerIn: parent
176 width: root.itemWidth - units.gu(1)
177 horizontalAlignment: Text.AlignHCenter
178 elide: Text.ElideRight
186 objectName: "progressOverlay"
188 anchors.centerIn: parent
189 width: root.itemWidth * .8
191 visible: root.progress > -1
192 backgroundColor: "white"
199 bottom: parent.bottom
201 width: Math.min(100, root.progress) / 100 * parent.width
208 bottom: parent.bottom
210 backgroundColor: theme.palette.normal.activity
212 width: progressOverlay.width
220 verticalCenter: parent.verticalCenter
222 spacing: units.gu(.5)
224 model: 1 // TODO: This should be "Math.min(3, app.surfaceCount)" once we have multiple surfaces
226 objectName: "runningHighlight" + index
227 width: units.gu(0.25)
230 visible: root.itemRunning
236 objectName: "focusedHighlight"
239 verticalCenter: parent.verticalCenter
241 width: units.gu(0.25)
244 visible: root.itemFocused
248 objectName: "shortcutHint"
249 anchors.centerIn: parent
252 backgroundColor: "#F2111111"
253 visible: root.shortcutHintShown
254 aspect: UbuntuShape.Flat
256 anchors.centerIn: parent
257 text: (itemIndex + 1) % 10
259 font.weight: Font.Light
266 anchors.centerIn: parent
267 anchors.verticalCenterOffset: root.offset
268 width: iconItem.width
269 height: iconItem.height
270 property real itemOpacity: root.itemOpacity
271 property real brightness: Math.max(-1, root.brightness)
272 property real angle: root.angle
273 rotation: root.inverted ? 180 : 0
275 property variant source: ShaderEffectSource {
276 id: shaderEffectSource
282 // The rotation about the icon's center/z-axis for the wiggle
283 // needs to happen here too, because there's no other way to
284 // align the wiggle with the icon-folding otherwise
286 axis { x: 0; y: 0; z: 1 }
287 origin { x: iconItem.width / 2; y: iconItem.height / 2; z: 0 }
288 angle: priv.wiggleAngle
290 // Rotating 3 times at top/bottom because that increases the perspective.
291 // This is a hack, but as QML does not support real 3D coordinates
292 // getting a higher perspective can only be done by a hack. This is the most
293 // readable/understandable one I could come up with.
295 axis { x: 1; y: 0; z: 0 }
296 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
297 angle: root.angle * 0.7
300 axis { x: 1; y: 0; z: 0 }
301 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
302 angle: root.angle * 0.7
305 axis { x: 1; y: 0; z: 0 }
306 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
307 angle: root.angle * 0.7
309 // Because rotating it 3 times moves it more to the front/back, i.e. it gets
310 // bigger/smaller and we need a scale to compensate that again.
312 xScale: 1 - (Math.abs(angle) / 500)
313 yScale: 1 - (Math.abs(angle) / 500)
314 origin { x: iconItem.width / 2; y: iconItem.height / 2}
318 // Using a fragment shader instead of QML's opacity and BrightnessContrast
319 // to be able to do both in one step which gives quite some better performance
321 varying highp vec2 qt_TexCoord0;
322 uniform sampler2D source;
323 uniform lowp float brightness;
324 uniform lowp float itemOpacity;
327 highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
328 sourceColor.rgb = mix(sourceColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
329 sourceColor *= itemOpacity;
330 gl_FragColor = sourceColor;