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 0.1
23
property string iconName
24
property int count: -1
25
property int progress: -1
26
property bool highlighted: false
27
property bool itemFocused: false
28
property real maxAngle: 0
29
property bool inverted: false
31
readonly property int effectiveHeight: Math.cos(angle * Math.PI / 180) * itemHeight
32
readonly property real foldedHeight: Math.cos(maxAngle * Math.PI / 180) * itemHeight
34
property int itemWidth
35
property int itemHeight
36
// The angle used for rotating
37
property real angle: 0
38
// This is the offset that keeps the items inside the panel
39
property real offset: 0
40
property real itemOpacity: 1
41
property real brightness: 0
43
onIconNameChanged: shaderEffectSource.scheduleUpdate();
44
onCountChanged: shaderEffectSource.scheduleUpdate();
45
onProgressChanged: shaderEffectSource.scheduleUpdate();
46
onHighlightedChanged: shaderEffectSource.scheduleUpdate();
47
onItemFocusedChanged: shaderEffectSource.scheduleUpdate();
51
width: parent.itemWidth + units.gu(1)
52
height: parent.itemHeight + units.gu(1)
53
anchors.centerIn: parent
58
anchors.margins: units.gu(1)
64
sourceSize.width: iconShape.width
65
sourceSize.height: iconShape.height
72
anchors.centerIn: iconItem
73
rotation: inverted ? 180 : 0
74
source: root.highlighted ? "graphics/selected.sci" : "graphics/non-selected.sci"
75
width: root.itemWidth + units.gu(0.5)
76
height: root.itemHeight + units.gu(0.5)
80
objectName: "countEmblem"
86
width: Math.min(root.itemWidth, Math.max(units.gu(3), countLabel.implicitWidth + units.gu(2.5)))
88
source: "graphics/notification.sci"
89
visible: root.count > 0
94
anchors.centerIn: parent
95
width: root.itemWidth - units.gu(1)
96
horizontalAlignment: Text.AlignHCenter
97
elide: Text.ElideRight
106
objectName: "progressOverlay"
109
right: iconItem.right
110
bottom: iconItem.bottom
111
leftMargin: units.gu(1)
112
rightMargin: units.gu(1)
113
bottomMargin: units.gu(1)
115
height: units.gu(1.5)
116
visible: root.progress > -1
117
source: "graphics/progressbar-trough.sci"
119
// For fill calculation we need to remove the 2 units of border defined in .sci file
120
property int adjustedWidth: width - units.gu(2)
126
bottom: parent.bottom
128
width: Math.min(100, root.progress) / 100 * parent.adjustedWidth + units.gu(1)
135
bottom: parent.bottom
137
width: progressOverlay.width
138
source: "graphics/progressbar-fill.sci"
143
objectName: "focusedHighlight"
146
verticalCenter: parent.verticalCenter
148
visible: root.itemFocused
149
source: "graphics/focused_app_arrow.png"
155
anchors.centerIn: parent
156
anchors.verticalCenterOffset: root.offset
157
width: iconItem.width
158
height: iconItem.height
159
property real itemOpacity: root.itemOpacity
160
property real brightness: Math.max(-1, root.brightness)
161
property real angle: root.angle
162
rotation: root.inverted ? 180 : 0
164
property variant source: ShaderEffectSource {
165
id: shaderEffectSource
172
// Rotating 3 times at top/bottom because that increases the perspective.
173
// This is a hack, but as QML does not support real 3D coordinates
174
// getting a higher perspective can only be done by a hack. This is the most
175
// readable/understandable one I could come up with.
177
axis { x: 1; y: 0; z: 0 }
178
origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
179
angle: root.angle * 0.7
182
axis { x: 1; y: 0; z: 0 }
183
origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
184
angle: root.angle * 0.7
187
axis { x: 1; y: 0; z: 0 }
188
origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
189
angle: root.angle * 0.7
191
// Because rotating it 3 times moves it more to the front/back, i.e. it gets
192
// bigger/smaller and we need a scale to compensate that again.
194
xScale: 1 - (Math.abs(angle) / 500)
195
yScale: 1 - (Math.abs(angle) / 500)
196
origin { x: iconItem.width / 2; y: iconItem.height / 2}
200
// Using a fragment shader instead of QML's opacity and BrightnessContrast
201
// to be able to do both in one step which gives quite some better performance
203
varying highp vec2 qt_TexCoord0;
204
uniform sampler2D source;
205
uniform lowp float brightness;
206
uniform lowp float itemOpacity;
209
highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
210
sourceColor.rgb = mix(sourceColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
211
sourceColor *= itemOpacity;
212
gl_FragColor = sourceColor;