File indexing completed on 2024-05-19 07:43:36

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #ifndef KICONENGINE_H
0009 #define KICONENGINE_H
0010 
0011 #include "kiconthemes_export.h"
0012 #include <QIconEngine>
0013 #include <QPointer>
0014 
0015 class KIconColors;
0016 class KIconLoader;
0017 class KIconEnginePrivate;
0018 
0019 /**
0020  * @class KIconEngine kiconengine.h KIconEngine
0021  *
0022  * \short A class to provide rendering of KDE icons.
0023  *
0024  * Currently, this class is not much more than a wrapper around QIconEngine.
0025  * However, it should not be difficult to extend with features such as SVG
0026  * rendered icons.
0027  *
0028  * Icon themes specifying a KDE-Extensions string list setting, will limit
0029  * themselves to checking these extensions exclusively, in the order specified
0030  * in the setting.
0031  *
0032  * @author Hamish Rodda <rodda@kde.org>
0033  */
0034 class KICONTHEMES_EXPORT KIconEngine : public QIconEngine // exported for kdelibs4support's KIcon and plasma integration
0035 {
0036 public:
0037     /**
0038      * Constructs an icon engine for a KDE named icon.
0039      *
0040      * @param iconName the name of the icon to load
0041      * @param iconLoader The KDE icon loader that this engine is to use.
0042      * @param overlays Add one or more overlays to the icon. See KIconLoader::Overlays.
0043      *
0044      * @sa KIconLoader
0045      */
0046     KIconEngine(const QString &iconName, KIconLoader *iconLoader, const QStringList &overlays);
0047 
0048     /**
0049      * \overload
0050      */
0051     KIconEngine(const QString &iconName, KIconLoader *iconLoader);
0052 
0053     /**
0054      * Constructs an icon engine for a KDE named icon with a specific palette.
0055      *
0056      * @param iconName the name of the icon to load
0057      * @param colors defines the colors we want to be applied on this icon
0058      * @param iconLoader The KDE icon loader that this engine is to use.
0059      */
0060     KIconEngine(const QString &iconName, const KIconColors &colors, KIconLoader *iconLoader);
0061 
0062     /**
0063      * Destructor.
0064      */
0065     ~KIconEngine() override;
0066 
0067     /// Reimplementation
0068     QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
0069     /// Reimplementation
0070     void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
0071     /// Reimplementation
0072     QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
0073     QPixmap scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale) override;
0074 
0075     /// Reimplementation
0076     QString iconName() override;
0077     /// Reimplementation
0078     QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state) override;
0079 
0080     bool isNull() override;
0081 
0082     QString key() const override;
0083     QIconEngine *clone() const override;
0084     bool read(QDataStream &in) override;
0085     bool write(QDataStream &out) const override;
0086 
0087 private:
0088     // TODO KF6: move those into the d-pointer
0089     QPixmap createPixmap(const QSize &size, qreal scale, QIcon::Mode mode, QIcon::State state);
0090     QString mIconName;
0091     QStringList mOverlays;
0092     KIconEnginePrivate *const d;
0093 };
0094 
0095 #endif