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 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | |
15 | class QIconPrivate; |
16 | class QIconEngine; |
17 | class QPainter; |
18 | |
19 | class Q_GUI_EXPORT QIcon |
20 | { |
21 | public: |
22 | enum Mode { Normal, Disabled, Active, Selected }; |
23 | enum State { On, Off }; |
24 | |
25 | enum class ThemeIcon { |
26 | AddressBookNew, |
27 | ApplicationExit, |
28 | AppointmentNew, |
29 | CallStart, |
30 | CallStop, |
31 | ContactNew, |
32 | DocumentNew, |
33 | DocumentOpen, |
34 | DocumentOpenRecent, |
35 | DocumentPageSetup, |
36 | DocumentPrint, |
37 | DocumentPrintPreview, |
38 | DocumentProperties, |
39 | DocumentRevert, |
40 | DocumentSave, |
41 | DocumentSaveAs, |
42 | DocumentSend, |
43 | EditClear, |
44 | EditCopy, |
45 | EditCut, |
46 | EditDelete, |
47 | EditFind, |
48 | EditPaste, |
49 | EditRedo, |
50 | EditSelectAll, |
51 | EditUndo, |
52 | FolderNew, |
53 | FormatIndentLess, |
54 | FormatIndentMore, |
55 | FormatJustifyCenter, |
56 | FormatJustifyFill, |
57 | FormatJustifyLeft, |
58 | FormatJustifyRight, |
59 | FormatTextDirectionLtr, |
60 | FormatTextDirectionRtl, |
61 | FormatTextBold, |
62 | FormatTextItalic, |
63 | FormatTextUnderline, |
64 | FormatTextStrikethrough, |
65 | GoDown, |
66 | GoHome, |
67 | GoNext, |
68 | GoPrevious, |
69 | GoUp, |
70 | HelpAbout, |
71 | HelpFaq, |
72 | InsertImage, |
73 | InsertLink, |
74 | InsertText, |
75 | ListAdd, |
76 | ListRemove, |
77 | MailForward, |
78 | MailMarkImportant, |
79 | MailMarkRead, |
80 | MailMarkUnread, |
81 | MailMessageNew, |
82 | MailReplyAll, |
83 | MailReplySender, |
84 | MailSend, |
85 | MediaEject, |
86 | MediaPlaybackPause, |
87 | MediaPlaybackStart, |
88 | MediaPlaybackStop, |
89 | MediaRecord, |
90 | MediaSeekBackward, |
91 | MediaSeekForward, |
92 | MediaSkipBackward, |
93 | MediaSkipForward, |
94 | ObjectRotateLeft, |
95 | ObjectRotateRight, |
96 | ProcessStop, |
97 | SystemLockScreen, |
98 | SystemLogOut, |
99 | SystemSearch, |
100 | SystemReboot, |
101 | SystemShutdown, |
102 | ToolsCheckSpelling, |
103 | ViewFullscreen, |
104 | ViewRefresh, |
105 | ViewRestore, |
106 | WindowClose, |
107 | WindowNew, |
108 | ZoomFitBest, |
109 | ZoomIn, |
110 | ZoomOut, |
111 | |
112 | AudioCard, |
113 | AudioInputMicrophone, |
114 | Battery, |
115 | CameraPhoto, |
116 | CameraVideo, |
117 | CameraWeb, |
118 | Computer, |
119 | DriveHarddisk, |
120 | DriveOptical, |
121 | InputGaming, |
122 | InputKeyboard, |
123 | InputMouse, |
124 | InputTablet, |
125 | MediaFlash, |
126 | MediaOptical, |
127 | MediaTape, |
128 | MultimediaPlayer, |
129 | NetworkWired, |
130 | NetworkWireless, |
131 | Phone, |
132 | Printer, |
133 | Scanner, |
134 | VideoDisplay, |
135 | |
136 | AppointmentMissed, |
137 | AppointmentSoon, |
138 | AudioVolumeHigh, |
139 | AudioVolumeLow, |
140 | AudioVolumeMedium, |
141 | AudioVolumeMuted, |
142 | BatteryCaution, |
143 | BatteryLow, |
144 | DialogError, |
145 | DialogInformation, |
146 | DialogPassword, |
147 | DialogQuestion, |
148 | DialogWarning, |
149 | FolderDragAccept, |
150 | FolderOpen, |
151 | FolderVisiting, |
152 | ImageLoading, |
153 | ImageMissing, |
154 | MailAttachment, |
155 | MailUnread, |
156 | MailRead, |
157 | MailReplied, |
158 | MediaPlaylistRepeat, |
159 | MediaPlaylistShuffle, |
160 | NetworkOffline, |
161 | PrinterPrinting, |
162 | SecurityHigh, |
163 | SecurityLow, |
164 | SoftwareUpdateAvailable, |
165 | SoftwareUpdateUrgent, |
166 | SyncError, |
167 | SyncSynchronizing, |
168 | UserAvailable, |
169 | UserOffline, |
170 | WeatherClear, |
171 | WeatherClearNight, |
172 | WeatherFewClouds, |
173 | WeatherFewCloudsNight, |
174 | WeatherFog, |
175 | WeatherShowers, |
176 | WeatherSnow, |
177 | WeatherStorm, |
178 | |
179 | NThemeIcons |
180 | }; |
181 | |
182 | QIcon() noexcept; |
183 | QIcon(const QPixmap &pixmap); |
184 | QIcon(const QIcon &other); |
185 | QIcon(QIcon &&other) noexcept |
186 | : d(std::exchange(obj&: other.d, new_val: nullptr)) |
187 | {} |
188 | explicit QIcon(const QString &fileName); // file or resource name |
189 | explicit QIcon(QIconEngine *engine); |
190 | ~QIcon(); |
191 | QIcon &operator=(const QIcon &other); |
192 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QIcon) |
193 | inline void swap(QIcon &other) noexcept |
194 | { qt_ptr_swap(lhs&: d, rhs&: other.d); } |
195 | bool operator==(const QIcon &) const = delete; |
196 | bool operator!=(const QIcon &) const = delete; |
197 | |
198 | operator QVariant() const; |
199 | |
200 | QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const; |
201 | inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const |
202 | { return pixmap(size: QSize(w, h), mode, state); } |
203 | inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const |
204 | { return pixmap(size: QSize(extent, extent), mode, state); } |
205 | QPixmap pixmap(const QSize &size, qreal devicePixelRatio, Mode mode = Normal, State state = Off) const; |
206 | #if QT_DEPRECATED_SINCE(6, 0) |
207 | QT_DEPRECATED_VERSION_X_6_0("Use pixmap(size, devicePixelRatio) instead" ) |
208 | QPixmap pixmap(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const; |
209 | #endif |
210 | |
211 | QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const; |
212 | #if QT_DEPRECATED_SINCE(6, 0) |
213 | QT_DEPRECATED_VERSION_X_6_0("Use actualSize(size) instead" ) |
214 | QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const; |
215 | #endif |
216 | |
217 | QString name() const; |
218 | |
219 | void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const; |
220 | 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 |
221 | { paint(painter, rect: QRect(x, y, w, h), alignment, mode, state); } |
222 | |
223 | bool isNull() const; |
224 | bool isDetached() const; |
225 | void detach(); |
226 | |
227 | qint64 cacheKey() const; |
228 | |
229 | void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off); |
230 | void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off); |
231 | |
232 | QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const; |
233 | |
234 | void setIsMask(bool isMask); |
235 | bool isMask() const; |
236 | |
237 | static QIcon fromTheme(const QString &name); |
238 | static QIcon fromTheme(const QString &name, const QIcon &fallback); |
239 | static bool hasThemeIcon(const QString &name); |
240 | |
241 | static QIcon fromTheme(ThemeIcon icon); |
242 | static QIcon fromTheme(ThemeIcon icon, const QIcon &fallback); |
243 | static bool hasThemeIcon(ThemeIcon icon); |
244 | |
245 | static QStringList themeSearchPaths(); |
246 | static void setThemeSearchPaths(const QStringList &searchpath); |
247 | |
248 | static QStringList fallbackSearchPaths(); |
249 | static void setFallbackSearchPaths(const QStringList &paths); |
250 | |
251 | static QString themeName(); |
252 | static void setThemeName(const QString &path); |
253 | |
254 | static QString fallbackThemeName(); |
255 | static void setFallbackThemeName(const QString &name); |
256 | |
257 | private: |
258 | QIconPrivate *d; |
259 | #if !defined(QT_NO_DATASTREAM) |
260 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &); |
261 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &); |
262 | #endif |
263 | |
264 | public: |
265 | typedef QIconPrivate * DataPtr; |
266 | inline DataPtr &data_ptr() { return d; } |
267 | }; |
268 | |
269 | Q_DECLARE_SHARED(QIcon) |
270 | |
271 | #if !defined(QT_NO_DATASTREAM) |
272 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &); |
273 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &); |
274 | #endif |
275 | |
276 | #ifndef QT_NO_DEBUG_STREAM |
277 | Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &); |
278 | #endif |
279 | |
280 | Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio, |
281 | qreal *sourceDevicePixelRatio = nullptr); |
282 | |
283 | QT_END_NAMESPACE |
284 | |
285 | #endif // QICON_H |
286 | |