2
* Copyright 2014 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/>.
23
The source of the icon to display.
24
\qmlproperty url source
29
The color that all pixels that originally are of color \l keyColor should take.
30
\qmlproperty color color
32
property alias color: colorizedImage.keyColorOut
35
The color of the pixels that should be colorized.
36
By default it is set to #808080.
37
\qmlproperty color keyColor
39
property alias keyColor: colorizedImage.keyColorIn
41
// FIXME: should only be "status", but overriding in settings app doesn't work.
42
property var sets: ["status","apps"]
44
implicitWidth: image.width
49
anchors { top: parent.top; bottom: parent.bottom }
50
sourceSize.height: height
52
visible: !colorizedImage.active
54
property string iconPath: "/usr/share/icons/suru/%1/scalable/%2.svg"
56
if (String(root.source).match(/^image:\/\/theme/)) {
57
return String(root.source).replace("image://theme/", "").split(",");
60
property int fallback: 0
61
property int setFallback: 0
63
Component.onCompleted: updateSource()
64
onStatusChanged: if (status == Image.Error) bump();
65
onIconsChanged: reset()
69
onSetsChanged: image.reset()
80
if (icons === null) return;
81
if (fallback < icons.length - 1) fallback += 1;
82
else if (setFallback < root.sets.length - 1) {
86
console.warn("Could not load StatusIcon with source \"%1\" and sets %2.".arg(root.source).arg(root.sets));
93
function updateSource() {
97
source = (root.sets && root.sets.length > setFallback) && (icons && icons.length > fallback) ?
98
iconPath.arg(root.sets[setFallback]).arg(icons[fallback]) : "";
107
visible: active && image.status == Image.Ready
109
// Whether or not a color has been set.
110
property bool active: keyColorOut != Qt.rgba(0.0, 0.0, 0.0, 0.0)
112
property Image source: visible ? image : null
113
property color keyColorOut: Qt.rgba(0.0, 0.0, 0.0, 0.0)
114
property color keyColorIn: "#808080"
115
property real threshold: 0.1
118
varying highp vec2 qt_TexCoord0;
119
uniform sampler2D source;
120
uniform highp vec4 keyColorOut;
121
uniform highp vec4 keyColorIn;
122
uniform lowp float threshold;
123
uniform lowp float qt_Opacity;
125
lowp vec4 sourceColor = texture2D(source, qt_TexCoord0);
126
gl_FragColor = mix(vec4(keyColorOut.rgb, 1.0) * sourceColor.a, sourceColor, step(threshold, distance(sourceColor.rgb / sourceColor.a, keyColorIn.rgb))) * qt_Opacity;