10#include "private/qfactoryloader_p.h"
11#include "private/qiconloader_p.h"
14#if QT_CONFIG(mimetype)
26#include "private/qhexstring_p.h"
27#include "private/qguiapplication_p.h"
28#include "private/qoffsetstringarray_p.h"
29#include "qpa/qplatformtheme.h"
72 return 1 + serial.fetchAndAddRelaxed(1);
77 struct IconCache :
public QCache<QString, QIcon>
91 qtIconCache()->clear();
120 QSize targetSize = requestedSize * displayDevicePixelRatio;
124 return displayDevicePixelRatio;
147 qreal dpr = paintDevice ? paintDevice->devicePixelRatio() :
qApp->devicePixelRatio();
153static inline int area(
const QSize &
s) {
return s.width() *
s.height(); }
163 const auto scaleA = pa->pixmap.devicePixelRatio();
166 if (scaleA != scaleB) {
175 if ((ascore < 0) != (bscore < 0))
176 return bscore < 0 ? pa : pb;
178 return (
qAbs(ascore) <
qAbs(bscore)) ? pa : pb;
183 pa->pixmap =
QPixmap(pa->fileName);
184 pa->size = pa->pixmap.size();
186 int a =
area(pa->size);
205 for (
auto &
entry : pixmaps) {
236 if ((pe = tryMatch(
size,
scale, oppositeMode, oppositeState)))
244 if ((pe = tryMatch(
size,
scale, oppositeMode, oppositeState)))
260 if (sizeOnly ? (pe->size.isNull() || !pe->size.isValid()) : pe->
pixmap.
isNull()) {
262 if (!pe->pixmap.isNull())
263 pe->size = pe->pixmap.size();
283 auto idx = pixmaps.
size();
285 if (pe == &pixmaps.
at(idx)) {
358 if (pe.mode !=
mode || pe.state !=
state)
360 if (pe.size.isEmpty() && pe.pixmap.isNull()) {
361 pe.pixmap =
QPixmap(pe.fileName);
362 pe.size = pe.pixmap.size();
364 if (!pe.size.isEmpty() && !
sizes.contains(pe.size))
365 sizes.push_back(pe.size);
374 if (pe && pe->size ==
pixmap.size() && pe->pixmap.devicePixelRatio() ==
pixmap.devicePixelRatio()) {
376 pe->fileName.clear();
387 return s.isEmpty() ? 32 :
s.toInt();
412 *
image = m_reader.read();
413 if (!
image->size().isValid()) {
417 m_atEnd = !m_reader.jumpToNextImage();
432 const bool ignoreSize = !
size.isValid();
433 ImageReader imageReader(abs);
440 while (imageReader.read(&
image))
454 QList<QImage> icoImages;
455 while (imageReader.read(&
image)) {
456 if (ignoreSize ||
image.size() ==
size) {
462 icoImages.append(
image);
466 for (
const QImage &
i : std::as_const(icoImages))
468 if (icoImages.isEmpty() && !ignoreSize)
479 return "QPixmapIconEngine"_L1;
497 for (
int i=0;
i < num_entries; ++
i) {
520 int num_entries = pixmaps.
size();
522 for (
int i=0;
i < num_entries; ++
i) {
877 if (devicePixelRatio == -1)
878 devicePixelRatio =
qApp->devicePixelRatio();
881 if (!(devicePixelRatio > 1.0)) {
883 pixmap.setDevicePixelRatio(1.0);
893#if QT_DEPRECATED_SINCE(6, 0)
931 const qreal devicePixelRatio =
qApp->devicePixelRatio();
934 if (!(devicePixelRatio > 1.0))
941#if QT_DEPRECATED_SINCE(6, 0)
963 if (!(devicePixelRatio > 1.0))
987 int w =
size.width();
988 int h =
size.height();
990 y +=
rect.size().height()/2 -
h/2;
992 y +=
rect.size().height() -
h;
994 x +=
rect.size().width() -
w;
996 x +=
rect.size().width()/2 -
w/2;
1073 const int index = iceLoader()->indexOf(suffix);
1122#if QT_CONFIG(mimetype)
1147 return QList<QSize>();
1347 if (
QIcon *cachedIcon = qtIconCache()->
object(
name))
1417 "document-open-recent",
1418 "document-page-setup",
1420 "document-print-preview",
1421 "document-properties",
1436 "format-indent-less",
1437 "format-indent-more",
1438 "format-justify-center",
1439 "format-justify-fill",
1440 "format-justify-left",
1441 "format-justify-right",
1442 "format-text-direction-ltr",
1443 "format-text-direction-rtl",
1445 "format-text-italic",
1446 "format-text-underline",
1447 "format-text-strikethrough",
1461 "mail-mark-important",
1466 "mail-reply-sender",
1469 "media-playback-pause",
1470 "media-playback-start",
1471 "media-playback-stop",
1473 "media-seek-backward",
1474 "media-seek-forward",
1475 "media-skip-backward",
1476 "media-skip-forward",
1477 "object-rotate-left",
1478 "object-rotate-right",
1480 "system-lock-screen",
1485 "tools-check-spelling",
1496 "audio-input-microphone",
1511 "multimedia-player",
1519 "appointment-missed",
1521 "audio-volume-high",
1523 "audio-volume-medium",
1524 "audio-volume-muted",
1528 "dialog-information",
1532 "folder-drag-accept",
1541 "media-playlist-repeat",
1542 "media-playlist-shuffle",
1547 "software-update-available",
1548 "software-update-urgent",
1550 "sync-synchronizing",
1554 "weather-clear-night",
1555 "weather-few-clouds",
1556 "weather-few-clouds-night",
1566 using ThemeIconIndex = std::underlying_type_t<QIcon::ThemeIcon>;
1567 const auto index =
static_cast<ThemeIconIndex
>(
icon);
1837#if !defined(QT_NO_DATASTREAM)
1851 if (
s.version() >= QDataStream::Qt_4_3) {
1858 }
else if (
s.version() == QDataStream::Qt_4_2) {
1863 int num_entries =
engine->pixmaps.size();
1865 for (
int i=0;
i < num_entries; ++
i) {
1867 s <<
engine->pixmaps.at(
i).fileName;
1890 if (
s.version() >= QDataStream::Qt_4_3) {
1894 if (
key ==
"QPixmapIconEngine"_L1) {
1897 }
else if (
key ==
"QIconLoaderEngine"_L1 ||
key ==
"QThemeIconEngine"_L1) {
1901 const int index = iceLoader()->indexOf(
key);
1911 }
else if (
s.version() == QDataStream::Qt_4_2) {
1921 for (
int i=0;
i < num_entries; ++
i) {
1942#ifndef QT_NO_DEBUG_STREAM
1952 if (!
i.name().isEmpty())
1953 dbg <<
i.name() <<
',';
1954 dbg <<
"availableSizes[normal,Off]=" <<
i.availableSizes()
1985 qreal *sourceDevicePixelRatio)
1987 if (targetDevicePixelRatio <= 1.0)
1988 return baseFileName;
1991 if (disableNxImageLoading)
1992 return baseFileName;
1994 int dotIndex = baseFileName.lastIndexOf(u
'.');
1995 if (dotIndex == -1) {
1996 dotIndex = baseFileName.size();
1997 }
else if (dotIndex >= 2 && baseFileName[dotIndex - 1] == u
'9'
1998 && baseFileName[dotIndex - 2] == u
'.') {
2003 QString atNxfileName = baseFileName;
2004 atNxfileName.
insert(dotIndex,
"@2x"_L1);
2006 for (
int n =
qMin(
qCeil(targetDevicePixelRatio), 9);
n > 1; --
n) {
2009 if (sourceDevicePixelRatio)
2010 *sourceDevicePixelRatio =
n;
2011 return atNxfileName;
2015 return baseFileName;
T loadRelaxed() const noexcept
\inmodule QtCore\reentrant
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
QString absoluteFilePath() const
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
static QPalette palette()
Returns the current application palette.
The QIconEnginePlugin class provides an abstract base for custom QIconEngine plugins.
The QIconEngine class provides an abstract base class for QIcon renderers.
virtual void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)=0
Uses the given painter to paint the icon with the required mode and state into the rectangle rect.
virtual QPixmap scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale)
virtual QIconEngine * clone() const =0
Reimplement this method to return a clone of this icon engine.
virtual bool read(QDataStream &in)
Reads icon engine contents from the QDataStream in.
virtual QString iconName()
virtual QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the icon as a pixmap with the required size, mode, and state.
virtual void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)
Called by QIcon::addFile().
virtual QList< QSize > availableSizes(QIcon::Mode mode=QIcon::Normal, QIcon::State state=QIcon::Off)
virtual QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)
Returns the actual size of the icon the engine provides for the requested size, mode and state.
virtual void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
Called by QIcon::addPixmap().
virtual QString key() const
\variable QIconEngine::ScaledPixmapArgument::size
virtual bool write(QDataStream &out) const
Writes the contents of this engine to the QDataStream out.
static QIconLoader * instance()
QIconPrivate(QIconEngine *e)
static void clearIconCache()
qreal pixmapDevicePixelRatio(qreal displayDevicePixelRatio, const QSize &requestedSize, const QSize &actualSize)
The QIcon class provides scalable icons in different modes and states.
static bool hasThemeIcon(const QString &name)
void setIsMask(bool isMask)
void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment=Qt::AlignCenter, Mode mode=Normal, State state=Off) const
Uses the painter to paint the icon with specified alignment, required mode, and state into the rectan...
~QIcon()
Destroys the icon.
static QString themeName()
static void setFallbackSearchPaths(const QStringList &paths)
static void setThemeName(const QString &path)
static QStringList fallbackSearchPaths()
void addPixmap(const QPixmap &pixmap, Mode mode=Normal, State state=Off)
Adds pixmap to the icon, as a specialization for mode and state.
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Mode
This enum type describes the mode for which a pixmap is intended to be used.
QList< QSize > availableSizes(Mode mode=Normal, State state=Off) const
static void setThemeSearchPaths(const QStringList &searchpath)
qint64 cacheKey() const
Returns a number that identifies the contents of this QIcon object.
static void setFallbackThemeName(const QString &name)
void addFile(const QString &fileName, const QSize &size=QSize(), Mode mode=Normal, State state=Off)
Adds an image from the file with the given fileName to the icon, as a specialization for size,...
State
This enum describes the state for which a pixmap is intended to be used.
static QStringList themeSearchPaths()
QSize actualSize(const QSize &size, Mode mode=Normal, State state=Off) const
Returns the actual size of the icon for the requested size, mode, and state.
QIcon & operator=(const QIcon &other)
Assigns the other icon to this icon and returns a reference to this icon.
static QString fallbackThemeName()
QIcon() noexcept
Constructs a null icon.
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
static QIcon fromTheme(const QString &name)
The QImageReader class provides a format independent interface for reading images from files or other...
QSize size() const
Returns the size of the image, i.e.
qsizetype size() const noexcept
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
void remove(qsizetype i, qsizetype n=1)
QMimeType mimeTypeForFile(const QString &fileName, MatchMode mode=MatchDefault) const
Returns a MIME type for the file named fileName using mode.
QString preferredSuffix
the preferred suffix for the MIME type
static QObjectPrivate * get(QObject *o)
The QPainter class performs low-level painting on widgets and other paint devices.
Qt::LayoutDirection layoutDirection() const
Returns the layout direction used by the painter when drawing text.
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or \nullptr if the painter is n...
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
static bool find(const QString &key, QPixmap *pixmap)
Looks for a cached pixmap associated with the given key in the cache.
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
bool read(QDataStream &in) override
Reads icon engine contents from the QDataStream in.
QList< QSize > availableSizes(QIcon::Mode mode, QIcon::State state) override
QString key() const override
\variable QIconEngine::ScaledPixmapArgument::size
void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state) override
Called by QIcon::addPixmap().
QIconEngine * clone() const override
Reimplement this method to return a clone of this icon engine.
bool write(QDataStream &out) const override
Writes the contents of this engine to the QDataStream out.
QPixmap scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale) override
void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override
Uses the given painter to paint the icon with the required mode and state into the rectangle rect.
QPixmapIconEngineEntry * bestMatch(const QSize &size, qreal scale, QIcon::Mode mode, QIcon::State state, bool sizeOnly)
QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override
Returns the actual size of the icon the engine provides for the requested size, mode and state.
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override
Returns the icon as a pixmap with the required size, mode, and state.
void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state) override
Called by QIcon::addFile().
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
QSize size() const
Returns the size of the pixmap.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
qreal devicePixelRatio() const
Returns the device pixel ratio for the pixmap.
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
void scale(int w, int h, Qt::AspectRatioMode mode) noexcept
Scales the size to a rectangle with the given width and height, according to the specified mode:
constexpr bool isNull() const noexcept
Returns true if both the width and height is 0; otherwise returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
QString & insert(qsizetype i, QChar c)
A named-based icon engine for providing theme icons.
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Combined button and popup list for selecting options.
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
QTextStream & showbase(QTextStream &stream)
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() | QTextStream::ShowBase) on stream and r...
QTextStream & noshowbase(QTextStream &stream)
Calls QTextStream::setNumberFlags(QTextStream::numberFlags() & ~QTextStream::ShowBase) on stream and ...
QTextStream & dec(QTextStream &stream)
Calls QTextStream::setIntegerBase(10) on stream and returns stream.
#define Q_BASIC_ATOMIC_INITIALIZER(a)
void qAddPostRoutine(QtCleanUpFunction p)
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
static void qt_cleanup_icon_cache()
static constexpr auto themeIconMapping
static int origIcoDepth(const QImage &image)
static int area(const QSize &s)
static int nextSerialNumCounter()
QDataStream & operator>>(QDataStream &s, QIcon &icon)
static QIconEngine * iconEngineFromSuffix(const QString &fileName, const QString &suffix)
QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio, qreal *sourceDevicePixelRatio)
static int findBySize(const QList< QImage > &images, const QSize &size)
static QPixmapIconEngineEntry * bestSizeScaleMatch(const QSize &size, qreal scale, QPixmapIconEngineEntry *pa, QPixmapIconEngineEntry *pb)
static constexpr QLatin1StringView themeIconName(QIcon::ThemeIcon icon)
QDataStream & operator<<(QDataStream &s, const QIcon &icon)
Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio, qreal *sourceDevicePixelRatio=nullptr)
#define QIconEngineFactoryInterface_iid
QFactoryLoader * qt_iconEngineFactoryLoader()
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
constexpr auto qOffsetStringArray(const char(&...strings)[Nx]) noexcept
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLuint * paths
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
GLenum GLenum GLenum GLenum GLenum scale
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
static QRectF alignedRect(bool mirrored, Qt::Alignment alignment, const QSizeF &size, const QRectF &rectangle)
#define QStringLiteral(str)
Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
ReturnedValue read(const char *data)
QList< QImage > images
[6]
QTextStream out(stdout)
[7]
QItemEditorFactory * factory
\inmodule QtCore \reentrant