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 styleName: "FocusShape"
129 anchors.fill: iconShape
130 activeFocusOnTab: true
132 visible: root.highlighted
133 radius: units.gu(2.55)
139 anchors.centerIn: parent
140 width: root.itemWidth
141 aspect: UbuntuShape.DropShadow
144 sourceSize.width: iconShape.width
145 sourceSize.height: iconShape.height
146 source: root.iconName
147 cache: false // see lpbug#1543290 why no cache
153 objectName: "countEmblem"
156 bottom: parent.bottom
157 rightMargin: (iconItem.width - root.itemWidth) / 2 - units.dp(2)
160 width: Math.min(root.itemWidth, Math.max(units.gu(2), countLabel.implicitWidth + units.gu(1)))
162 backgroundColor: theme.palette.normal.positive
163 visible: root.countVisible
164 aspect: UbuntuShape.Flat
168 objectName: "countLabel"
170 anchors.centerIn: parent
171 width: root.itemWidth - units.gu(1)
172 horizontalAlignment: Text.AlignHCenter
173 elide: Text.ElideRight
181 objectName: "progressOverlay"
183 anchors.centerIn: parent
184 width: root.itemWidth * .8
186 visible: root.progress > -1
187 backgroundColor: "white"
194 bottom: parent.bottom
196 width: Math.min(100, root.progress) / 100 * parent.width
203 bottom: parent.bottom
205 backgroundColor: theme.palette.normal.activity
207 width: progressOverlay.width
215 verticalCenter: parent.verticalCenter
217 spacing: units.gu(.5)
219 objectName: "surfacePipRepeater"
220 model: Math.min(3, root.surfaceCount)
222 objectName: "runningHighlight" + index
223 width: units.gu(0.25)
225 color: root.alerting ? theme.palette.normal.activity : "white"
226 visible: root.itemRunning
232 objectName: "focusedHighlight"
235 verticalCenter: parent.verticalCenter
237 width: units.gu(0.25)
240 visible: root.itemFocused
244 objectName: "shortcutHint"
245 anchors.centerIn: parent
248 backgroundColor: "#F2111111"
249 visible: root.shortcutHintShown
250 aspect: UbuntuShape.Flat
252 anchors.centerIn: parent
253 text: (itemIndex + 1) % 10
255 font.weight: Font.Light
262 anchors.centerIn: parent
263 anchors.verticalCenterOffset: root.offset
264 width: iconItem.width
265 height: iconItem.height
266 property real itemOpacity: root.itemOpacity
267 property real brightness: Math.max(-1, root.brightness)
268 property real angle: root.angle
269 rotation: root.inverted ? 180 : 0
271 property variant source: ShaderEffectSource {
272 id: shaderEffectSource
278 // The rotation about the icon's center/z-axis for the wiggle
279 // needs to happen here too, because there's no other way to
280 // align the wiggle with the icon-folding otherwise
282 axis { x: 0; y: 0; z: 1 }
283 origin { x: iconItem.width / 2; y: iconItem.height / 2; z: 0 }
284 angle: priv.wiggleAngle
286 // Rotating 3 times at top/bottom because that increases the perspective.
287 // This is a hack, but as QML does not support real 3D coordinates
288 // getting a higher perspective can only be done by a hack. This is the most
289 // readable/understandable one I could come up with.
291 axis { x: 1; y: 0; z: 0 }
292 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
293 angle: root.angle * 0.7
296 axis { x: 1; y: 0; z: 0 }
297 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
298 angle: root.angle * 0.7
301 axis { x: 1; y: 0; z: 0 }
302 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
303 angle: root.angle * 0.7
305 // Because rotating it 3 times moves it more to the front/back, i.e. it gets
306 // bigger/smaller and we need a scale to compensate that again.
308 xScale: 1 - (Math.abs(angle) / 500)
309 yScale: 1 - (Math.abs(angle) / 500)
310 origin { x: iconItem.width / 2; y: iconItem.height / 2}
314 // Using a fragment shader instead of QML's opacity and BrightnessContrast
315 // to be able to do both in one step which gives quite some better performance
317 varying highp vec2 qt_TexCoord0;
318 uniform sampler2D source;
319 uniform lowp float brightness;
320 uniform lowp float itemOpacity;
323 highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
324 sourceColor.rgb = mix(sourceColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
325 sourceColor *= itemOpacity;
326 gl_FragColor = sourceColor;