Debian Codegraph @

src/imports/Components/2.0/Icon.qml

raw
1 /*
2 * Copyright (C) 2015 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 *
16 * Authors: Zsombor Egri <[email protected]>
17 * Loic Molinari <[email protected]>
18 */
19
20 import QtQuick 2.4
21
22 /*!
23 \qmltype Icon
24 \inqmlmodule Lomiri.Components
25 \inherits Item
26 \ingroup lomiri
27 \brief The Icon component displays an icon from the icon theme.
28
29 The icon theme contains a set of standard icons referred to by their name.
30 Using icons whenever possible enhances consistency across applications.
31 Each icon has a name and can have different visual representations depending
32 on the size requested.
33
34 Icons can also be colorized. Setting the \l color property will make all pixels
35 with the \l keyColor (by default #808080) colored.
36
37 Example:
38 \qml
39 Icon {
40 width: 64
41 height: 64
42 name: "toolkit_input-search"
43 }
44 \endqml
45
46 Example of colorization:
47 \qml
48 Icon {
49 width: 64
50 height: 64
51 name: "toolkit_input-search"
52 color: LomiriColors.warmGrey
53 }
54 \endqml
55
56 Icon themes are created following the
57 \l{http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html}{Freedesktop Icon Theme Specification}.
58 */
59
60 Item {
61 id: icon
62
63 /*!
64 The name of the icon to display.
65 \qmlproperty string Icon::name
66
67 If both name and source are set, name will be ignored.
68
69 \note The complete list of icons available in Lomiri is not published yet.
70 For now please refer to the folders where the icon themes are installed:
71 \list
72 \li Lomiri Touch: \l file:/usr/share/icons/suru
73 \li Lomiri Desktop: \l file:/usr/share/icons/lomiri-mono-dark
74 \endlist
75 These 2 separate icon themes will be merged soon.
76 */
77 property string name
78
79 /*!
80 The color that all pixels that originally are of color \l keyColor should take.
81 \qmlproperty color Icon::color
82 */
83
84 property alias color: colorizedImage.keyColorOut
85
86 /*!
87 The color of the pixels that should be colorized.
88 By default it is set to #808080.
89 \qmlproperty color Icon::keyColor
90 */
91 property alias keyColor: colorizedImage.keyColorIn
92
93 /*!
94 The source url of the icon to display. It has precedence over name.
95
96 If both name and source are set, name will be ignored.
97
98 \since Lomiri.Components 1.1
99 \qmlproperty url Icon::source
100 */
101
102 property url source: ""
103
104 /*!
105 \qmlproperty bool Icon::asynchronous
106 The property drives the image loading of the icon. Defaults to false.
107 */
108 property alias asynchronous: image.asynchronous
109
110 /*!
111 \qmlproperty enumeration Icon::status
112 \readonly
113
114 Holds the loading status of the icon.
115
116 The value is one of:
117 \list
118 \li Image.Null
119 \li Image.Ready
120 \li Image.Loading
121 \li Image.Error
122 \endlist
123 */
124 property alias status: image.status
125
126 implicitWidth: image.implicitWidth
127 implicitHeight: image.implicitHeight
128
129 Component.onCompleted: image.completed = true
130
131 Image {
132 id: image
133 objectName: "image"
134 anchors.fill: parent
135 fillMode: Image.PreserveAspectFit
136
137 sourceSize {
138 width: icon.width
139 height: icon.height
140 }
141
142 property bool completed: false
143 source: icon.source.toString() !== "" ? icon.source : (completed && icon.name ? "image://theme/%1".arg(icon.name) : "")
144
145 cache: true
146 visible: !colorizedImage.visible
147 asynchronous: false
148 }
149
150 ShaderEffect {
151 id: colorizedImage
152 objectName: "shader"
153
154 anchors.fill: parent
155
156 // Whether or not a color has been set.
157 visible: image.status === Image.Ready && keyColorOut !== Qt.rgba(0.0, 0.0, 0.0, 0.0)
158
159 property Image source: image
160 property color keyColorOut: Qt.rgba(0.0, 0.0, 0.0, 0.0)
161 property color keyColorIn: "#808080"
162 property real threshold: 0.1
163
164 fragmentShader: "qrc:/2.0/shaders/colorizeimage.frag.qsb"
165 }
166 }