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_H
5#define QICON_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qsize.h>
9#include <QtCore/qlist.h>
10#include <QtGui/qpixmap.h>
11
12QT_BEGIN_NAMESPACE
13
14
15class QIconPrivate;
16class QIconEngine;
17class QPainter;
18
19class Q_GUI_EXPORT QIcon
20{
21public:
22 enum Mode { Normal, Disabled, Active, Selected };
23 enum State { On, Off };
24
25 QIcon() noexcept;
26 QIcon(const QPixmap &pixmap);
27 QIcon(const QIcon &other);
28 QIcon(QIcon &&other) noexcept
29 : d(std::exchange(obj&: other.d, new_val: nullptr))
30 {}
31 explicit QIcon(const QString &fileName); // file or resource name
32 explicit QIcon(QIconEngine *engine);
33 ~QIcon();
34 QIcon &operator=(const QIcon &other);
35 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QIcon)
36 inline void swap(QIcon &other) noexcept
37 { qt_ptr_swap(lhs&: d, rhs&: other.d); }
38 bool operator==(const QIcon &) const = delete;
39 bool operator!=(const QIcon &) const = delete;
40
41 operator QVariant() const;
42
43 QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;
44 inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const
45 { return pixmap(size: QSize(w, h), mode, state); }
46 inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const
47 { return pixmap(size: QSize(extent, extent), mode, state); }
48 QPixmap pixmap(const QSize &size, qreal devicePixelRatio, Mode mode = Normal, State state = Off) const;
49#if QT_DEPRECATED_SINCE(6, 0)
50 QT_DEPRECATED_VERSION_X_6_0("Use pixmap(size, devicePixelRatio) instead")
51 QPixmap pixmap(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
52#endif
53
54 QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const;
55#if QT_DEPRECATED_SINCE(6, 0)
56 QT_DEPRECATED_VERSION_X_6_0("Use actualSize(size) instead")
57 QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
58#endif
59
60 QString name() const;
61
62 void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const;
63 inline void paint(QPainter *painter, int x, int y, int w, int h, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const
64 { paint(painter, rect: QRect(x, y, w, h), alignment, mode, state); }
65
66 bool isNull() const;
67 bool isDetached() const;
68 void detach();
69
70 qint64 cacheKey() const;
71
72 void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off);
73 void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off);
74
75 QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
76
77 void setIsMask(bool isMask);
78 bool isMask() const;
79
80 static QIcon fromTheme(const QString &name);
81 static QIcon fromTheme(const QString &name, const QIcon &fallback);
82 static bool hasThemeIcon(const QString &name);
83
84 static QStringList themeSearchPaths();
85 static void setThemeSearchPaths(const QStringList &searchpath);
86
87 static QStringList fallbackSearchPaths();
88 static void setFallbackSearchPaths(const QStringList &paths);
89
90 static QString themeName();
91 static void setThemeName(const QString &path);
92
93 static QString fallbackThemeName();
94 static void setFallbackThemeName(const QString &name);
95
96private:
97 QIconPrivate *d;
98#if !defined(QT_NO_DATASTREAM)
99 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
100 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
101#endif
102
103public:
104 typedef QIconPrivate * DataPtr;
105 inline DataPtr &data_ptr() { return d; }
106};
107
108Q_DECLARE_SHARED(QIcon)
109
110#if !defined(QT_NO_DATASTREAM)
111Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
112Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
113#endif
114
115#ifndef QT_NO_DEBUG_STREAM
116Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
117#endif
118
119Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
120 qreal *sourceDevicePixelRatio = nullptr);
121
122QT_END_NAMESPACE
123
124#endif // QICON_H
125

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