on f404864 help sign in
unity8/Launcher/LauncherDelegate.qml
137 lines 5.1 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17import QtQuick 2.0
18import Ubuntu.Components 0.1
20Item {
21 id: root
23 property string iconName
25 property bool highlighted: false
26 property real maxAngle: 0
27 property bool inverted: false
29 readonly property int effectiveHeight: Math.cos(angle * Math.PI / 180) * itemHeight
30 readonly property real foldedHeight: Math.cos(maxAngle * Math.PI / 180) * itemHeight
32 property int itemWidth
33 property int itemHeight
34 // The angle used for rotating
35 property real angle: 0
36 // This is the offset that keeps the items inside the panel
37 property real offset: 0
38 property real itemOpacity: 1
39 property real brightness: 0
41 Item {
42 id: iconItem
43 width: parent.itemWidth
44 height: parent.itemHeight
45 anchors.centerIn: parent
47 UbuntuShape {
48 id: iconShape
49 anchors.fill: parent
50 anchors.margins: units.gu(0.5)
51 radius: "medium"
53 image: Image {
54 id: iconImage
55 sourceSize.width: iconShape.width
56 sourceSize.height: iconShape.height
57 source: "../graphics/applicationIcons/" + iconName + ".png"
58 property string iconName: root.iconName
59 onIconNameChanged: shaderEffectSource.scheduleUpdate();
60 }
61 }
63 BorderImage {
64 id: overlayHighlight
65 anchors.centerIn: iconItem
66 rotation: inverted ? 180 : 0
67 source: isSelected ? "graphics/selected.sci" : "graphics/non-selected.sci"
68 width: root.itemWidth + units.gu(0.5)
69 height: root.itemHeight + units.gu(0.5)
70 property bool isSelected: root.highlighted
71 onIsSelectedChanged: shaderEffectSource.scheduleUpdate();
72 }
73 }
75 ShaderEffect {
76 id: transformEffect
77 anchors.centerIn: parent
78 anchors.verticalCenterOffset: root.offset
79 width: parent.itemWidth
80 height: parent.itemHeight
81 property real itemOpacity: root.itemOpacity
82 property real brightness: Math.max(-1, root.brightness)
83 property real angle: root.angle
84 rotation: root.inverted ? 180 : 0
86 property variant source: ShaderEffectSource {
87 id: shaderEffectSource
88 sourceItem: iconItem
89 hideSource: true
90 live: false
91 }
93 transform: [
94 // Rotating 3 times at top/bottom because that increases the perspective.
95 // This is a hack, but as QML does not support real 3D coordinates
96 // getting a higher perspective can only be done by a hack. This is the most
97 // readable/understandable one I could come up with.
98 Rotation {
99 axis { x: 1; y: 0; z: 0 }
100 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
101 angle: root.angle * 0.7
102 },
103 Rotation {
104 axis { x: 1; y: 0; z: 0 }
105 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
106 angle: root.angle * 0.7
107 },
108 Rotation {
109 axis { x: 1; y: 0; z: 0 }
110 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
111 angle: root.angle * 0.7
112 },
113 // Because rotating it 3 times moves it more to the front/back, i.e. it gets
114 // bigger/smaller and we need a scale to compensate that again.
115 Scale {
116 xScale: 1 - (Math.abs(angle) / 500)
117 yScale: 1 - (Math.abs(angle) / 500)
118 origin { x: iconItem.width / 2; y: iconItem.height / 2}
119 }
120 ]
122 // Using a fragment shader instead of QML's opacity and BrightnessContrast
123 // to be able to do both in one step which gives quite some better performance
124 fragmentShader: "
125 varying highp vec2 qt_TexCoord0;
126 uniform sampler2D source;
127 uniform lowp float brightness;
128 uniform lowp float itemOpacity;
129 void main(void)
130 {
131 highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
132 sourceColor.rgb = mix(sourceColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
133 sourceColor *= itemOpacity;
134 gl_FragColor = sourceColor;
135 }"
136 }