KIconThemes

kiconloader.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: 2000 Antonio Larrosa <larrosa@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-only
8*/
9
10#ifndef KICONLOADER_H
11#define KICONLOADER_H
12
13#include <QObject>
14#include <QSize>
15#include <QString>
16#include <QStringList>
17#include <memory>
18
19#if __has_include(<optional>) && __cplusplus >= 201703L
20#include <optional>
21#endif
22
23#include <kiconthemes_export.h>
24
25class QIcon;
26class QMovie;
27class QPixmap;
28
29class KIconColors;
30class KIconLoaderPrivate;
31class KIconEffect;
32class KIconTheme;
33
34/**
35 * @class KIconLoader kiconloader.h KIconLoader
36 *
37 * Iconloader for KDE.
38 *
39 * @note For most icon loading use cases perfer using QIcon::fromTheme
40 *
41 * KIconLoader will load the current icon theme and all its base themes.
42 * Icons will be searched in any of these themes. Additionally, it caches
43 * icons and applies effects according to the user's preferences.
44 *
45 * In KDE, it is encouraged to load icons by "Group". An icon group is a
46 * location on the screen where icons are being used. Standard groups are:
47 * Desktop, Toolbar, MainToolbar, Small and Panel. Each group can have some
48 * centrally-configured effects applied to its icons. This makes it possible
49 * to offer a consistent icon look in all KDE applications.
50 *
51 * The standard groups are defined below.
52 *
53 * @li KIconLoader::Desktop: Icons in the iconview of konqueror, kdesktop and similar apps.
54 * @li KIconLoader::Toolbar: Icons in toolbars.
55 * @li KIconLoader::MainToolbar: Icons in the main toolbars.
56 * @li KIconLoader::Small: Various small (typical 16x16) places: titlebars, listviews
57 * and menu entries.
58 * @li KIconLoader::Panel: Icons in kicker's panel
59 *
60 * The icons are stored on disk in an icon theme or in a standalone
61 * directory. The icon theme directories contain multiple sizes and/or
62 * depths for the same icon. The iconloader will load the correct one based
63 * on the icon group and the current theme. Icon themes are stored globally
64 * in share/icons, or, application specific in share/apps/$appdir/icons.
65 *
66 * The standalone directories contain just one version of an icon. The
67 * directories that are searched are: $appdir/pics and $appdir/toolbar.
68 * Icons in these directories can be loaded by using the special group
69 * "User".
70 *
71 */
72class KICONTHEMES_EXPORT KIconLoader : public QObject
73{
74 Q_OBJECT
75
76public:
77 /**
78 * Defines the context of the icon.
79 */
80 enum Context {
81 Any, ///< Some icon with unknown purpose.
82 Action, ///< An action icon (e.g. 'save', 'print').
83 Application, ///< An icon that represents an application.
84 Device, ///< An icon that represents a device.
85 MimeType, ///< An icon that represents a mime type (or file type).
86 Animation, ///< An icon that is animated.
87 Category, ///< An icon that represents a category.
88 Emblem, ///< An icon that adds information to an existing icon.
89 Emote, ///< An icon that expresses an emotion.
90 International, ///< An icon that represents a country's flag.
91 Place, ///< An icon that represents a location (e.g. 'home', 'trash').
92 StatusIcon, ///< An icon that represents an event.
93 };
94 Q_ENUM(Context)
95
96 /**
97 * The type of the icon.
98 */
99 enum Type {
100 Fixed, ///< Fixed-size icon.
101 Scalable, ///< Scalable-size icon.
102 Threshold, ///< A threshold icon.
103 };
104 Q_ENUM(Type)
105
106 /**
107 * The type of a match.
108 */
110 MatchExact, ///< Only try to find an exact match.
111 MatchBest, ///< Take the best match if there is no exact match.
112 MatchBestOrGreaterSize, ///< Take the best match or the match with a greater size if there is no exact match. @since 6.0
113 };
114 Q_ENUM(MatchType)
115
116 /**
117 * The group of the icon.
118 */
119 enum Group {
120 /// No group
121 NoGroup = -1,
122 /// Desktop icons
123 Desktop = 0,
124 /// First group
125 FirstGroup = 0,
126 /// Toolbar icons
128 /// Main toolbar icons
130 /// Small icons, e.g. for buttons
132 /// Panel (Plasma Taskbar) icons
133 // TODO KF6: remove this (See https://phabricator.kde.org/T14340)
135 /// Icons for use in dialog titles, page lists, etc
137 /// Last group
139 /// User icons
141 };
142 Q_ENUM(Group)
143
144 /**
145 * These are the standard sizes for icons.
146 */
147 enum StdSizes {
148 /// small icons for menu entries
149 SizeSmall = 16,
150 /// slightly larger small icons for toolbars, panels, etc
151 SizeSmallMedium = 22,
152 /// medium sized icons for the desktop
153 SizeMedium = 32,
154 /// large sized icons for the panel
155 SizeLarge = 48,
156 /// huge sized icons for iconviews
157 SizeHuge = 64,
158 /// enormous sized icons for iconviews
159 SizeEnormous = 128,
160 };
161 Q_ENUM(StdSizes)
162
163 /**
164 * Defines the possible states of an icon.
165 */
166 enum States {
167 DefaultState, ///< The default state.
168 ActiveState, ///< Icon is active.
169 DisabledState, ///< Icon is disabled.
170 SelectedState, ///< Icon is selected. @since 5.22
171 LastState, ///< Last state (last constant)
172 };
173 Q_ENUM(States)
174
175 /**
176 * Constructs an iconloader.
177 * @param appname Add the data directories of this application to the
178 * icon search path for the "User" group. The default argument adds the
179 * directories of the current application.
180 * @param extraSearchPaths additional search paths, either absolute or relative to GenericDataLocation
181 *
182 * Usually, you use the default iconloader, which can be accessed via
183 * KIconLoader::global(), so you hardly ever have to create an
184 * iconloader object yourself. That one is the application's iconloader.
185 */
186 explicit KIconLoader(const QString &appname = QString(), const QStringList &extraSearchPaths = QStringList(), QObject *parent = nullptr);
187
188 /**
189 * Cleanup
190 */
191 ~KIconLoader() override;
192
193 /**
194 * Returns the global icon loader initialized with the application name.
195 * @return global icon loader
196 */
197 static KIconLoader *global();
198
199 /**
200 * Adds @p appname to the list of application specific directories with @p themeBaseDir as its base directory.
201 * Assume the icons are in /home/user/app/icons/hicolor/48x48/my_app.png, the base directory would be
202 * /home/user/app/icons; KIconLoader automatically searches @p themeBaseDir + "/hicolor"
203 * This directory must contain a dir structure as defined by the XDG icons specification
204 * @param appname The application name.
205 * @param themeBaseDir The base directory of the application's theme (eg. "/home/user/app/icons")
206 */
207 void addAppDir(const QString &appname, const QString &themeBaseDir = QString());
208
209 /**
210 * Loads an icon. It will try very hard to find an icon which is
211 * suitable. If no exact match is found, a close match is searched.
212 * If neither an exact nor a close match is found, a null pixmap or
213 * the "unknown" pixmap is returned, depending on the value of the
214 * @p canReturnNull parameter.
215 *
216 * @param name The name of the icon, without extension.
217 * @param group The icon group. This will specify the size of and effects to
218 * be applied to the icon.
219 * @param size If nonzero, this overrides the size specified by @p group.
220 * See KIconLoader::StdSizes.
221 * @param state The icon state: @p DefaultState, @p ActiveState or
222 * @p DisabledState. Depending on the user's preferences, the iconloader
223 * may apply a visual effect to hint about its state.
224 * @param overlays a list of emblem icons to overlay, by name
225 * @see drawOverlays
226 * @param path_store If not null, the path of the icon is stored here,
227 * if the icon was found. If the icon was not found @p path_store
228 * is unaltered even if the "unknown" pixmap was returned.
229 * @param canReturnNull Can return a null pixmap? If false, the
230 * "unknown" pixmap is returned when no appropriate icon has been
231 * found. <em>Note:</em> a null pixmap can still be returned in the
232 * event of invalid parameters, such as empty names, negative sizes,
233 * and etc.
234 * @return the QPixmap. Can be null when not found, depending on
235 * @p canReturnNull.
236 */
237 QPixmap loadIcon(const QString &name,
238 KIconLoader::Group group,
239 int size = 0,
240 int state = KIconLoader::DefaultState,
241 const QStringList &overlays = QStringList(),
242 QString *path_store = nullptr,
243 bool canReturnNull = false) const;
244
245 /**
246 * Loads an icon. It will try very hard to find an icon which is
247 * suitable. If no exact match is found, a close match is searched.
248 * If neither an exact nor a close match is found, a null pixmap or
249 * the "unknown" pixmap is returned, depending on the value of the
250 * @p canReturnNull parameter.
251 *
252 * @param name The name of the icon, without extension.
253 * @param group The icon group. This will specify the size of and effects to
254 * be applied to the icon.
255 * @param scale The scale of the icon group to use. If no icon exists in the
256 * scaled group, a 1x icon with its size multiplied by the scale will be
257 * loaded instead.
258 * @param size If nonzero, this overrides the size specified by @p group.
259 * See KIconLoader::StdSizes.
260 * @param state The icon state: @p DefaultState, @p ActiveState or
261 * @p DisabledState. Depending on the user's preferences, the iconloader
262 * may apply a visual effect to hint about its state.
263 * @param overlays a list of emblem icons to overlay, by name
264 * @see drawOverlays
265 * @param path_store If not null, the path of the icon is stored here,
266 * if the icon was found. If the icon was not found @p path_store
267 * is unaltered even if the "unknown" pixmap was returned.
268 * @param canReturnNull Can return a null pixmap? If false, the
269 * "unknown" pixmap is returned when no appropriate icon has been
270 * found. <em>Note:</em> a null pixmap can still be returned in the
271 * event of invalid parameters, such as empty names, negative sizes,
272 * and etc.
273 * @return the QPixmap. Can be null when not found, depending on
274 * @p canReturnNull.
275 * @since 5.48
276 */
277 // TODO KF6 merge loadIcon() and loadScaledIcon()
278 QPixmap loadScaledIcon(const QString &name,
279 KIconLoader::Group group,
280 qreal scale,
281 int size = 0,
282 int state = KIconLoader::DefaultState,
283 const QStringList &overlays = QStringList(),
284 QString *path_store = nullptr,
285 bool canReturnNull = false) const;
286
287 /**
288 * Loads an icon. It will try very hard to find an icon which is
289 * suitable. If no exact match is found, a close match is searched.
290 * If neither an exact nor a close match is found, a null pixmap or
291 * the "unknown" pixmap is returned, depending on the value of the
292 * @p canReturnNull parameter.
293 *
294 * @param name The name of the icon, without extension.
295 * @param group The icon group. This will specify the size of and effects to
296 * be applied to the icon.
297 * @param scale The scale of the icon group to use. If no icon exists in the
298 * scaled group, a 1x icon with its size multiplied by the scale will be
299 * loaded instead.
300 * @param size If nonzero, this overrides the size specified by @p group.
301 * See KIconLoader::StdSizes. The icon will be fit into @p size
302 * without changing the aspect ratio, which particularly matters
303 * for non-square icons.
304 * @param state The icon state: @p DefaultState, @p ActiveState or
305 * @p DisabledState. Depending on the user's preferences, the iconloader
306 * may apply a visual effect to hint about its state.
307 * @param overlays a list of emblem icons to overlay, by name
308 * @see drawOverlays
309 * @param path_store If not null, the path of the icon is stored here,
310 * if the icon was found. If the icon was not found @p path_store
311 * is unaltered even if the "unknown" pixmap was returned.
312 * @param canReturnNull Can return a null pixmap? If false, the
313 * "unknown" pixmap is returned when no appropriate icon has been
314 * found. <em>Note:</em> a null pixmap can still be returned in the
315 * event of invalid parameters, such as empty names, negative sizes,
316 * and etc.
317 * @return the QPixmap. Can be null when not found, depending on
318 * @p canReturnNull.
319 * @since 5.81
320 */
321 QPixmap loadScaledIcon(const QString &name,
322 KIconLoader::Group group,
323 qreal scale,
324 const QSize &size = {},
325 int state = KIconLoader::DefaultState,
326 const QStringList &overlays = QStringList(),
327 QString *path_store = nullptr,
328 bool canReturnNull = false) const;
329
330#if __has_include(<optional>) && __cplusplus >= 201703L
331 /**
332 * Loads an icon. It will try very hard to find an icon which is
333 * suitable. If no exact match is found, a close match is searched.
334 * If neither an exact nor a close match is found, a null pixmap or
335 * the "unknown" pixmap is returned, depending on the value of the
336 * @p canReturnNull parameter.
337 *
338 * @param name The name of the icon, without extension.
339 * @param group The icon group. This will specify the size of and effects to
340 * be applied to the icon.
341 * @param scale The scale of the icon group to use. If no icon exists in the
342 * scaled group, a 1x icon with its size multiplied by the scale will be
343 * loaded instead.
344 * @param size If nonzero, this overrides the size specified by @p group.
345 * See KIconLoader::StdSizes. The icon will be fit into @p size
346 * without changing the aspect ratio, which particularly matters
347 * for non-square icons.
348 * @param state The icon state: @p DefaultState, @p ActiveState or
349 * @p DisabledState. Depending on the user's preferences, the iconloader
350 * may apply a visual effect to hint about its state.
351 * @param overlays a list of emblem icons to overlay, by name
352 * @see drawOverlays
353 * @param path_store If not null, the path of the icon is stored here,
354 * if the icon was found. If the icon was not found @p path_store
355 * is unaltered even if the "unknown" pixmap was returned.
356 * @param canReturnNull Can return a null pixmap? If false, the
357 * "unknown" pixmap is returned when no appropriate icon has been
358 * found. <em>Note:</em> a null pixmap can still be returned in the
359 * event of invalid parameters, such as empty names, negative sizes,
360 * and etc.
361 * @param colorScheme will define the stylesheet used to color this icon.
362 * Note this will only work if @p name is an svg file.
363 * @return the QPixmap. Can be null when not found, depending on
364 * @p canReturnNull.
365 * @since 5.88
366 */
367 QPixmap loadScaledIcon(const QString &name,
368 KIconLoader::Group group,
369 qreal scale,
370 const QSize &size,
371 int state,
372 const QStringList &overlays,
373 QString *path_store,
374 bool canReturnNull,
375 const std::optional<KIconColors> &colorScheme) const;
376#endif
377
378 /**
379 * Loads an icon for a mimetype.
380 * This is basically like loadIcon except that extra desktop themes are loaded if necessary.
381 *
382 * Consider using QIcon::fromTheme() with a fallback to "application-octet-stream" instead.
383 *
384 * @param iconName The name of the icon, without extension, usually from KMimeType.
385 * @param group The icon group. This will specify the size of and effects to
386 * be applied to the icon.
387 * @param size If nonzero, this overrides the size specified by @p group.
388 * See KIconLoader::StdSizes.
389 * @param state The icon state: @p DefaultState, @p ActiveState or
390 * @p DisabledState. Depending on the user's preferences, the iconloader
391 * may apply a visual effect to hint about its state.
392 * @param path_store If not null, the path of the icon is stored here.
393 * @param overlays a list of emblem icons to overlay, by name
394 * @see drawOverlays
395 * @return the QPixmap. Can not be null, the
396 * "unknown" pixmap is returned when no appropriate icon has been found.
397 */
398 QPixmap loadMimeTypeIcon(const QString &iconName,
399 KIconLoader::Group group,
400 int size = 0,
401 int state = KIconLoader::DefaultState,
402 const QStringList &overlays = QStringList(),
403 QString *path_store = nullptr) const;
404
405 /**
406 * Returns the path of an icon.
407 * @param name The name of the icon, without extension. If an absolute
408 * path is supplied for this parameter, iconPath will return it
409 * directly.
410 * @param group_or_size If positive, search icons whose size is
411 * specified by the icon group @p group_or_size. If negative, search
412 * icons whose size is - @p group_or_size.
413 * See KIconLoader::Group and KIconLoader::StdSizes
414 * @param canReturnNull Can return a null string? If not, a path to the
415 * "unknown" icon will be returned.
416 * @return the path of an icon, can be null or the "unknown" icon when
417 * not found, depending on @p canReturnNull.
418 */
419 QString iconPath(const QString &name, int group_or_size, bool canReturnNull = false) const;
420
421 /**
422 * Returns the path of an icon.
423 * @param name The name of the icon, without extension. If an absolute
424 * path is supplied for this parameter, iconPath will return it
425 * directly.
426 * @param group_or_size If positive, search icons whose size is
427 * specified by the icon group @p group_or_size. If negative, search
428 * icons whose size is - @p group_or_size.
429 * See KIconLoader::Group and KIconLoader::StdSizes
430 * @param canReturnNull Can return a null string? If not, a path to the
431 * "unknown" icon will be returned.
432 * @param scale The scale of the icon group.
433 * @return the path of an icon, can be null or the "unknown" icon when
434 * not found, depending on @p canReturnNull.
435 * @since 5.48
436 */
437 // TODO KF6 merge iconPath() with and without "scale" and move that argument after "group_or_size"
438 QString iconPath(const QString &name, int group_or_size, bool canReturnNull, qreal scale) const;
439
440#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
441 /**
442 * Loads an animated icon.
443 * @param name The name of the icon.
444 * @param group The icon group. See loadIcon().
445 * @param size Override the default size for @p group.
446 * See KIconLoader::StdSizes.
447 * @param parent The parent object of the returned QMovie.
448 * @return A QMovie object. Can be null if not found or not valid.
449 * Ownership is passed to the caller.
450 * @deprecated since 6.5, use QMovie API
451 */
452 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use QMovie API")
453 QMovie *loadMovie(const QString &name, KIconLoader::Group group, int size = 0, QObject *parent = nullptr) const;
454#endif
455
456#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
457 /**
458 * Returns the path to an animated icon.
459 * @param name The name of the icon.
460 * @param group The icon group. See loadIcon().
461 * @param size Override the default size for @p group.
462 * See KIconLoader::StdSizes.
463 * @return the full path to the movie, ready to be passed to QMovie's constructor.
464 * Empty string if not found.
465 * @deprecated since 6.5, use QMovie API
466 */
467 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use QMovie API")
468 QString moviePath(const QString &name, KIconLoader::Group group, int size = 0) const;
469#endif
470
471#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
472 /**
473 * Loads an animated icon as a series of still frames. If you want to load
474 * a .mng animation as QMovie instead, please use loadMovie() instead.
475 * @param name The name of the icon.
476 * @param group The icon group. See loadIcon().
477 * @param size Override the default size for @p group.
478 * See KIconLoader::StdSizes.
479 * @return A QStringList containing the absolute path of all the frames
480 * making up the animation.
481 *
482 * @deprecated since 6.5, use QMovie API
483 */
484 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use QMovie API")
485 QStringList loadAnimated(const QString &name, KIconLoader::Group group, int size = 0) const;
486#endif
487
488 /**
489 * Queries all available icons for a specific group, having a specific
490 * context.
491 * @param group_or_size If positive, search icons whose size is
492 * specified by the icon group @p group_or_size. If negative, search
493 * icons whose size is - @p group_or_size.
494 * See KIconLoader::Group and KIconLoader::StdSizes
495 * @param context The icon context.
496 * @return a list of all icons
497 */
498 QStringList queryIcons(int group_or_size, KIconLoader::Context context = KIconLoader::Any) const;
499
500 /**
501 * Queries all available icons for a specific context.
502 * @param group_or_size The icon preferred group or size. If available
503 * at this group or size, those icons will be returned, in other case,
504 * icons of undefined size will be returned. Positive numbers are groups,
505 * negative numbers are negated sizes. See KIconLoader::Group and
506 * KIconLoader::StdSizes
507 * @param context The icon context.
508 * @return A QStringList containing the icon names
509 * available for that context
510 */
511 QStringList queryIconsByContext(int group_or_size, KIconLoader::Context context = KIconLoader::Any) const;
512
513 /**
514 * @internal
515 */
516 bool hasContext(KIconLoader::Context context) const;
517
518 /**
519 * Returns a list of all icons (*.png or *.xpm extension) in the
520 * given directory.
521 * @param iconsDir the directory to search in
522 * @return A QStringList containing the icon paths
523 */
524 QStringList queryIconsByDir(const QString &iconsDir) const;
525
526 /**
527 * Returns all the search paths for this icon loader, either absolute or
528 * relative to GenericDataLocation.
529 * Mostly internal (for KIconDialog).
530 * \since 5.0
531 */
532 QStringList searchPaths() const;
533
534 /**
535 * Returns the size of the specified icon group.
536 * Using e.g. KIconLoader::SmallIcon will return 16.
537 * @param group the group to check.
538 * @return the current size for an icon group.
539 */
540 int currentSize(KIconLoader::Group group) const;
541
542 /**
543 * Returns a pointer to the current theme. Can be used to query
544 * available and default sizes for groups.
545 * @note The KIconTheme will change if reconfigure() is called and
546 * therefore it's not recommended to store the pointer anywhere.
547 * @return a pointer to the current theme. 0 if no theme set.
548 */
549 KIconTheme *theme() const;
550
551#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
552 /**
553 * Returns a pointer to the KIconEffect object used by the icon loader.
554 * @return the KIconEffect.
555 *
556 * @deprecated since 6.5, use the static KIconEffect API
557 */
558 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use static KIconEffect API")
559 KIconEffect *iconEffect() const;
560#endif
561
562 /**
563 * Reconfigure the icon loader, for instance to change the associated app name or extra search paths.
564 * This also clears the in-memory pixmap cache (even if the appname didn't change, which is useful for unittests)
565 * @param appname the application name (empty for the global iconloader)
566 * @param extraSearchPaths additional search paths, either absolute or relative to GenericDataLocation
567 */
568 void reconfigure(const QString &appname, const QStringList &extraSearchPaths = QStringList());
569
570 /**
571 * Returns the unknown icon. An icon that is used when no other icon
572 * can be found.
573 * @return the unknown pixmap
574 */
575 static QPixmap unknown();
576
577#if KICONTHEMES_ENABLE_DEPRECATED_SINCE(6, 5)
578 /**
579 * Draws overlays on the specified pixmap, it takes the width and height
580 * of the pixmap into consideration
581 * @param overlays List of up to 4 overlays to blend over the pixmap. The first overlay
582 * will be in the bottom right corner, followed by bottom left, top left
583 * and top right. An empty QString can be used to leave the specific position
584 * blank.
585 * @param pixmap to draw on
586 * @since 4.7
587 * @deprecated since 6.5, use KIconUtils::addOverlays from KGuiAddons
588 */
589 KICONTHEMES_DEPRECATED_VERSION(6, 5, "Use KIconUtils::addOverlays from KGuiAddons")
590 void drawOverlays(const QStringList &overlays, QPixmap &pixmap, KIconLoader::Group group, int state = KIconLoader::DefaultState) const;
591#endif
592
593 bool hasIcon(const QString &iconName) const;
594
595 /**
596 * Sets the colors for this KIconLoader.
597 * NOTE: if you set a custom palette, if you are using some colors from
598 * application's palette, you need to track the application palette changes by yourself.
599 * If you no longer wish to use a custom palette, use resetPalette()
600 * @see resetPalette
601 * @since 5.39
602 */
603 void setCustomPalette(const QPalette &palette);
604
605 /**
606 * The colors that will be used for the svg stylesheet in case the
607 * loaded icons are svg-based, icons can be colored in different ways in
608 * different areas of the application
609 * @return the palette, if any, an invalid one if the user didn't set it
610 * @since 5.39
611 */
612 QPalette customPalette() const;
613
614 /**
615 * Resets the custom palette used by the KIconLoader to use the
616 * QGuiApplication::palette() again (and to follow it in case the
617 * application's palette changes)
618 * @since 5.39
619 */
620 void resetPalette();
621
622 /**
623 * @returns whether we have set a custom palette using @f setCustomPalette
624 *
625 * @since 5.85
626 * @see resetPalette, setCustomPalette
627 */
628 bool hasCustomPalette() const;
629
630public Q_SLOTS:
631 // TODO: while marked as deprecated, newIconLoader() is still used:
632 // internally by KIconLoadeer as well as by Plasma's Icons kcm module (state: 5.17)
633 // this needs some further cleanup work before removing it from the API with KICONTHEMES_ENABLE_DEPRECATED_SINCE
634 /**
635 * Re-initialize the global icon loader
636 *
637 * @todo Check deprecation, still used internally.
638 * @deprecated Since 5.0, use emitChange(Group)
639 */
640 KICONTHEMES_DEPRECATED_VERSION(5, 0, "Use KIconLoader::emitChange(Group)") // TODO KF6 remove
641 void newIconLoader();
642
643 /**
644 * Emits an iconChanged() signal on all the KIconLoader instances in the system
645 * indicating that a system's icon group has changed in some way. It will also trigger
646 * a reload in all of them to update to the new theme.
647 *
648 * @p group indicates the group that has changed
649 *
650 * @since 5.0
651 */
652 static void emitChange(Group group);
653
654Q_SIGNALS:
655 /**
656 * Emitted by newIconLoader once the new settings have been loaded
657 */
658 void iconLoaderSettingsChanged();
659
660 /**
661 * Emitted when the system icon theme changes
662 *
663 * @since 5.0
664 */
665 void iconChanged(int group);
666
667private:
668 friend class KIconLoaderPrivate;
669 // @internal the data object
670 std::unique_ptr<KIconLoaderPrivate> const d;
671
672 Q_PRIVATE_SLOT(d, void _k_refreshIcons(int group))
673};
674
675namespace KDE
676{
677/**
678 * \relates KIconLoader
679 * Returns a QIcon with an appropriate
680 * KIconEngine to perform loading and rendering. KIcons thus adhere to
681 * KDE style and effect standards.
682 * @since 5.0
683 */
684KICONTHEMES_EXPORT QIcon icon(const QString &iconName, KIconLoader *iconLoader = nullptr);
685KICONTHEMES_EXPORT QIcon icon(const QString &iconName, const KIconColors &colors, KIconLoader *iconLoader = nullptr);
686
687/**
688 * \relates KIconLoader
689 * Returns a QIcon for the given icon, with additional overlays.
690 * @since 5.0
691 */
692KICONTHEMES_EXPORT QIcon icon(const QString &iconName, const QStringList &overlays, KIconLoader *iconLoader = nullptr);
693
694}
695
696inline KIconLoader::Group &operator++(KIconLoader::Group &group)
697{
698 group = static_cast<KIconLoader::Group>(group + 1);
699 return group;
700}
701inline KIconLoader::Group operator++(KIconLoader::Group &group, int)
702{
703 KIconLoader::Group ret = group;
704 ++group;
705 return ret;
706}
707
708#endif // KICONLOADER_H
Sepecifies which colors will be used when recoloring icons as its stylesheet.
Definition kiconcolors.h:31
Applies effects to icons.
Definition kiconeffect.h:40
Iconloader for KDE.
Definition kiconloader.h:73
Group
The group of the icon.
@ Small
Small icons, e.g. for buttons.
@ Panel
Panel (Plasma Taskbar) icons.
@ User
User icons.
@ LastGroup
Last group.
@ MainToolbar
Main toolbar icons.
@ Toolbar
Toolbar icons.
@ Dialog
Icons for use in dialog titles, page lists, etc.
~KIconLoader() override
Cleanup.
States
Defines the possible states of an icon.
@ ActiveState
Icon is active.
@ DisabledState
Icon is disabled.
@ LastState
Last state (last constant)
@ DefaultState
The default state.
@ SelectedState
Icon is selected.
StdSizes
These are the standard sizes for icons.
KICONTHEMES_EXPORT QIcon icon(const QString &iconName, const QStringList &overlays, KIconLoader *iconLoader=nullptr)
Returns a QIcon for the given icon, with additional overlays.
KICONTHEMES_EXPORT QIcon icon(const QString &iconName, KIconLoader *iconLoader=nullptr)
Returns a QIcon with an appropriate KIconEngine to perform loading and rendering.
Context
Defines the context of the icon.
Definition kiconloader.h:80
@ Category
An icon that represents a category.
Definition kiconloader.h:87
@ Emblem
An icon that adds information to an existing icon.
Definition kiconloader.h:88
@ StatusIcon
An icon that represents an event.
Definition kiconloader.h:92
@ Application
An icon that represents an application.
Definition kiconloader.h:83
@ Emote
An icon that expresses an emotion.
Definition kiconloader.h:89
@ Any
Some icon with unknown purpose.
Definition kiconloader.h:81
@ Place
An icon that represents a location (e.g. 'home', 'trash').
Definition kiconloader.h:91
@ MimeType
An icon that represents a mime type (or file type).
Definition kiconloader.h:85
@ Action
An action icon (e.g. 'save', 'print').
Definition kiconloader.h:82
@ International
An icon that represents a country's flag.
Definition kiconloader.h:90
@ Animation
An icon that is animated.
Definition kiconloader.h:86
@ Device
An icon that represents a device.
Definition kiconloader.h:84
Type
The type of the icon.
Definition kiconloader.h:99
@ Fixed
Fixed-size icon.
@ Scalable
Scalable-size icon.
@ Threshold
A threshold icon.
MatchType
The type of a match.
@ MatchBest
Take the best match if there is no exact match.
@ MatchExact
Only try to find an exact match.
@ MatchBestOrGreaterSize
Take the best match or the match with a greater size if there is no exact match.
Q_ENUM(...)
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.