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/>.
18import Lomiri.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
41 property int itemWidth
42 property int itemHeight
43 // The angle used for rotating
44 property real angle: 0
45 // This is the offset that keeps the items inside the panel
46 property real offset: 0
47 property real itemOpacity: 1
48 property real brightness: 0
49 property double maxWiggleAngle: 5.0
54 readonly property int wiggleDuration: LomiriAnimation.SnapDuration
55 property real wiggleAngle: 0
58 readonly property var wiggleAnim: SequentialAnimation {
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
122 height: parent.itemHeight + units.gu(1)
123 anchors.centerIn: parent
126 styleName: "FocusShape"
127 anchors.fill: iconShape
128 activeFocusOnTab: true
130 visible: root.highlighted
131 radius: units.gu(2.55)
137 anchors.centerIn: parent
138 width: root.itemWidth
139 aspect: LomiriShape.DropShadow
142 sourceSize.width: iconShape.width
143 sourceSize.height: iconShape.height
144 source: root.iconName
145 cache: false // see lpbug#1543290 why no cache
151 objectName: "countEmblem"
154 bottom: parent.bottom
155 rightMargin: (iconItem.width - root.itemWidth) / 2 - units.dp(2)
158 width: Math.min(root.itemWidth, Math.max(units.gu(2), countLabel.implicitWidth + units.gu(1)))
160 backgroundColor: theme.palette.normal.positive
161 visible: root.countVisible
162 aspect: LomiriShape.Flat
166 objectName: "countLabel"
168 anchors.centerIn: parent
169 width: root.itemWidth - units.gu(1)
170 horizontalAlignment: Text.AlignHCenter
171 elide: Text.ElideRight
179 objectName: "progressOverlay"
181 anchors.centerIn: parent
182 width: root.itemWidth * .8
184 visible: root.progress > -1
185 backgroundColor: "white"
192 bottom: parent.bottom
194 width: Math.min(100, root.progress) / 100 * parent.width
201 bottom: parent.bottom
203 backgroundColor: theme.palette.normal.activity
205 width: progressOverlay.width
213 verticalCenter: parent.verticalCenter
215 spacing: units.gu(.5)
217 objectName: "surfacePipRepeater"
218 model: Math.min(3, root.surfaceCount)
220 objectName: "runningHighlight" + index
221 width: units.gu(0.25)
223 color: root.alerting ? theme.palette.normal.activity : "white"
224 visible: root.itemRunning
230 objectName: "focusedHighlight"
233 verticalCenter: parent.verticalCenter
235 width: units.gu(0.25)
238 visible: root.itemFocused
242 objectName: "shortcutHint"
243 anchors.centerIn: parent
246 backgroundColor: "#F2111111"
247 visible: root.shortcutHintShown
248 aspect: LomiriShape.Flat
250 anchors.centerIn: parent
251 text: (itemIndex + 1) % 10
253 font.weight: Font.Light
260 anchors.centerIn: parent
261 anchors.verticalCenterOffset: root.offset
262 width: iconItem.width
263 height: iconItem.height
264 property real itemOpacity: root.itemOpacity
265 property real brightness: Math.max(-1, root.brightness)
266 property real angle: root.angle
267 rotation: root.inverted ? 180 : 0
269 property variant source: ShaderEffectSource {
270 id: shaderEffectSource
276 // The rotation about the icon's center/z-axis for the wiggle
277 // needs to happen here too, because there's no other way to
278 // align the wiggle with the icon-folding otherwise
280 axis { x: 0; y: 0; z: 1 }
281 origin { x: iconItem.width / 2; y: iconItem.height / 2; z: 0 }
282 angle: priv.wiggleAngle
284 // Rotating 3 times at top/bottom because that increases the perspective.
285 // This is a hack, but as QML does not support real 3D coordinates
286 // getting a higher perspective can only be done by a hack. This is the most
287 // readable/understandable one I could come up with.
289 axis { x: 1; y: 0; z: 0 }
290 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
291 angle: root.angle * 0.7
294 axis { x: 1; y: 0; z: 0 }
295 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
296 angle: root.angle * 0.7
299 axis { x: 1; y: 0; z: 0 }
300 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
301 angle: root.angle * 0.7
303 // Because rotating it 3 times moves it more to the front/back, i.e. it gets
304 // bigger/smaller and we need a scale to compensate that again.
306 xScale: 1 - (Math.abs(angle) / 500)
307 yScale: 1 - (Math.abs(angle) / 500)
308 origin { x: iconItem.width / 2; y: iconItem.height / 2}
312 // Using a fragment shader instead of QML's opacity and BrightnessContrast
313 // to be able to do both in one step which gives quite some better performance
315 varying highp vec2 qt_TexCoord0;
316 uniform sampler2D source;
317 uniform lowp float brightness;
318 uniform lowp float itemOpacity;
321 highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
322 sourceColor.rgb = mix(sourceColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
323 sourceColor *= itemOpacity;
324 gl_FragColor = sourceColor;