Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qabstractfileiconengine.cpp
Go to the documentation of this file.
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
5
6#include <qpixmapcache.h>
7
9
10using namespace Qt::StringLiterals;
11
31{
34
35 if (!size.isValid())
36 return QPixmap();
37
39 if (key.isEmpty())
40 return filePixmap(size, mode, state);
41
42 key += u'_' + QString::number(size.width());
43
47 if (!result.isNull())
49 }
50
51 return result;
52}
53
55{
56 Q_UNUSED(scale); // (size is pre-multiplied by scale)
57 return pixmap(size, mode, state);
58}
59
62{
63 const QList<QSize> &sizes = availableSizes(mode, state);
64 const int numberSizes = sizes.size();
65 if (numberSizes == 0)
66 return QSize();
67
68 // Find the smallest available size whose area is still larger than the input
69 // size. Otherwise, use the largest area available size. (We don't assume the
70 // platform theme sizes are sorted, hence the extra logic.)
71 const int sizeArea = size.width() * size.height();
72 QSize actualSize = sizes.first();
73 int actualArea = actualSize.width() * actualSize.height();
74 for (int i = 1; i < numberSizes; ++i) {
75 const QSize &s = sizes.at(i);
76 const int a = s.width() * s.height();
77 if ((sizeArea <= a && a < actualArea) || (actualArea < sizeArea && actualArea < a)) {
78 actualSize = s;
79 actualArea = a;
80 }
81 }
82
83 if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
85
86 return actualSize;
87}
88
89/* Reimplement to return a cache key for the entry. An empty result indicates
90 * the icon should not be cached (for example, directory icons having custom icons). */
92{
93 if (!m_fileInfo.isFile() || m_fileInfo.isSymLink() || m_fileInfo.isExecutable())
94 return QString();
95
96 const QString &suffix = m_fileInfo.suffix();
97 return "qt_."_L1
98 + (suffix.isEmpty() ? m_fileInfo.fileName() : suffix); // handle "Makefile" ;)
99}
100
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State) override
Returns the icon as a pixmap with the required size, mode, and state.
virtual QPixmap filePixmap(const QSize &size, QIcon::Mode mode, QIcon::State)=0
virtual QString cacheKey() const
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 scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State, qreal scale) override
bool isSymLink() const
QString suffix() const
Returns the suffix (extension) of the file.
QString fileName() const
bool isExecutable() const
bool isFile() const
Returns true if this object points to a file or to a symbolic link to a file.
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition qicon.h:22
State
This enum describes the state for which a pixmap is intended to be used.
Definition qicon.h:23
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.
QList< QSize > availableSizes(QIcon::Mode mode, QIcon::State state) override
Definition qicon.cpp:354
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
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:
Definition qsize.h:145
constexpr bool isNull() const noexcept
Returns true if both the width and height is 0; otherwise returns false.
Definition qsize.h:121
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
else opt state
[0]
Combined button and popup list for selecting options.
@ KeepAspectRatio
GLenum mode
GLuint64 key
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble s
[6]
Definition qopenglext.h:235
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
GLuint64EXT * result
[6]
GLenum GLenum GLenum GLenum GLenum scale
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:187
widget render & pixmap