File indexing completed on 2026-10-05 09:28:14
0001
0002
0003
0004 #ifndef QICON_H
0005 #define QICON_H
0006
0007 #include <QtGui/qtguiglobal.h>
0008 #include <QtCore/qsize.h>
0009 #include <QtCore/qlist.h>
0010 #include <QtGui/qpixmap.h>
0011
0012 QT_BEGIN_NAMESPACE
0013
0014
0015 class QIconPrivate;
0016 class QIconEngine;
0017 class QPainter;
0018
0019 class Q_GUI_EXPORT QIcon
0020 {
0021 Q_GADGET
0022 Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
0023 public:
0024 enum Mode { Normal, Disabled, Active, Selected };
0025 Q_ENUM(Mode);
0026 enum State { On, Off };
0027 Q_ENUM(State);
0028
0029 enum class ThemeIcon {
0030 AddressBookNew,
0031 ApplicationExit,
0032 AppointmentNew,
0033 CallStart,
0034 CallStop,
0035 ContactNew,
0036 DocumentNew,
0037 DocumentOpen,
0038 DocumentOpenRecent,
0039 DocumentPageSetup,
0040 DocumentPrint,
0041 DocumentPrintPreview,
0042 DocumentProperties,
0043 DocumentRevert,
0044 DocumentSave,
0045 DocumentSaveAs,
0046 DocumentSend,
0047 EditClear,
0048 EditCopy,
0049 EditCut,
0050 EditDelete,
0051 EditFind,
0052 EditPaste,
0053 EditRedo,
0054 EditSelectAll,
0055 EditUndo,
0056 FolderNew,
0057 FormatIndentLess,
0058 FormatIndentMore,
0059 FormatJustifyCenter,
0060 FormatJustifyFill,
0061 FormatJustifyLeft,
0062 FormatJustifyRight,
0063 FormatTextDirectionLtr,
0064 FormatTextDirectionRtl,
0065 FormatTextBold,
0066 FormatTextItalic,
0067 FormatTextUnderline,
0068 FormatTextStrikethrough,
0069 GoDown,
0070 GoHome,
0071 GoNext,
0072 GoPrevious,
0073 GoUp,
0074 HelpAbout,
0075 HelpFaq,
0076 InsertImage,
0077 InsertLink,
0078 InsertText,
0079 ListAdd,
0080 ListRemove,
0081 MailForward,
0082 MailMarkImportant,
0083 MailMarkRead,
0084 MailMarkUnread,
0085 MailMessageNew,
0086 MailReplyAll,
0087 MailReplySender,
0088 MailSend,
0089 MediaEject,
0090 MediaPlaybackPause,
0091 MediaPlaybackStart,
0092 MediaPlaybackStop,
0093 MediaRecord,
0094 MediaSeekBackward,
0095 MediaSeekForward,
0096 MediaSkipBackward,
0097 MediaSkipForward,
0098 ObjectRotateLeft,
0099 ObjectRotateRight,
0100 ProcessStop,
0101 SystemLockScreen,
0102 SystemLogOut,
0103 SystemSearch,
0104 SystemReboot,
0105 SystemShutdown,
0106 ToolsCheckSpelling,
0107 ViewFullscreen,
0108 ViewRefresh,
0109 ViewRestore,
0110 WindowClose,
0111 WindowNew,
0112 ZoomFitBest,
0113 ZoomIn,
0114 ZoomOut,
0115
0116 AudioCard,
0117 AudioInputMicrophone,
0118 Battery,
0119 CameraPhoto,
0120 CameraVideo,
0121 CameraWeb,
0122 Computer,
0123 DriveHarddisk,
0124 DriveOptical,
0125 InputGaming,
0126 InputKeyboard,
0127 InputMouse,
0128 InputTablet,
0129 MediaFlash,
0130 MediaOptical,
0131 MediaTape,
0132 MultimediaPlayer,
0133 NetworkWired,
0134 NetworkWireless,
0135 Phone,
0136 Printer,
0137 Scanner,
0138 VideoDisplay,
0139
0140 AppointmentMissed,
0141 AppointmentSoon,
0142 AudioVolumeHigh,
0143 AudioVolumeLow,
0144 AudioVolumeMedium,
0145 AudioVolumeMuted,
0146 BatteryCaution,
0147 BatteryLow,
0148 DialogError,
0149 DialogInformation,
0150 DialogPassword,
0151 DialogQuestion,
0152 DialogWarning,
0153 FolderDragAccept,
0154 FolderOpen,
0155 FolderVisiting,
0156 ImageLoading,
0157 ImageMissing,
0158 MailAttachment,
0159 MailUnread,
0160 MailRead,
0161 MailReplied,
0162 MediaPlaylistRepeat,
0163 MediaPlaylistShuffle,
0164 NetworkOffline,
0165 PrinterPrinting,
0166 SecurityHigh,
0167 SecurityLow,
0168 SoftwareUpdateAvailable,
0169 SoftwareUpdateUrgent,
0170 SyncError,
0171 SyncSynchronizing,
0172 UserAvailable,
0173 UserOffline,
0174 WeatherClear,
0175 WeatherClearNight,
0176 WeatherFewClouds,
0177 WeatherFewCloudsNight,
0178 WeatherFog,
0179 WeatherShowers,
0180 WeatherSnow,
0181 WeatherStorm,
0182
0183 NThemeIcons
0184 };
0185 Q_ENUM(ThemeIcon);
0186
0187 QIcon() noexcept;
0188 QIcon(const QPixmap &pixmap);
0189 QIcon(const QIcon &other);
0190 QIcon(QIcon &&other) noexcept
0191 : d(std::exchange(other.d, nullptr))
0192 {}
0193 explicit QIcon(const QString &fileName);
0194 explicit QIcon(QIconEngine *engine);
0195 ~QIcon();
0196 QIcon &operator=(const QIcon &other);
0197 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QIcon)
0198 inline void swap(QIcon &other) noexcept
0199 { qt_ptr_swap(d, other.d); }
0200 bool operator==(const QIcon &) const = delete;
0201 bool operator!=(const QIcon &) const = delete;
0202
0203 operator QVariant() const;
0204
0205 QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;
0206 inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const
0207 { return pixmap(QSize(w, h), mode, state); }
0208 inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const
0209 { return pixmap(QSize(extent, extent), mode, state); }
0210 QPixmap pixmap(const QSize &size, qreal devicePixelRatio, Mode mode = Normal, State state = Off) const;
0211 #if QT_DEPRECATED_SINCE(6, 0)
0212 QT_DEPRECATED_VERSION_X_6_0("Use pixmap(size, devicePixelRatio) instead")
0213 QPixmap pixmap(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
0214 #endif
0215
0216 QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const;
0217 #if QT_DEPRECATED_SINCE(6, 0)
0218 QT_DEPRECATED_VERSION_X_6_0("Use actualSize(size) instead")
0219 QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
0220 #endif
0221
0222 QString name() const;
0223
0224 void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const;
0225 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
0226 { paint(painter, QRect(x, y, w, h), alignment, mode, state); }
0227
0228 bool isNull() const;
0229 bool isDetached() const;
0230 void detach();
0231
0232 qint64 cacheKey() const;
0233
0234 void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off);
0235 void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off);
0236
0237 QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
0238
0239 void setIsMask(bool isMask);
0240 bool isMask() const;
0241
0242 static QIcon fromTheme(const QString &name);
0243 static QIcon fromTheme(const QString &name, const QIcon &fallback);
0244 static bool hasThemeIcon(const QString &name);
0245
0246 static QIcon fromTheme(ThemeIcon icon);
0247 static QIcon fromTheme(ThemeIcon icon, const QIcon &fallback);
0248 static bool hasThemeIcon(ThemeIcon icon);
0249
0250 static QStringList themeSearchPaths();
0251 static void setThemeSearchPaths(const QStringList &searchpath);
0252
0253 static QStringList fallbackSearchPaths();
0254 static void setFallbackSearchPaths(const QStringList &paths);
0255
0256 static QString themeName();
0257 static void setThemeName(const QString &path);
0258
0259 static QString fallbackThemeName();
0260 static void setFallbackThemeName(const QString &name);
0261
0262 private:
0263 QIconPrivate *d;
0264 #if !defined(QT_NO_DATASTREAM)
0265 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
0266 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
0267 #endif
0268
0269 friend class QIconPrivate;
0270
0271 public:
0272 typedef QIconPrivate * DataPtr;
0273 inline DataPtr &data_ptr() { return d; }
0274 };
0275
0276 Q_DECLARE_SHARED(QIcon)
0277
0278 #if !defined(QT_NO_DATASTREAM)
0279 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
0280 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
0281 #endif
0282
0283 #ifndef QT_NO_DEBUG_STREAM
0284 Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
0285 #endif
0286
0287 Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
0288 qreal *sourceDevicePixelRatio = nullptr);
0289
0290 QT_END_NAMESPACE
0291
0292 #endif