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
27 property bool countVisible: false
28 property int progress: -1
29 property bool itemRunning: false
30 property bool itemFocused: false
31 property real maxAngle: 0
32 property bool inverted: false
33 property bool alerting: false
34 property bool highlighted: false
35 property bool shortcutHintShown: false
36 property int surfaceCount: 1
38 readonly property int effectiveHeight: Math.cos(angle * Math.PI / 180) * itemHeight
39 readonly property real foldedHeight: Math.cos(maxAngle * Math.PI / 180) * itemHeight
40 readonly property alias wiggling: wiggleAnim.running
42 property int itemWidth
43 property int itemHeight
44 // The angle used for rotating
45 property real angle: 0
46 // This is the offset that keeps the items inside the panel
47 property real offset: 0
48 property real itemOpacity: 1
49 property real brightness: 0
50 property double maxWiggleAngle: 5.0
55 readonly property int wiggleDuration: UbuntuAnimation.SnapDuration
56 property real wiggleAngle: 0
68 property: "wiggleAngle"
71 duration: priv.wiggleDuration
72 easing.type: Easing.InQuad
77 property: "wiggleAngle"
80 duration: priv.wiggleDuration
81 easing.type: Easing.InOutQuad
86 property: "wiggleAngle"
89 duration: priv.wiggleDuration
90 easing.type: Easing.InOutQuad
95 property: "wiggleAngle"
98 duration: priv.wiggleDuration
99 easing.type: Easing.InOutQuad
104 property: "wiggleAngle"
105 from: -maxWiggleAngle
107 duration: priv.wiggleDuration
108 easing.type: Easing.InOutQuad
113 property: "wiggleAngle"
116 duration: priv.wiggleDuration
117 easing.type: Easing.OutQuad
124 height: parent.itemHeight + units.gu(1)
125 anchors.centerIn: parent
128 objectName: "focusRing"
129 anchors.centerIn: iconShape
130 height: width * 15 / 16
131 width: iconShape.width + units.gu(1)
132 source: "graphics/launcher-app-focus-ring.svg"
133 sourceSize.width: width
134 sourceSize.height: height
135 visible: root.highlighted
140 anchors.centerIn: parent
141 width: root.itemWidth
142 aspect: UbuntuShape.DropShadow
145 sourceSize.width: iconShape.width
146 sourceSize.height: iconShape.height
147 source: root.iconName
148 cache: false // see lpbug#1543290 why no cache
154 objectName: "countEmblem"
157 bottom: parent.bottom
158 rightMargin: (iconItem.width - root.itemWidth) / 2 - units.dp(2)
161 width: Math.min(root.itemWidth, Math.max(units.gu(2), countLabel.implicitWidth + units.gu(1)))
163 backgroundColor: theme.palette.normal.positive
164 visible: root.countVisible
165 aspect: UbuntuShape.Flat
169 objectName: "countLabel"
171 anchors.centerIn: parent
172 width: root.itemWidth - units.gu(1)
173 horizontalAlignment: Text.AlignHCenter
174 elide: Text.ElideRight
182 objectName: "progressOverlay"
184 anchors.centerIn: parent
185 width: root.itemWidth * .8
187 visible: root.progress > -1
188 backgroundColor: "white"
195 bottom: parent.bottom
197 width: Math.min(100, root.progress) / 100 * parent.width
204 bottom: parent.bottom
206 backgroundColor: theme.palette.normal.activity
208 width: progressOverlay.width
216 verticalCenter: parent.verticalCenter
218 spacing: units.gu(.5)
220 objectName: "surfacePipRepeater"
221 model: Math.min(3, root.surfaceCount)
223 objectName: "runningHighlight" + index
224 width: units.gu(0.25)
226 color: root.alerting ? theme.palette.normal.activity : "white"
227 visible: root.itemRunning
233 objectName: "focusedHighlight"
236 verticalCenter: parent.verticalCenter
238 width: units.gu(0.25)
241 visible: root.itemFocused
245 objectName: "shortcutHint"
246 anchors.centerIn: parent
249 backgroundColor: "#F2111111"
250 visible: root.shortcutHintShown
251 aspect: UbuntuShape.Flat
253 anchors.centerIn: parent
254 text: (itemIndex + 1) % 10
256 font.weight: Font.Light
263 anchors.centerIn: parent
264 anchors.verticalCenterOffset: root.offset
265 width: iconItem.width
266 height: iconItem.height
267 property real itemOpacity: root.itemOpacity
268 property real brightness: Math.max(-1, root.brightness)
269 property real angle: root.angle
270 rotation: root.inverted ? 180 : 0
272 property variant source: ShaderEffectSource {
273 id: shaderEffectSource
279 // The rotation about the icon's center/z-axis for the wiggle
280 // needs to happen here too, because there's no other way to
281 // align the wiggle with the icon-folding otherwise
283 axis { x: 0; y: 0; z: 1 }
284 origin { x: iconItem.width / 2; y: iconItem.height / 2; z: 0 }
285 angle: priv.wiggleAngle
287 // Rotating 3 times at top/bottom because that increases the perspective.
288 // This is a hack, but as QML does not support real 3D coordinates
289 // getting a higher perspective can only be done by a hack. This is the most
290 // readable/understandable one I could come up with.
292 axis { x: 1; y: 0; z: 0 }
293 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
294 angle: root.angle * 0.7
297 axis { x: 1; y: 0; z: 0 }
298 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
299 angle: root.angle * 0.7
302 axis { x: 1; y: 0; z: 0 }
303 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
304 angle: root.angle * 0.7
306 // Because rotating it 3 times moves it more to the front/back, i.e. it gets
307 // bigger/smaller and we need a scale to compensate that again.
309 xScale: 1 - (Math.abs(angle) / 500)
310 yScale: 1 - (Math.abs(angle) / 500)
311 origin { x: iconItem.width / 2; y: iconItem.height / 2}
315 // Using a fragment shader instead of QML's opacity and BrightnessContrast
316 // to be able to do both in one step which gives quite some better performance
318 varying highp vec2 qt_TexCoord0;
319 uniform sampler2D source;
320 uniform lowp float brightness;
321 uniform lowp float itemOpacity;
324 highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
325 sourceColor.rgb = mix(sourceColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
326 sourceColor *= itemOpacity;
327 gl_FragColor = sourceColor;