1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QICON_H |
41 | #define QICON_H |
42 | |
43 | #include <QtGui/qtguiglobal.h> |
44 | #include <QtCore/qsize.h> |
45 | #include <QtCore/qlist.h> |
46 | #include <QtGui/qpixmap.h> |
47 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | |
51 | class QIconPrivate; |
52 | class QIconEngine; |
53 | class QPainter; |
54 | |
55 | class Q_GUI_EXPORT QIcon |
56 | { |
57 | public: |
58 | enum Mode { Normal, Disabled, Active, Selected }; |
59 | enum State { On, Off }; |
60 | |
61 | QIcon() noexcept; |
62 | QIcon(const QPixmap &pixmap); |
63 | QIcon(const QIcon &other); |
64 | QIcon(QIcon &&other) noexcept |
65 | : d(qExchange(other.d, nullptr)) |
66 | {} |
67 | explicit QIcon(const QString &fileName); // file or resource name |
68 | explicit QIcon(QIconEngine *engine); |
69 | ~QIcon(); |
70 | QIcon &operator=(const QIcon &other); |
71 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QIcon) |
72 | inline void swap(QIcon &other) noexcept |
73 | { qSwap(d, other.d); } |
74 | bool operator==(const QIcon &) const = delete; |
75 | bool operator!=(const QIcon &) const = delete; |
76 | |
77 | operator QVariant() const; |
78 | |
79 | QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const; |
80 | inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const |
81 | { return pixmap(QSize(w, h), mode, state); } |
82 | inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const |
83 | { return pixmap(QSize(extent, extent), mode, state); } |
84 | QPixmap pixmap(const QSize &size, qreal devicePixelRatio, Mode mode = Normal, State state = Off) const; |
85 | #if QT_DEPRECATED_SINCE(6, 0) |
86 | QT_DEPRECATED_VERSION_X_6_0("Use pixmap(size, devicePixelRatio) instead" ) |
87 | QPixmap pixmap(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const; |
88 | #endif |
89 | |
90 | QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const; |
91 | #if QT_DEPRECATED_SINCE(6, 0) |
92 | QT_DEPRECATED_VERSION_X_6_0("Use actualSize(size) instead" ) |
93 | QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const; |
94 | #endif |
95 | |
96 | QString name() const; |
97 | |
98 | void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const; |
99 | 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 |
100 | { paint(painter, QRect(x, y, w, h), alignment, mode, state); } |
101 | |
102 | bool isNull() const; |
103 | bool isDetached() const; |
104 | void detach(); |
105 | |
106 | qint64 cacheKey() const; |
107 | |
108 | void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off); |
109 | void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off); |
110 | |
111 | QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const; |
112 | |
113 | void setIsMask(bool isMask); |
114 | bool isMask() const; |
115 | |
116 | static QIcon fromTheme(const QString &name); |
117 | static QIcon fromTheme(const QString &name, const QIcon &fallback); |
118 | static bool hasThemeIcon(const QString &name); |
119 | |
120 | static QStringList themeSearchPaths(); |
121 | static void setThemeSearchPaths(const QStringList &searchpath); |
122 | |
123 | static QStringList fallbackSearchPaths(); |
124 | static void setFallbackSearchPaths(const QStringList &paths); |
125 | |
126 | static QString themeName(); |
127 | static void setThemeName(const QString &path); |
128 | |
129 | static QString fallbackThemeName(); |
130 | static void setFallbackThemeName(const QString &name); |
131 | |
132 | Q_DUMMY_COMPARISON_OPERATOR(QIcon) |
133 | |
134 | private: |
135 | QIconPrivate *d; |
136 | #if !defined(QT_NO_DATASTREAM) |
137 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &); |
138 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &); |
139 | #endif |
140 | |
141 | public: |
142 | typedef QIconPrivate * DataPtr; |
143 | inline DataPtr &data_ptr() { return d; } |
144 | }; |
145 | |
146 | Q_DECLARE_SHARED(QIcon) |
147 | |
148 | #if !defined(QT_NO_DATASTREAM) |
149 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &); |
150 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &); |
151 | #endif |
152 | |
153 | #ifndef QT_NO_DEBUG_STREAM |
154 | Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &); |
155 | #endif |
156 | |
157 | Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio, |
158 | qreal *sourceDevicePixelRatio = nullptr); |
159 | |
160 | QT_END_NAMESPACE |
161 | |
162 | #endif // QICON_H |
163 | |