1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-only |
6 | */ |
7 | |
8 | #ifndef KICONENGINE_H |
9 | #define KICONENGINE_H |
10 | |
11 | #include "kiconthemes_export.h" |
12 | #include <QIconEngine> |
13 | #include <QPointer> |
14 | |
15 | class KIconColors; |
16 | class KIconLoader; |
17 | class KIconEnginePrivate; |
18 | |
19 | /*! |
20 | * \class KIconEngine |
21 | * \inmodule KIconThemes |
22 | * |
23 | * \brief A class to provide rendering of KDE icons. |
24 | * |
25 | * This is mostly used to provide Qt's icon loading in plasma-integration |
26 | * |
27 | * Application developers should use QIcon::fromTheme instead of using it directly. |
28 | */ |
29 | class KICONTHEMES_EXPORT KIconEngine : public QIconEngine // exported for plasma-integration |
30 | { |
31 | public: |
32 | /*! |
33 | * Constructs an icon engine for a named icon. |
34 | * |
35 | * \a iconName the name of the icon to load |
36 | * |
37 | * \a iconLoader The icon loader that this engine is to use. |
38 | * |
39 | * \a overlays Add one or more overlays to the icon. See KIconLoader::Overlays. |
40 | * |
41 | * \sa KIconLoader |
42 | */ |
43 | KIconEngine(const QString &iconName, KIconLoader *iconLoader, const QStringList &overlays); |
44 | |
45 | /*! |
46 | * \overload |
47 | */ |
48 | KIconEngine(const QString &iconName, KIconLoader *iconLoader); |
49 | |
50 | /*! |
51 | * Constructs an icon engine for a KDE named icon with a specific palette. |
52 | * |
53 | * \a iconName the name of the icon to load |
54 | * |
55 | * \a colors defines the colors we want to be applied on this icon |
56 | * |
57 | * \a iconLoader The KDE icon loader that this engine is to use. |
58 | */ |
59 | KIconEngine(const QString &iconName, const KIconColors &colors, KIconLoader *iconLoader); |
60 | |
61 | /*! |
62 | * Constructs an icon engine for a KDE named icon with a specific palette and overlays. |
63 | * |
64 | * \a iconName the name of the icon to load |
65 | * |
66 | * \a colors defines the colors we want to be applied on this icon |
67 | * |
68 | * \a iconLoader The KDE icon loader that this engine is to use. |
69 | * |
70 | * \a overlays Add one or more overlays to the icon. See KIconLoader::Overlays. |
71 | * |
72 | * \since 6.1 |
73 | */ |
74 | KIconEngine(const QString &iconName, const KIconColors &colors, KIconLoader *iconLoader, const QStringList &overlays); |
75 | |
76 | ~KIconEngine() override; |
77 | |
78 | /// Reimplementation |
79 | QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override; |
80 | /// Reimplementation |
81 | void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override; |
82 | /// Reimplementation |
83 | QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; |
84 | QPixmap scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale) override; |
85 | |
86 | /// Reimplementation |
87 | QString iconName() override; |
88 | /// Reimplementation |
89 | QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state) override; |
90 | |
91 | bool isNull() override; |
92 | |
93 | QString key() const override; |
94 | QIconEngine *clone() const override; |
95 | bool read(QDataStream &in) override; |
96 | bool write(QDataStream &out) const override; |
97 | |
98 | private: |
99 | // TODO KF6: move those into the d-pointer |
100 | QPixmap createPixmap(const QSize &size, qreal scale, QIcon::Mode mode, QIcon::State state); |
101 | QString mIconName; |
102 | QStringList mOverlays; |
103 | KIconEnginePrivate *const d; |
104 | }; |
105 | |
106 | #endif |
107 | |