File indexing completed on 2024-04-21 14:59:18

0001 /* vi: ts=8 sts=4 sw=4
0002 
0003     This file is part of the KDE project, module kdecore.
0004     SPDX-FileCopyrightText: 2000 Geert Jansen <jansen@kde.org>
0005     SPDX-FileCopyrightText: 2000 Antonio Larrosa <larrosa@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-only
0008 */
0009 
0010 #ifndef KICONLOADER_H
0011 #define KICONLOADER_H
0012 
0013 #include <QObject>
0014 #include <QSize>
0015 #include <QString>
0016 #include <QStringList>
0017 #include <memory>
0018 
0019 #if __has_include(<optional>) && __cplusplus >= 201703L
0020 #include <optional>
0021 #endif
0022 
0023 #include <kiconthemes_export.h>
0024 
0025 class QIcon;
0026 class QMovie;
0027 class QPixmap;
0028 
0029 class KIconColors;
0030 class KIconLoaderPrivate;
0031 class KIconEffect;
0032 class KIconTheme;
0033 
0034 class KPixmapSequence;
0035 
0036 /**
0037  * @class KIconLoader kiconloader.h KIconLoader
0038  *
0039  * Iconloader for KDE.
0040  *
0041  * KIconLoader will load the current icon theme and all its base themes.
0042  * Icons will be searched in any of these themes. Additionally, it caches
0043  * icons and applies effects according to the user's preferences.
0044  *
0045  * In KDE, it is encouraged to load icons by "Group". An icon group is a
0046  * location on the screen where icons are being used. Standard groups are:
0047  * Desktop, Toolbar, MainToolbar, Small and Panel. Each group has some
0048  * centrally configured properties bound to it, including the icon size
0049  * and effects. This makes it possible to offer a consistent icon look in
0050  * all KDE applications.
0051  *
0052  * The standard groups are defined below.
0053  *
0054  * @li KIconLoader::Desktop: Icons in the iconview of konqueror, kdesktop and similar apps.
0055  * @li KIconLoader::Toolbar: Icons in toolbars.
0056  * @li KIconLoader::MainToolbar: Icons in the main toolbars.
0057  * @li KIconLoader::Small: Various small (typical 16x16) places: titlebars, listviews
0058  * and menu entries.
0059  * @li KIconLoader::Panel: Icons in kicker's panel
0060  *
0061  * The icons are stored on disk in an icon theme or in a standalone
0062  * directory. The icon theme directories contain multiple sizes and/or
0063  * depths for the same icon. The iconloader will load the correct one based
0064  * on the icon group and the current theme. Icon themes are stored globally
0065  * in share/icons, or, application specific in share/apps/$appdir/icons.
0066  *
0067  * The standalone directories contain just one version of an icon. The
0068  * directories that are searched are: $appdir/pics and $appdir/toolbar.
0069  * Icons in these directories can be loaded by using the special group
0070  * "User".
0071  *
0072  */
0073 class KICONTHEMES_EXPORT KIconLoader : public QObject
0074 {
0075     Q_OBJECT
0076 
0077 public:
0078     /**
0079      * Defines the context of the icon.
0080      */
0081     enum Context {
0082         Any, ///< Some icon with unknown purpose.
0083         Action, ///< An action icon (e.g. 'save', 'print').
0084         Application, ///< An icon that represents an application.
0085         Device, ///< An icon that represents a device.
0086 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(4, 8)
0087         FileSystem ///< An icon that represents a file system. @deprecated Since 4.8. Use Place instead.
0088             KICONTHEMES_ENUMERATOR_DEPRECATED_VERSION_BELATED(5, 82, 4, 8, "Use Place instead"),
0089 #elif KICONTHEMES_BUILD_DEPRECATED_SINCE(4, 8)
0090         FileSystem_DEPRECATED_DO_NOT_USE,
0091 #endif
0092         MimeType, ///< An icon that represents a mime type (or file type).
0093         Animation, ///< An icon that is animated.
0094         Category, ///< An icon that represents a category.
0095         Emblem, ///< An icon that adds information to an existing icon.
0096         Emote, ///< An icon that expresses an emotion.
0097         International, ///< An icon that represents a country's flag.
0098         Place, ///< An icon that represents a location (e.g. 'home', 'trash').
0099         StatusIcon, ///< An icon that represents an event.
0100     };
0101     Q_ENUM(Context)
0102 
0103     /**
0104      * The type of the icon.
0105      */
0106     enum Type {
0107         Fixed, ///< Fixed-size icon.
0108         Scalable, ///< Scalable-size icon.
0109         Threshold, ///< A threshold icon.
0110     };
0111     Q_ENUM(Type)
0112 
0113     /**
0114      * The type of a match.
0115      */
0116     enum MatchType {
0117         MatchExact, ///< Only try to find an exact match.
0118         MatchBest, ///< Take the best match if there is no exact match.
0119     };
0120     Q_ENUM(MatchType)
0121 
0122     /**
0123      * The group of the icon.
0124      */
0125     enum Group {
0126         /// No group
0127         NoGroup = -1,
0128         /// Desktop icons
0129         Desktop = 0,
0130         /// First group
0131         FirstGroup = 0,
0132         /// Toolbar icons
0133         Toolbar,
0134         /// Main toolbar icons
0135         MainToolbar,
0136         /// Small icons, e.g. for buttons
0137         Small,
0138 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 104)
0139         /// Panel (Plasma Taskbar) icons, @deprecated since 5.104, use another group or explicit size
0140         Panel KICONTHEMES_ENUMERATOR_DEPRECATED_VERSION(5, 104, "Use another group or explicit size"),
0141 #else
0142         Panel_DEPRECATED_DO_NOT_USE,
0143 #endif
0144         /// Icons for use in dialog titles, page lists, etc
0145         Dialog,
0146         /// Last group
0147         LastGroup,
0148         /// User icons
0149         User,
0150     };
0151     Q_ENUM(Group)
0152 
0153     /**
0154      * These are the standard sizes for icons.
0155      */
0156     enum StdSizes {
0157         /// small icons for menu entries
0158         SizeSmall = 16,
0159         /// slightly larger small icons for toolbars, panels, etc
0160         SizeSmallMedium = 22,
0161         /// medium sized icons for the desktop
0162         SizeMedium = 32,
0163         /// large sized icons for the panel
0164         SizeLarge = 48,
0165         /// huge sized icons for iconviews
0166         SizeHuge = 64,
0167         /// enormous sized icons for iconviews
0168         SizeEnormous = 128,
0169     };
0170     Q_ENUM(StdSizes)
0171 
0172     /**
0173      * Defines the possible states of an icon.
0174      */
0175     enum States {
0176         DefaultState, ///< The default state.
0177         ActiveState, ///< Icon is active.
0178         DisabledState, ///< Icon is disabled.
0179         SelectedState, ///< Icon is selected. @since 5.22
0180         LastState, ///< Last state (last constant)
0181     };
0182     Q_ENUM(States)
0183 
0184     /**
0185      * Constructs an iconloader.
0186      * @param appname Add the data directories of this application to the
0187      * icon search path for the "User" group. The default argument adds the
0188      * directories of the current application.
0189      * @param extraSearchPaths additional search paths, either absolute or relative to GenericDataLocation
0190      *
0191      * Usually, you use the default iconloader, which can be accessed via
0192      * KIconLoader::global(), so you hardly ever have to create an
0193      * iconloader object yourself. That one is the application's iconloader.
0194      */
0195     explicit KIconLoader(const QString &appname = QString(), const QStringList &extraSearchPaths = QStringList(), QObject *parent = nullptr);
0196 
0197     /**
0198      * Cleanup
0199      */
0200     ~KIconLoader() override;
0201 
0202     /**
0203      * Returns the global icon loader initialized with the application name.
0204      * @return global icon loader
0205      */
0206     static KIconLoader *global();
0207 
0208     /**
0209      * Adds @p appname to the list of application specific directories with @p themeBaseDir as its base directory.
0210      * Assume the icons are in /home/user/app/icons/hicolor/48x48/my_app.png, the base directory would be
0211      * /home/user/app/icons; KIconLoader automatically searches @p themeBaseDir + "/hicolor"
0212      * This directory must contain a dir structure as defined by the XDG icons specification
0213      * @param appname The application name.
0214      * @param themeBaseDir The base directory of the application's theme (eg. "/home/user/app/icons")
0215      */
0216     void addAppDir(const QString &appname, const QString &themeBaseDir = QString());
0217 
0218     /**
0219      * Loads an icon. It will try very hard to find an icon which is
0220      * suitable. If no exact match is found, a close match is searched.
0221      * If neither an exact nor a close match is found, a null pixmap or
0222      * the "unknown" pixmap is returned, depending on the value of the
0223      * @p canReturnNull parameter.
0224      *
0225      * @param name The name of the icon, without extension.
0226      * @param group The icon group. This will specify the size of and effects to
0227      * be applied to the icon.
0228      * @param size If nonzero, this overrides the size specified by @p group.
0229      *             See KIconLoader::StdSizes.
0230      * @param state The icon state: @p DefaultState, @p ActiveState or
0231      * @p DisabledState. Depending on the user's preferences, the iconloader
0232      * may apply a visual effect to hint about its state.
0233      * @param overlays a list of emblem icons to overlay, by name
0234      *                 @see drawOverlays
0235      * @param path_store If not null, the path of the icon is stored here,
0236      *        if the icon was found. If the icon was not found @p path_store
0237      *        is unaltered even if the "unknown" pixmap was returned.
0238      * @param canReturnNull Can return a null pixmap? If false, the
0239      *        "unknown" pixmap is returned when no appropriate icon has been
0240      *        found. <em>Note:</em> a null pixmap can still be returned in the
0241      *        event of invalid parameters, such as empty names, negative sizes,
0242      *        and etc.
0243      * @return the QPixmap. Can be null when not found, depending on
0244      *         @p canReturnNull.
0245      */
0246     QPixmap loadIcon(const QString &name,
0247                      KIconLoader::Group group,
0248                      int size = 0,
0249                      int state = KIconLoader::DefaultState,
0250                      const QStringList &overlays = QStringList(),
0251                      QString *path_store = nullptr,
0252                      bool canReturnNull = false) const;
0253 
0254     /**
0255      * Loads an icon. It will try very hard to find an icon which is
0256      * suitable. If no exact match is found, a close match is searched.
0257      * If neither an exact nor a close match is found, a null pixmap or
0258      * the "unknown" pixmap is returned, depending on the value of the
0259      * @p canReturnNull parameter.
0260      *
0261      * @param name The name of the icon, without extension.
0262      * @param group The icon group. This will specify the size of and effects to
0263      * be applied to the icon.
0264      * @param scale The scale of the icon group to use. If no icon exists in the
0265      * scaled group, a 1x icon with its size multiplied by the scale will be
0266      * loaded instead.
0267      * @param size If nonzero, this overrides the size specified by @p group.
0268      *             See KIconLoader::StdSizes.
0269      * @param state The icon state: @p DefaultState, @p ActiveState or
0270      * @p DisabledState. Depending on the user's preferences, the iconloader
0271      * may apply a visual effect to hint about its state.
0272      * @param overlays a list of emblem icons to overlay, by name
0273      *                 @see drawOverlays
0274      * @param path_store If not null, the path of the icon is stored here,
0275      *        if the icon was found. If the icon was not found @p path_store
0276      *        is unaltered even if the "unknown" pixmap was returned.
0277      * @param canReturnNull Can return a null pixmap? If false, the
0278      *        "unknown" pixmap is returned when no appropriate icon has been
0279      *        found. <em>Note:</em> a null pixmap can still be returned in the
0280      *        event of invalid parameters, such as empty names, negative sizes,
0281      *        and etc.
0282      * @return the QPixmap. Can be null when not found, depending on
0283      *         @p canReturnNull.
0284      * @since 5.48
0285      */
0286     // TODO KF6 merge loadIcon() and loadScaledIcon()
0287     QPixmap loadScaledIcon(const QString &name,
0288                            KIconLoader::Group group,
0289                            qreal scale,
0290                            int size = 0,
0291                            int state = KIconLoader::DefaultState,
0292                            const QStringList &overlays = QStringList(),
0293                            QString *path_store = nullptr,
0294                            bool canReturnNull = false) const;
0295 
0296     /**
0297      * Loads an icon. It will try very hard to find an icon which is
0298      * suitable. If no exact match is found, a close match is searched.
0299      * If neither an exact nor a close match is found, a null pixmap or
0300      * the "unknown" pixmap is returned, depending on the value of the
0301      * @p canReturnNull parameter.
0302      *
0303      * @param name The name of the icon, without extension.
0304      * @param group The icon group. This will specify the size of and effects to
0305      * be applied to the icon.
0306      * @param scale The scale of the icon group to use. If no icon exists in the
0307      * scaled group, a 1x icon with its size multiplied by the scale will be
0308      * loaded instead.
0309      * @param size If nonzero, this overrides the size specified by @p group.
0310      *             See KIconLoader::StdSizes. The icon will be fit into @p size
0311      *             without changing the aspect ratio, which particularly matters
0312      *             for non-square icons.
0313      * @param state The icon state: @p DefaultState, @p ActiveState or
0314      * @p DisabledState. Depending on the user's preferences, the iconloader
0315      * may apply a visual effect to hint about its state.
0316      * @param overlays a list of emblem icons to overlay, by name
0317      *                 @see drawOverlays
0318      * @param path_store If not null, the path of the icon is stored here,
0319      *        if the icon was found. If the icon was not found @p path_store
0320      *        is unaltered even if the "unknown" pixmap was returned.
0321      * @param canReturnNull Can return a null pixmap? If false, the
0322      *        "unknown" pixmap is returned when no appropriate icon has been
0323      *        found. <em>Note:</em> a null pixmap can still be returned in the
0324      *        event of invalid parameters, such as empty names, negative sizes,
0325      *        and etc.
0326      * @return the QPixmap. Can be null when not found, depending on
0327      *         @p canReturnNull.
0328      * @since 5.81
0329      */
0330     QPixmap loadScaledIcon(const QString &name,
0331                            KIconLoader::Group group,
0332                            qreal scale,
0333                            const QSize &size = {},
0334                            int state = KIconLoader::DefaultState,
0335                            const QStringList &overlays = QStringList(),
0336                            QString *path_store = nullptr,
0337                            bool canReturnNull = false) const;
0338 
0339 #if __has_include(<optional>) && __cplusplus >= 201703L
0340     /**
0341      * Loads an icon. It will try very hard to find an icon which is
0342      * suitable. If no exact match is found, a close match is searched.
0343      * If neither an exact nor a close match is found, a null pixmap or
0344      * the "unknown" pixmap is returned, depending on the value of the
0345      * @p canReturnNull parameter.
0346      *
0347      * @param name The name of the icon, without extension.
0348      * @param group The icon group. This will specify the size of and effects to
0349      * be applied to the icon.
0350      * @param scale The scale of the icon group to use. If no icon exists in the
0351      * scaled group, a 1x icon with its size multiplied by the scale will be
0352      * loaded instead.
0353      * @param size If nonzero, this overrides the size specified by @p group.
0354      *             See KIconLoader::StdSizes. The icon will be fit into @p size
0355      *             without changing the aspect ratio, which particularly matters
0356      *             for non-square icons.
0357      * @param state The icon state: @p DefaultState, @p ActiveState or
0358      * @p DisabledState. Depending on the user's preferences, the iconloader
0359      * may apply a visual effect to hint about its state.
0360      * @param overlays a list of emblem icons to overlay, by name
0361      *                 @see drawOverlays
0362      * @param path_store If not null, the path of the icon is stored here,
0363      *        if the icon was found. If the icon was not found @p path_store
0364      *        is unaltered even if the "unknown" pixmap was returned.
0365      * @param canReturnNull Can return a null pixmap? If false, the
0366      *        "unknown" pixmap is returned when no appropriate icon has been
0367      *        found. <em>Note:</em> a null pixmap can still be returned in the
0368      *        event of invalid parameters, such as empty names, negative sizes,
0369      *        and etc.
0370      * @param colorScheme will define the stylesheet used to color this icon.
0371      *        Note this will only work if @p name is an svg file.
0372      * @return the QPixmap. Can be null when not found, depending on
0373      *         @p canReturnNull.
0374      * @since 5.88
0375      */
0376     QPixmap loadScaledIcon(const QString &name,
0377                            KIconLoader::Group group,
0378                            qreal scale,
0379                            const QSize &size,
0380                            int state,
0381                            const QStringList &overlays,
0382                            QString *path_store,
0383                            bool canReturnNull,
0384                            const std::optional<KIconColors> &colorScheme) const;
0385 #endif
0386 
0387     /**
0388      * Loads an icon for a mimetype.
0389      * This is basically like loadIcon except that extra desktop themes are loaded if necessary.
0390      *
0391      * Consider using QIcon::fromTheme() with a fallback to "application-octet-stream" instead.
0392      *
0393      * @param iconName The name of the icon, without extension, usually from KMimeType.
0394      * @param group The icon group. This will specify the size of and effects to
0395      * be applied to the icon.
0396      * @param size If nonzero, this overrides the size specified by @p group.
0397      *             See KIconLoader::StdSizes.
0398      * @param state The icon state: @p DefaultState, @p ActiveState or
0399      * @p DisabledState. Depending on the user's preferences, the iconloader
0400      * may apply a visual effect to hint about its state.
0401      * @param path_store If not null, the path of the icon is stored here.
0402      * @param overlays a list of emblem icons to overlay, by name
0403      *                 @see drawOverlays
0404      * @return the QPixmap. Can not be null, the
0405      * "unknown" pixmap is returned when no appropriate icon has been found.
0406      */
0407     QPixmap loadMimeTypeIcon(const QString &iconName,
0408                              KIconLoader::Group group,
0409                              int size = 0,
0410                              int state = KIconLoader::DefaultState,
0411                              const QStringList &overlays = QStringList(),
0412                              QString *path_store = nullptr) const;
0413 
0414     /**
0415      * Loads a pixmapSequence given the xdg icon name
0416      *
0417      * @param iconName The name of the icon, without extension.
0418      * @param size the size/group to be used
0419      * @since 5.0
0420      */
0421     KPixmapSequence loadPixmapSequence(const QString &iconName, int size = SizeSmall) const;
0422 
0423 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 0)
0424     /**
0425      * Creates an icon set, that will do on-demand loading of the icon.
0426      * Loading itself is done by calling loadIcon .
0427      *
0428      * @param name The name of the icon, without extension.
0429      * @param group The icon group. This will specify the size of and effects to
0430      * be applied to the icon.
0431      * @param size If nonzero, this overrides the size specified by @p group.
0432      *             See KIconLoader::StdSizes.
0433      * @param canReturnNull Can return a null iconset? If false, iconset
0434      * containing the "unknown" pixmap is returned when no appropriate icon has
0435      * been found.
0436      * @return the icon set. Can be null when not found, depending on
0437      *          @p canReturnNull.
0438      *
0439      * @deprecated Since 5.0, use QIcon::fromTheme instead, which uses the iconloader internally
0440      */
0441     KICONTHEMES_DEPRECATED_VERSION(5, 0, "Use QIcon::fromTheme(const QString&)")
0442     QIcon loadIconSet(const QString &name, KIconLoader::Group group, int size = 0, bool canReturnNull = false);
0443 #endif
0444 
0445     /**
0446      * Returns the path of an icon.
0447      * @param name The name of the icon, without extension. If an absolute
0448      * path is supplied for this parameter, iconPath will return it
0449      * directly.
0450      * @param group_or_size If positive, search icons whose size is
0451      * specified by the icon group @p group_or_size. If negative, search
0452      * icons whose size is - @p group_or_size.
0453      *             See KIconLoader::Group and KIconLoader::StdSizes
0454      * @param canReturnNull Can return a null string? If not, a path to the
0455      *                      "unknown" icon will be returned.
0456      * @return the path of an icon, can be null or the "unknown" icon when
0457      *         not found, depending on @p canReturnNull.
0458      */
0459     QString iconPath(const QString &name, int group_or_size, bool canReturnNull = false) const;
0460 
0461     /**
0462      * Returns the path of an icon.
0463      * @param name The name of the icon, without extension. If an absolute
0464      * path is supplied for this parameter, iconPath will return it
0465      * directly.
0466      * @param group_or_size If positive, search icons whose size is
0467      * specified by the icon group @p group_or_size. If negative, search
0468      * icons whose size is - @p group_or_size.
0469      *             See KIconLoader::Group and KIconLoader::StdSizes
0470      * @param canReturnNull Can return a null string? If not, a path to the
0471      *                      "unknown" icon will be returned.
0472      * @param scale The scale of the icon group.
0473      * @return the path of an icon, can be null or the "unknown" icon when
0474      *         not found, depending on @p canReturnNull.
0475      * @since 5.48
0476      */
0477     // TODO KF6 merge iconPath() with and without "scale" and move that argument after "group_or_size"
0478     QString iconPath(const QString &name, int group_or_size, bool canReturnNull, qreal scale) const;
0479 
0480     /**
0481      * Loads an animated icon.
0482      * @param name The name of the icon.
0483      * @param group The icon group. See loadIcon().
0484      * @param size Override the default size for @p group.
0485      *             See KIconLoader::StdSizes.
0486      * @param parent The parent object of the returned QMovie.
0487      * @return A QMovie object. Can be null if not found or not valid.
0488      *         Ownership is passed to the caller.
0489      */
0490     QMovie *loadMovie(const QString &name, KIconLoader::Group group, int size = 0, QObject *parent = nullptr) const;
0491 
0492     /**
0493      * Returns the path to an animated icon.
0494      * @param name The name of the icon.
0495      * @param group The icon group. See loadIcon().
0496      * @param size Override the default size for @p group.
0497      *             See KIconLoader::StdSizes.
0498      * @return the full path to the movie, ready to be passed to QMovie's constructor.
0499      * Empty string if not found.
0500      */
0501     QString moviePath(const QString &name, KIconLoader::Group group, int size = 0) const;
0502 
0503     /**
0504      * Loads an animated icon as a series of still frames. If you want to load
0505      * a .mng animation as QMovie instead, please use loadMovie() instead.
0506      * @param name The name of the icon.
0507      * @param group The icon group. See loadIcon().
0508      * @param size Override the default size for @p group.
0509      *             See KIconLoader::StdSizes.
0510      * @return A QStringList containing the absolute path of all the frames
0511      * making up the animation.
0512      */
0513     QStringList loadAnimated(const QString &name, KIconLoader::Group group, int size = 0) const;
0514 
0515     /**
0516      * Queries all available icons for a specific group, having a specific
0517      * context.
0518      * @param group_or_size If positive, search icons whose size is
0519      * specified by the icon group @p group_or_size. If negative, search
0520      * icons whose size is - @p group_or_size.
0521      *             See KIconLoader::Group and KIconLoader::StdSizes
0522      * @param context The icon context.
0523      * @return a list of all icons
0524      */
0525     QStringList queryIcons(int group_or_size, KIconLoader::Context context = KIconLoader::Any) const;
0526 
0527     /**
0528      * Queries all available icons for a specific context.
0529      * @param group_or_size The icon preferred group or size. If available
0530      * at this group or size, those icons will be returned, in other case,
0531      * icons of undefined size will be returned. Positive numbers are groups,
0532      * negative numbers are negated sizes. See KIconLoader::Group and
0533      * KIconLoader::StdSizes
0534      * @param context The icon context.
0535      * @return A QStringList containing the icon names
0536      * available for that context
0537      */
0538     QStringList queryIconsByContext(int group_or_size, KIconLoader::Context context = KIconLoader::Any) const;
0539 
0540     /**
0541      * @internal
0542      */
0543     bool hasContext(KIconLoader::Context context) const;
0544 
0545     /**
0546      * Returns a list of all icons (*.png or *.xpm extension) in the
0547      * given directory.
0548      * @param iconsDir the directory to search in
0549      * @return A QStringList containing the icon paths
0550      */
0551     QStringList queryIconsByDir(const QString &iconsDir) const;
0552 
0553     /**
0554      * Returns all the search paths for this icon loader, either absolute or
0555      * relative to GenericDataLocation.
0556      * Mostly internal (for KIconDialog).
0557      * \since 5.0
0558      */
0559     QStringList searchPaths() const;
0560 
0561     /**
0562      * Returns the current size of the icon group.
0563      * Using e.g. KIconLoader::SmallIcon will retrieve the icon size
0564      * that is currently set from System Settings->Appearance->Icon
0565      * sizes. SmallIcon for instance, would typically be 16x16, but
0566      * the user could increase it and this setting would change as well.
0567      * @param group the group to check.
0568      * @return the current size for an icon group.
0569      */
0570     int currentSize(KIconLoader::Group group) const;
0571 
0572     /**
0573      * Returns a pointer to the current theme. Can be used to query
0574      * available and default sizes for groups.
0575      * @note The KIconTheme will change if reconfigure() is called and
0576      * therefore it's not recommended to store the pointer anywhere.
0577      * @return a pointer to the current theme. 0 if no theme set.
0578      */
0579     KIconTheme *theme() const;
0580 
0581     /**
0582      * Returns a pointer to the KIconEffect object used by the icon loader.
0583      * @return the KIconEffect.
0584      */
0585     KIconEffect *iconEffect() const;
0586 
0587     /**
0588      * Reconfigure the icon loader, for instance to change the associated app name or extra search paths.
0589      * This also clears the in-memory pixmap cache (even if the appname didn't change, which is useful for unittests)
0590      * @param appname the application name (empty for the global iconloader)
0591      * @param extraSearchPaths additional search paths, either absolute or relative to GenericDataLocation
0592      */
0593     void reconfigure(const QString &appname, const QStringList &extraSearchPaths = QStringList());
0594 
0595     /**
0596      * Returns the unknown icon. An icon that is used when no other icon
0597      * can be found.
0598      * @return the unknown pixmap
0599      */
0600     static QPixmap unknown();
0601 
0602 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 82)
0603     /**
0604      * Checks whether the user wants to blend the icons with the background
0605      *  using the alpha channel information for a given group.
0606      * @param group the group to check
0607      * @return true if alpha blending is desired
0608      * @deprecated Since 3.1, no known users
0609      */
0610     KICONTHEMES_DEPRECATED_VERSION_BELATED(5, 82, 3, 1, "No known users")
0611     bool alphaBlending(KIconLoader::Group group) const;
0612 #endif
0613 
0614     /**
0615      * Draws overlays on the specified pixmap, it takes the width and height
0616      * of the pixmap into consideration
0617      * @param overlays List of up to 4 overlays to blend over the pixmap. The first overlay
0618      *                 will be in the bottom right corner, followed by bottom left, top left
0619      *                 and top right. An empty QString can be used to leave the specific position
0620      *                 blank.
0621      * @param pixmap to draw on
0622      * @since 4.7
0623      */
0624     void drawOverlays(const QStringList &overlays, QPixmap &pixmap, KIconLoader::Group group, int state = KIconLoader::DefaultState) const;
0625 
0626     bool hasIcon(const QString &iconName) const;
0627 
0628     /**
0629      * Sets the colors for this KIconLoader.
0630      * NOTE: if you set a custom palette, if you are using some colors from
0631      * application's palette, you need to track the application palette changes by yourself.
0632      * If you no longer wish to use a custom palette, use resetPalette()
0633      * @see resetPalette
0634      * @since 5.39
0635      */
0636     void setCustomPalette(const QPalette &palette);
0637 
0638     /**
0639      * The colors that will be used for the svg stylesheet in case the
0640      * loaded icons are svg-based, icons can be colored in different ways in
0641      * different areas of the application
0642      * @return the palette, if any, an invalid one if the user didn't set it
0643      * @since 5.39
0644      */
0645     QPalette customPalette() const;
0646 
0647     /**
0648      * Resets the custom palette used by the KIconLoader to use the
0649      * QGuiApplication::palette() again (and to follow it in case the
0650      * application's palette changes)
0651      * @since 5.39
0652      */
0653     void resetPalette();
0654 
0655     /**
0656      * @returns whether we have set a custom palette using @f setCustomPalette
0657      *
0658      * @since 5.85
0659      * @see resetPalette, setCustomPalette
0660      */
0661     bool hasCustomPalette() const;
0662 
0663 public Q_SLOTS:
0664     // TODO: while marked as deprecated, newIconLoader() is still used:
0665     // internally by KIconLoadeer as well as by Plasma's Icons kcm module (state: 5.17)
0666     // this needs some further cleanup work before removing it from the API with KICONTHEMES_ENABLE_DEPRECATED_SINCE
0667     /**
0668      * Re-initialize the global icon loader
0669      *
0670      * @todo Check deprecation, still used internally.
0671      * @deprecated Since 5.0, use emitChange(Group)
0672      */
0673     KICONTHEMES_DEPRECATED_VERSION(5, 0, "Use KIconLoader::emitChange(Group)")
0674     void newIconLoader();
0675 
0676     /**
0677      * Emits an iconChanged() signal on all the KIconLoader instances in the system
0678      * indicating that a system's icon group has changed in some way. It will also trigger
0679      * a reload in all of them to update to the new theme.
0680      *
0681      * @p group indicates the group that has changed
0682      *
0683      * @since 5.0
0684      */
0685     static void emitChange(Group group);
0686 
0687 Q_SIGNALS:
0688     /**
0689      * Emitted by newIconLoader once the new settings have been loaded
0690      */
0691     void iconLoaderSettingsChanged();
0692 
0693     /**
0694      * Emitted when the system icon theme changes
0695      *
0696      * @since 5.0
0697      */
0698     void iconChanged(int group);
0699 
0700 private:
0701     friend class KIconLoaderPrivate;
0702     // @internal the data object
0703     std::unique_ptr<KIconLoaderPrivate> const d;
0704 
0705     Q_PRIVATE_SLOT(d, void _k_refreshIcons(int group))
0706 };
0707 
0708 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 63)
0709 /**
0710  * \relates KIconLoader
0711  * Load a desktop icon.
0712  * @deprecated since 5.63. Prefer QIcon::fromTheme instead where possible,
0713  * if you need a pixmap use QIcon::pixmap with KIconLoader::StdSizes,
0714  * if you need the overlay, use KIconLoader::loadIcon.
0715  */
0716 KICONTHEMES_EXPORT
0717 KICONTHEMES_DEPRECATED_VERSION(5, 63, "See API dox for replacement")
0718 QPixmap DesktopIcon(const QString &name, int size = 0, int state = KIconLoader::DefaultState, const QStringList &overlays = QStringList());
0719 #endif
0720 
0721 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 0)
0722 /**
0723  * \relates KIconLoader
0724  * Load a desktop icon, and apply the necessary effects to get an IconSet.
0725  * @deprecated Since 5.0, use QIcon::fromTheme instead
0726  */
0727 KICONTHEMES_EXPORT
0728 KICONTHEMES_DEPRECATED_VERSION(5, 0, "Use QIcon::fromTheme(const QString&)")
0729 QIcon DesktopIconSet(const QString &name, int size = 0);
0730 #endif
0731 
0732 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 63)
0733 /**
0734  * \relates KIconLoader
0735  * Load a toolbar icon.
0736  * @deprecated since 5.63. Prefer QIcon::fromTheme instead where possible,
0737  * if you need a pixmap use QIcon::pixmap with KIconLoader::StdSizes,
0738  * if you need the overlay, use KIconLoader::loadIcon.
0739  */
0740 KICONTHEMES_EXPORT
0741 KICONTHEMES_DEPRECATED_VERSION(5, 63, "See API dox for replacement")
0742 QPixmap BarIcon(const QString &name, int size = 0, int state = KIconLoader::DefaultState, const QStringList &overlays = QStringList());
0743 #endif
0744 
0745 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 0)
0746 /**
0747  * \relates KIconLoader
0748  * Load a toolbar icon, and apply the necessary effects to get an IconSet.
0749  * @deprecated Since 5.0, use QIcon::fromTheme instead
0750  */
0751 KICONTHEMES_EXPORT
0752 KICONTHEMES_DEPRECATED_VERSION(5, 0, "Use QIcon::fromTheme(const QString&)")
0753 QIcon BarIconSet(const QString &name, int size = 0);
0754 #endif
0755 
0756 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 63)
0757 /**
0758  * \relates KIconLoader
0759  * Load a small icon.
0760  * @deprecated since 5.63. Prefer QIcon::fromTheme instead where possible,
0761  * if you need a pixmap use QIcon::pixmap with KIconLoader::StdSizes,
0762  * if you need the overlay, use KIconLoader::loadIcon.
0763  */
0764 KICONTHEMES_EXPORT
0765 KICONTHEMES_DEPRECATED_VERSION(5, 63, "See API dox for replacement")
0766 QPixmap SmallIcon(const QString &name, int size = 0, int state = KIconLoader::DefaultState, const QStringList &overlays = QStringList());
0767 #endif
0768 
0769 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 0)
0770 /**
0771  * \relates KIconLoader
0772  * Load a small icon, and apply the necessary effects to get an IconSet.
0773  * @deprecated Since 5.0, use QIcon::fromTheme instead
0774  */
0775 KICONTHEMES_EXPORT
0776 KICONTHEMES_DEPRECATED_VERSION(5, 0, "Use QIcon::fromTheme(const QString&)")
0777 QIcon SmallIconSet(const QString &name, int size = 0);
0778 #endif
0779 
0780 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 63)
0781 /**
0782  * \relates KIconLoader
0783  * Load a main toolbar icon.
0784  * @deprecated since 5.63. Prefer QIcon::fromTheme instead where possible,
0785  * if you need a pixmap use QIcon::pixmap with KIconLoader::StdSizes,
0786  * if you need the overlay, use KIconLoader::loadIcon.
0787  */
0788 KICONTHEMES_EXPORT
0789 KICONTHEMES_DEPRECATED_VERSION(5, 63, "See API dox for replacement")
0790 QPixmap MainBarIcon(const QString &name, int size = 0, int state = KIconLoader::DefaultState, const QStringList &overlays = QStringList());
0791 #endif
0792 
0793 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 0)
0794 /**
0795  * \relates KIconLoader
0796  * Load a main toolbar icon, and apply the effects to get an IconSet.
0797  * @deprecated Since 5.0, use QIcon::fromTheme instead
0798  */
0799 KICONTHEMES_EXPORT
0800 KICONTHEMES_DEPRECATED_VERSION(5, 0, "Use QIcon::fromTheme(const QString&)")
0801 QIcon MainBarIconSet(const QString &name, int size = 0);
0802 #endif
0803 
0804 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 65)
0805 /**
0806  * \relates KIconLoader
0807  * Load a user icon. User icons are searched in $appdir/pics.
0808  * @deprecated since 5.65 Prefer qrc files over user icon themes.
0809  * If that's not an option for now, use KIconLoader::loadIcon.
0810  */
0811 KICONTHEMES_EXPORT
0812 KICONTHEMES_DEPRECATED_VERSION(5, 65, "See API dox for replacement")
0813 QPixmap UserIcon(const QString &name, int state = KIconLoader::DefaultState, const QStringList &overlays = QStringList());
0814 #endif
0815 
0816 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 0)
0817 /**
0818  * \relates KIconLoader
0819  * Load a user icon, and apply the effects to get an IconSet.
0820  * @deprecated Since 5.0, use QIcon::fromTheme instead
0821  */
0822 KICONTHEMES_EXPORT
0823 KICONTHEMES_DEPRECATED_VERSION(5, 0, "Use QIcon::fromTheme(const QString&)")
0824 QIcon UserIconSet(const QString &name);
0825 #endif
0826 
0827 #if KICONTHEMES_ENABLE_DEPRECATED_SINCE(5, 66)
0828 /**
0829  * \relates KIconLoader
0830  * Returns the current icon size for a specific group.
0831  * @deprecated since 5.66 Prefer QStyle::pixelMetric.
0832  * If that's not an option for now, use KIconLoader::currentSize.
0833  */
0834 KICONTHEMES_EXPORT
0835 KICONTHEMES_DEPRECATED_VERSION(5, 66, "Use QStyle::pixelMetric or KIconLoader::currentSize")
0836 int IconSize(KIconLoader::Group group);
0837 #endif
0838 
0839 namespace KDE
0840 {
0841 /**
0842  * \relates KIconLoader
0843  * Returns a QIcon with an appropriate
0844  * KIconEngine to perform loading and rendering.  KIcons thus adhere to
0845  * KDE style and effect standards.
0846  * @since 5.0
0847  */
0848 KICONTHEMES_EXPORT QIcon icon(const QString &iconName, KIconLoader *iconLoader = nullptr);
0849 KICONTHEMES_EXPORT QIcon icon(const QString &iconName, const KIconColors &colors, KIconLoader *iconLoader = nullptr);
0850 
0851 /**
0852  * \relates KIconLoader
0853  * Returns a QIcon for the given icon, with additional overlays.
0854  * @since 5.0
0855  */
0856 KICONTHEMES_EXPORT QIcon icon(const QString &iconName, const QStringList &overlays, KIconLoader *iconLoader = nullptr);
0857 
0858 }
0859 
0860 inline KIconLoader::Group &operator++(KIconLoader::Group &group)
0861 {
0862     group = static_cast<KIconLoader::Group>(group + 1);
0863     return group;
0864 }
0865 inline KIconLoader::Group operator++(KIconLoader::Group &group, int)
0866 {
0867     KIconLoader::Group ret = group;
0868     ++group;
0869     return ret;
0870 }
0871 
0872 #endif // KICONLOADER_H