1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QICON_P_H
5#define QICON_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qtguiglobal_p.h>
19#include <QtCore/qsize.h>
20#include <QtCore/qlist.h>
21#include <QtGui/qpixmap.h>
22#include <QtGui/qicon.h>
23#include <QtGui/qiconengine.h>
24
25#ifndef QT_NO_ICON
26QT_BEGIN_NAMESPACE
27
28class QIconPrivate
29{
30public:
31 explicit QIconPrivate(QIconEngine *e);
32
33 ~QIconPrivate() {
34 delete engine;
35 }
36
37 qreal pixmapDevicePixelRatio(qreal displayDevicePixelRatio, const QSize &requestedSize, const QSize &actualSize);
38
39 QIconEngine *engine;
40
41 QAtomicInt ref;
42 int serialNum;
43 int detach_no;
44 bool is_mask;
45
46 static void clearIconCache();
47};
48
49
50struct QPixmapIconEngineEntry
51{
52 QPixmapIconEngineEntry():scale(1), mode(QIcon::Normal), state(QIcon::Off){}
53 QPixmapIconEngineEntry(const QPixmap &pm, QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
54 :pixmap(pm), size(pm.size()), scale(pm.devicePixelRatio()), mode(m), state(s){}
55 QPixmapIconEngineEntry(const QString &file, const QSize &sz = QSize(), QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off)
56 :fileName(file), size(sz), scale(1), mode(m), state(s){}
57 QPixmapIconEngineEntry(const QString &file, const QImage &image, QIcon::Mode m = QIcon::Normal, QIcon::State s = QIcon::Off);
58 QPixmap pixmap;
59 QString fileName;
60 QSize size;
61 qreal scale;
62 QIcon::Mode mode;
63 QIcon::State state;
64 bool isNull() const {return (fileName.isEmpty() && pixmap.isNull()); }
65};
66Q_DECLARE_TYPEINFO(QPixmapIconEngineEntry, Q_RELOCATABLE_TYPE);
67
68inline QPixmapIconEngineEntry::QPixmapIconEngineEntry(const QString &file, const QImage &image, QIcon::Mode m, QIcon::State s)
69 : fileName(file), size(image.size()), scale(image.devicePixelRatio()), mode(m), state(s)
70{
71 pixmap.convertFromImage(img: image);
72}
73
74class Q_GUI_EXPORT QPixmapIconEngine : public QIconEngine {
75public:
76 QPixmapIconEngine();
77 QPixmapIconEngine(const QPixmapIconEngine &);
78 ~QPixmapIconEngine();
79 void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
80 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
81 QPixmap scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale) override;
82 QPixmapIconEngineEntry *bestMatch(const QSize &size, qreal scale, QIcon::Mode mode, QIcon::State state, bool sizeOnly);
83 QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
84 QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state) override;
85 void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state) override;
86 void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state) override;
87
88
89 QString key() const override;
90 QIconEngine *clone() const override;
91 bool read(QDataStream &in) override;
92 bool write(QDataStream &out) const override;
93
94private:
95 QPixmapIconEngineEntry *tryMatch(const QSize &size, qreal scale, QIcon::Mode mode, QIcon::State state);
96 QList<QPixmapIconEngineEntry> pixmaps;
97
98 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QIcon &icon);
99 friend class QIconThemeEngine;
100};
101
102QT_END_NAMESPACE
103#endif //QT_NO_ICON
104#endif // QICON_P_H
105

source code of qtbase/src/gui/image/qicon_p.h