KIconThemes

kiconeffect.h
1/*
2
3 This file is part of the KDE project, module kdecore.
4 SPDX-FileCopyrightText: 2000 Geert Jansen <jansen@kde.org>
5 SPDX-FileCopyrightText: 2007 Daniel M. Duley <daniel.duley@verizon.net>
6
7 with minor additions and based on ideas from
8 SPDX-FileContributor: Torsten Rahn <torsten@kde.org>
9
10 SPDX-License-Identifier: LGPL-2.0-only
11*/
12
13#ifndef KICONEFFECT_H
14#define KICONEFFECT_H
15
16#include <kiconthemes_export.h>
17
18#include <QColor>
19#include <QImage>
20#include <QPixmap>
21
22#include <memory>
23
24class KIconEffectPrivate;
25
26/**
27 * @class KIconEffect kiconeffect.h KIconEffect
28 *
29 * Applies effects to icons.
30 *
31 * This class applies effects to icons depending on their state and
32 * group. For example, it can be used to make all disabled icons
33 * in a toolbar gray.
34 *
35 * \image html kiconeffect-apply.png "Various Effects applied to an image"
36 *
37 * @see QIcon::fromTheme
38 */
39class KICONTHEMES_EXPORT KIconEffect
40{
41public:
42#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
43 /**
44 * Create a new KIconEffect.
45 * You will most likely never have to use this to create a new KIconEffect
46 * yourself, as you can use the KIconEffect provided by the global KIconLoader
47 * (which itself is accessible by KIconLoader::global()) through its
48 * iconEffect() function.
49 *
50 * @deprecated since 6.5, use the static API
51 *
52 */
53 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
55#endif
57
58 KIconEffect(const KIconEffect &) = delete;
59 KIconEffect &operator=(const KIconEffect &) = delete;
60
61#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
62 /**
63 * This is the enumeration of all possible icon effects.
64 * Note that 'LastEffect' is no valid icon effect but only
65 * used internally to check for invalid icon effects.
66 *
67 * @li NoEffect: Do not apply any icon effect
68 * @li ToGray: Tints the icon gray
69 * @li Colorize: Tints the icon with a specific color
70 * @li ToGamma: Change the gamma value of the icon
71 * @li DeSaturate: Reduce the saturation of the icon
72 * @li ToMonochrome: Produces a monochrome icon
73 *
74 * @deprecated since 6.5, use the static API
75 */
76 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
77 enum Effects {
78 NoEffect,
79 ToGray,
80 Colorize,
81 ToGamma,
82 DeSaturate,
83 ToMonochrome,
84 LastEffect,
85 };
86#endif
87
88#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
89 /**
90 * Rereads configuration.
91 *
92 * @deprecated since 6.5, use the static API
93 */
94 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
95 void init();
96#endif
97
98#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
99 /**
100 * Tests whether an effect has been configured for the given icon group.
101 * @param group the group to check, see KIconLoader::Group
102 * @param state the state to check, see KIconLoader::States
103 * @returns true if an effect is configured for the given @p group
104 * in @p state, otherwise false.
105 * @see KIconLoader::Group
106 * KIconLoader::States
107 *
108 * @deprecated since 6.5, use the static API
109 */
110 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
111 bool hasEffect(int group, int state) const;
112#endif
113
114#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
115 /**
116 * Returns a fingerprint for the effect by encoding
117 * the given @p group and @p state into a QString. This
118 * is useful for caching.
119 * @param group the group, see KIconLoader::Group
120 * @param state the state, see KIconLoader::States
121 * @return the fingerprint of the given @p group+@p state
122 *
123 * @deprecated since 6.5, use the static API
124 */
125 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
126 QString fingerprint(int group, int state) const;
127#endif
128
129#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
130 /**
131 * Applies an effect to an image. The effect to apply depends on the
132 * @p group and @p state parameters, and is configured by the user.
133 * @param src The image.
134 * @param group The group for the icon, see KIconLoader::Group
135 * @param state The icon's state, see KIconLoader::States
136 * @return An image with the effect applied.
137 *
138 * @deprecated since 6.5, use the static API
139 */
140 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
141 QImage apply(const QImage &src, int group, int state) const;
142#endif
143
144#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
145 /**
146 * Applies an effect to an image.
147 * @param src The image.
148 * @param effect The effect to apply, one of KIconEffect::Effects.
149 * @param value Strength of the effect. 0 <= @p value <= 1.
150 * @param rgb Color parameter for effects that need one.
151 * @param trans Add Transparency if trans = true.
152 * @return An image with the effect applied.
153 *
154 * @deprecated since 6.5, use the static API
155 */
156 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
157 QImage apply(const QImage &src, int effect, float value, const QColor &rgb, bool trans) const;
158 QImage apply(const QImage &src, int effect, float value, const QColor &rgb, const QColor &rgb2, bool trans) const;
159#endif
160
161#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
162 /**
163 * Applies an effect to a pixmap.
164 * @param src The pixmap.
165 * @param group The group for the icon, see KIconLoader::Group
166 * @param state The icon's state, see KIconLoader::States
167 * @return A pixmap with the effect applied.
168 *
169 * @deprecated since 6.5, use the static API
170 */
171 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
172 QPixmap apply(const QPixmap &src, int group, int state) const;
173#endif
174
175#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
176 /**
177 * Applies an effect to a pixmap.
178 * @param src The pixmap.
179 * @param effect The effect to apply, one of KIconEffect::Effects.
180 * @param value Strength of the effect. 0 <= @p value <= 1.
181 * @param rgb Color parameter for effects that need one.
182 * @param trans Add Transparency if trans = true.
183 * @return A pixmap with the effect applied.
184 *
185 * @deprecated since 6.5, use the static API
186 */
187 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
188 QPixmap apply(const QPixmap &src, int effect, float value, const QColor &rgb, bool trans) const;
189 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
190 QPixmap apply(const QPixmap &src, int effect, float value, const QColor &rgb, const QColor &rgb2, bool trans) const;
191#endif
192
193#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
194 /**
195 * Returns an image twice as large, consisting of 2x2 pixels.
196 * @param src the image.
197 * @return the scaled image.
198 *
199 * @deprecated since 6.5, use the static API
200 */
201 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static API")
202 QImage doublePixels(const QImage &src) const;
203#endif
204
205 /**
206 * Tints an image gray.
207 *
208 * @param image The image
209 * @param value Strength of the effect. 0 <= @p value <= 1
210 */
211 static void toGray(QImage &image, float value);
212
213 /**
214 * Colorizes an image with a specific color.
215 *
216 * @param image The image
217 * @param col The color with which the @p image is tinted
218 * @param value Strength of the effect. 0 <= @p value <= 1
219 */
220 static void colorize(QImage &image, const QColor &col, float value);
221
222 /**
223 * Produces a monochrome icon with a given foreground and background color
224 *
225 * @param image The image
226 * @param white The color with which the white parts of @p image are painted
227 * @param black The color with which the black parts of @p image are painted
228 * @param value Strength of the effect. 0 <= @p value <= 1
229 */
230 static void toMonochrome(QImage &image, const QColor &black, const QColor &white, float value);
231
232 /**
233 * Desaturates an image.
234 *
235 * @param image The image
236 * @param value Strength of the effect. 0 <= @p value <= 1
237 */
238 static void deSaturate(QImage &image, float value);
239
240 /**
241 * Changes the gamma value of an image.
242 *
243 * @param image The image
244 * @param value Strength of the effect. 0 <= @p value <= 1
245 */
246 static void toGamma(QImage &image, float value);
247
248 /**
249 * Renders an image semi-transparent.
250 *
251 * @param image The image
252 */
253 static void semiTransparent(QImage &image);
254
255 /**
256 * Renders a pixmap semi-transparent.
257 *
258 * @param pixmap The pixmap
259 */
260 static void semiTransparent(QPixmap &pixmap);
261
262 /**
263 * Overlays an image with an other image.
264 *
265 * @param src The image
266 * @param overlay The image to overlay @p src with
267 */
268 static void overlay(QImage &src, QImage &overlay);
269
270 /**
271 * Applies a disabled effect
272 *
273 * @param image The image
274 *
275 * @since 6.5
276 */
277 static void toDisabled(QImage &image);
278
279 /**
280 * Applies a disabled effect
281 *
282 * @param pixmap The image
283 *
284 * @since 6.5
285 */
286 static void toDisabled(QPixmap &pixmap);
287
288 /**
289 * Applies an effect for an icon that is in an 'active' state
290 *
291 * @param image The image
292 *
293 * @since 6.5
294 */
295 static void toActive(QImage &image);
296
297 /**
298 * Applies an effect for an icon that is in an 'active' state
299 *
300 * @param pixmap The image
301 *
302 * @since 6.5
303 */
304 static void toActive(QPixmap &pixmap);
305
306private:
307 std::unique_ptr<KIconEffectPrivate> const d;
308};
309
310#endif
Applies effects to icons.
Definition kiconeffect.h:40
Effects
This is the enumeration of all possible icon effects.
Definition kiconeffect.h:77
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.