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 itemFocused: false
27 property real maxAngle: 0
28 property bool inverted: false
29 property bool clipCorner: 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
45 width: parent.itemWidth + units.gu(1)
46 height: parent.itemHeight + units.gu(1)
47 anchors.centerIn: parent
52 anchors.margins: units.gu(1)
58 sourceSize.width: iconShape.width
59 sourceSize.height: iconShape.height
60 fillMode: Image.PreserveAspectCrop
67 anchors.centerIn: iconItem
68 source: "graphics/icon-top-highlight.png"
69 width: root.itemWidth - units.gu(1)
70 height: root.itemHeight - units.gu(1)
74 objectName: "countEmblem"
80 width: Math.min(root.itemWidth, Math.max(units.gu(2), countLabel.implicitWidth + units.gu(1)))
82 color: UbuntuColors.orange
83 visible: root.count > 0
89 anchors.centerIn: parent
90 // FIXME: verticalCenter seems to be off wee bit and QML doesn't have a centerLine
91 // property for Text: https://bugreports.qt-project.org/browse/QTBUG-40479
92 anchors.verticalCenterOffset: -units.dp(.5)
93 width: root.itemWidth - units.gu(1)
94 horizontalAlignment: Text.AlignHCenter
95 elide: Text.ElideRight
103 objectName: "progressOverlay"
106 right: iconItem.right
107 bottom: iconItem.bottom
108 leftMargin: units.gu(1)
109 rightMargin: units.gu(1)
110 bottomMargin: units.gu(1)
112 height: units.gu(1.5)
113 visible: root.progress > -1
114 source: "graphics/progressbar-trough.sci"
116 // For fill calculation we need to remove the 2 units of border defined in .sci file
117 property int adjustedWidth: width - units.gu(2)
123 bottom: parent.bottom
125 width: Math.min(100, root.progress) / 100 * parent.adjustedWidth + units.gu(1)
132 bottom: parent.bottom
134 width: progressOverlay.width
135 source: "graphics/progressbar-fill.sci"
140 objectName: "focusedHighlight"
143 verticalCenter: parent.verticalCenter
145 visible: root.itemFocused
146 source: "graphics/focused_app_arrow.png"
152 anchors.centerIn: parent
153 width: iconItem.width
154 height: iconItem.height
158 topMargin: -units.gu(2)
159 leftMargin: -units.gu(2)
160 rightMargin: -units.gu(2)
161 bottomMargin: units.gu(1.2)
164 rotation: root.rotation + 45
170 anchors.centerIn: parent
171 anchors.verticalCenterOffset: root.offset
172 width: iconItem.width
173 height: iconItem.height
174 property real itemOpacity: root.itemOpacity
175 property real brightness: Math.max(-1, root.brightness)
176 property real angle: root.angle
177 property bool clipCorner: root.clipCorner
178 rotation: root.inverted ? 180 : 0
180 property variant source: ShaderEffectSource {
181 id: shaderEffectSource
186 property var mask: ShaderEffectSource {
192 // Rotating 3 times at top/bottom because that increases the perspective.
193 // This is a hack, but as QML does not support real 3D coordinates
194 // getting a higher perspective can only be done by a hack. This is the most
195 // readable/understandable one I could come up with.
197 axis { x: 1; y: 0; z: 0 }
198 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
199 angle: root.angle * 0.7
202 axis { x: 1; y: 0; z: 0 }
203 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
204 angle: root.angle * 0.7
207 axis { x: 1; y: 0; z: 0 }
208 origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
209 angle: root.angle * 0.7
211 // Because rotating it 3 times moves it more to the front/back, i.e. it gets
212 // bigger/smaller and we need a scale to compensate that again.
214 xScale: 1 - (Math.abs(angle) / 500)
215 yScale: 1 - (Math.abs(angle) / 500)
216 origin { x: iconItem.width / 2; y: iconItem.height / 2}
220 // Using a fragment shader instead of QML's opacity and BrightnessContrast
221 // to be able to do both in one step which gives quite some better performance
223 varying highp vec2 qt_TexCoord0;
224 uniform sampler2D source;
225 uniform sampler2D mask;
226 uniform lowp float brightness;
227 uniform lowp float itemOpacity;
228 uniform bool clipCorner;
231 highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
232 highp vec4 maskColor = texture2D(mask, qt_TexCoord0);
233 sourceColor.rgb = mix(sourceColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
234 sourceColor *= itemOpacity;
236 sourceColor *= maskColor.a;
238 gl_FragColor = sourceColor;