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 "qpa/qplatformtheme.h"
71 return 1 + serial.fetchAndAddRelaxed(1);
76 struct IconCache :
public QCache<QString, QIcon>
90 qtIconCache()->clear();
119 QSize targetSize = requestedSize * displayDevicePixelRatio;
123 return displayDevicePixelRatio;
146 qreal dpr = paintDevice ? paintDevice->devicePixelRatio() :
qApp->devicePixelRatio();
152static inline int area(
const QSize &
s) {
return s.width() *
s.height(); }
173 return (
qAbs(ascore) <
qAbs(bscore)) ? pa : pb;
200 for (
int i = 0;
i < pixmaps.
size(); ++
i)
230 if ((pe = tryMatch(
size,
scale, oppositeMode, oppositeState)))
238 if ((pe = tryMatch(
size,
scale, oppositeMode, oppositeState)))
277 int idx = pixmaps.
size();
279 if (pe == &pixmaps.
at(idx)) {
351 for (
int i = 0;
i < pixmaps.
size(); ++
i) {
380 return s.isEmpty() ? 32 :
s.toInt();
405 *
image = m_reader.read();
406 if (!
image->size().isValid()) {
410 m_atEnd = !m_reader.jumpToNextImage();
425 const bool ignoreSize = !
size.isValid();
426 ImageReader imageReader(abs);
433 while (imageReader.read(&
image))
448 while (imageReader.read(&
image)) {
449 if (ignoreSize ||
image.size() ==
size) {
459 for (
const QImage &
i : std::as_const(icoImages))
461 if (icoImages.
isEmpty() && !ignoreSize)
467 return "QPixmapIconEngine"_L1;
485 for (
int i=0;
i < num_entries; ++
i) {
508 int num_entries = pixmaps.
size();
510 for (
int i=0;
i < num_entries; ++
i) {
831 if (devicePixelRatio == -1)
832 devicePixelRatio =
qApp->devicePixelRatio();
835 if (!(devicePixelRatio > 1.0)) {
837 pixmap.setDevicePixelRatio(1.0);
847#if QT_DEPRECATED_SINCE(6, 0)
885 const qreal devicePixelRatio =
qApp->devicePixelRatio();
888 if (!(devicePixelRatio > 1.0))
895#if QT_DEPRECATED_SINCE(6, 0)
917 if (!(devicePixelRatio > 1.0))
941 int w =
size.width();
942 int h =
size.height();
944 y +=
rect.size().height()/2 -
h/2;
946 y +=
rect.size().height() -
h;
948 x +=
rect.size().width() -
w;
950 x +=
rect.size().width()/2 -
w/2;
1027 const int index = iceLoader()->indexOf(suffix);
1076#if QT_CONFIG(mimetype)
1299 if (
QIcon *cachedIcon = qtIconCache()->
object(
name))
1381#if !defined(QT_NO_DATASTREAM)
1407 int num_entries =
engine->pixmaps.size();
1409 for (
int i=0;
i < num_entries; ++
i) {
1411 s <<
engine->pixmaps.at(
i).fileName;
1438 if (
key ==
"QPixmapIconEngine"_L1) {
1441 }
else if (
key ==
"QIconLoaderEngine"_L1 ||
key ==
"QThemeIconEngine"_L1) {
1445 const int index = iceLoader()->indexOf(
key);
1465 for (
int i=0;
i < num_entries; ++
i) {
1486#ifndef QT_NO_DEBUG_STREAM
1496 if (!
i.name().isEmpty())
1497 dbg <<
i.name() <<
',';
1498 dbg <<
"availableSizes[normal,Off]=" <<
i.availableSizes()
1529 qreal *sourceDevicePixelRatio)
1531 if (targetDevicePixelRatio <= 1.0)
1532 return baseFileName;
1535 if (disableNxImageLoading)
1536 return baseFileName;
1539 if (dotIndex == -1) {
1540 dotIndex = baseFileName.
size();
1541 }
else if (dotIndex >= 2 && baseFileName[dotIndex - 1] == u
'9'
1542 && baseFileName[dotIndex - 2] == u
'.') {
1547 QString atNxfileName = baseFileName;
1548 atNxfileName.
insert(dotIndex,
"@2x"_L1);
1550 for (
int n =
qMin(
qCeil(targetDevicePixelRatio), 9);
n > 1; --
n) {
1553 if (sourceDevicePixelRatio)
1554 *sourceDevicePixelRatio =
n;
1555 return atNxfileName;
1559 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.
\inmodule QtCore \reentrant
QString suffix() const
Returns the suffix (extension) of the file.
QString absoluteFilePath() const
Returns an absolute path including the file name.
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.
void setFallbackThemeName(const QString &themeName)
QStringList fallbackSearchPaths() const
void setFallbackSearchPaths(const QStringList &searchPaths)
void setThemeSearchPath(const QStringList &searchPaths)
static QIconLoader * instance()
QString fallbackThemeName() const
QStringList themeSearchPaths() const
QString themeName() const
void setThemeName(const QString &themeName)
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)
void append(parameter_type t)
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.
qint64 cacheKey() const
Returns a number that identifies the contents of this QPalette object.
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.
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.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
void clear()
Clears the contents of the string and makes it null.
qsizetype size() const
Returns the number of characters in this string.
bool isEmpty() const
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 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)
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)
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]
QFileInfo info(fileName)
[8]
QTextStream out(stdout)
[7]
QItemEditorFactory * factory
\inmodule QtCore \reentrant