Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickpixmap_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKPIXMAP_H
6#define QQUICKPIXMAP_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qcoreapplication.h>
20#include <QtCore/qstring.h>
21#include <QtGui/qpixmap.h>
22#include <QtCore/qmutex.h>
23#include <QtCore/qurl.h>
24#include <private/qtquickglobal_p.h>
25#include <QtQuick/qquickimageprovider.h>
26
28
29class QQmlEngine;
31class QQuickTextureFactory;
33
35{
37public:
39 QSGTexture *createTexture(QQuickWindow *window) const override;
40 QSize textureSize() const override { return size; }
41 int textureByteCount() const override { return size.width() * size.height() * 4; }
42 QImage image() const override { return im; }
43
44private:
45 QImage im;
46 QSize size;
47};
48
56
57// ### Qt 6: Make public moving to qquickimageprovider.h
58class Q_QUICK_EXPORT QQuickImageProviderOptions
59{
60public:
61 enum AutoTransform {
62 UsePluginDefaultTransform = -1,
63 ApplyTransform = 0,
64 DoNotApplyTransform = 1
65 };
66
67 QQuickImageProviderOptions();
68 ~QQuickImageProviderOptions();
69
70 QQuickImageProviderOptions(const QQuickImageProviderOptions&);
71 QQuickImageProviderOptions& operator=(const QQuickImageProviderOptions&);
72
73 bool operator==(const QQuickImageProviderOptions&) const;
74
75 AutoTransform autoTransform() const;
76 void setAutoTransform(AutoTransform autoTransform);
77
78 bool preserveAspectRatioCrop() const;
79 void setPreserveAspectRatioCrop(bool preserveAspectRatioCrop);
80
81 bool preserveAspectRatioFit() const;
82 void setPreserveAspectRatioFit(bool preserveAspectRatioFit);
83
84 QColorSpace targetColorSpace() const;
85 void setTargetColorSpace(const QColorSpace &colorSpace);
86
87 QRectF sourceClipRect() const;
88 void setSourceClipRect(const QRectF &rect);
89
90private:
91 QSharedDataPointer<QQuickImageProviderOptionsPrivate> d;
92};
93
94/*! \internal
95 A class that encapsulates the action of fetching a pixmap, as well as the
96 pixmap itself (indirectly via QQuickPixmapData::textureFactory) and the
97 responsibility of canceling outstanding requests. Rather than relying on
98 QPixmapCache which doesn't cache all the information Qt Quick needs,
99 QQuickPixmap implements its own cache, that correctly degrades over time.
100 (QQuickPixmapData::release() marks it as being not-currently-used, and
101 QQuickPixmapCache::shrinkCache() sweeps away the least-recently-released
102 instances until the remaining bytes are less than cache_limit.)
103*/
104class Q_QUICK_EXPORT QQuickPixmap
105{
106 Q_DECLARE_TR_FUNCTIONS(QQuickPixmap)
107public:
108 enum Status { Null, Ready, Error, Loading };
109
110 enum Option {
111 Asynchronous = 0x00000001,
112 Cache = 0x00000002
113 };
114 Q_DECLARE_FLAGS(Options, Option)
115
116 QQuickPixmap();
117 QQuickPixmap(QQmlEngine *, const QUrl &);
118 QQuickPixmap(QQmlEngine *, const QUrl &, Options options);
119 QQuickPixmap(QQmlEngine *, const QUrl &, const QRect &region, const QSize &);
120 QQuickPixmap(const QUrl &, const QImage &image);
121 ~QQuickPixmap();
122
123 bool isNull() const;
124 bool isReady() const;
125 bool isError() const;
126 bool isLoading() const;
127
128 Status status() const;
129 QString error() const;
130 const QUrl &url() const;
131 const QSize &implicitSize() const;
132 const QRect &requestRegion() const;
133 const QSize &requestSize() const;
135 int frameCount() const;
136 QImage image() const;
137 void setImage(const QImage &);
138 void setPixmap(const QQuickPixmap &other);
139
140 QColorSpace colorSpace() const;
141
142 QQuickTextureFactory *textureFactory() const;
143
144 QRect rect() const;
145 int width() const;
146 int height() const;
147 qreal devicePixelRatio() const;
148
149 void load(QQmlEngine *, const QUrl &);
150 void load(QQmlEngine *, const QUrl &, QQuickPixmap::Options options);
151 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize);
152 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize, QQuickPixmap::Options options);
153 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize,
154 QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions, int frame = 0, int frameCount = 1,
155 qreal devicePixelRatio = 1.0);
156 void loadImageFromDevice(QQmlEngine *engine, QIODevice *device, const QUrl &url,
157 const QRect &requestRegion, const QSize &requestSize,
158 const QQuickImageProviderOptions &providerOptions, int frame = 0, int frameCount = 1);
159
160 void clear();
161 void clear(QObject *);
162
163 bool connectFinished(QObject *, const char *);
164 bool connectFinished(QObject *, int);
165 bool connectDownloadProgress(QObject *, const char *);
166 bool connectDownloadProgress(QObject *, int);
167
168 static void purgeCache();
169 static bool isCached(const QUrl &url, const QRect &requestRegion, const QSize &requestSize,
170 const int frame, const QQuickImageProviderOptions &options);
171 static bool isScalableImageFormat(const QUrl &url);
172
174
175private:
176 Q_DISABLE_COPY(QQuickPixmap)
177 QQuickPixmapData *d;
178 friend class QQuickPixmapData;
179};
180
181Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPixmap::Options)
182
183// ### Qt 6: This should be made public in Qt 6. It's functionality can't be merged into
184// QQuickImageProvider without breaking source compatibility.
185class Q_QUICK_EXPORT QQuickImageProviderWithOptions : public QQuickAsyncImageProvider
186{
187public:
188 QQuickImageProviderWithOptions(ImageType type, Flags flags = Flags());
189
190 QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize) override;
191 QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize) override;
192 QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize) override;
193 QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
194
195 virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
196 virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
197 virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options);
198 virtual QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize, const QQuickImageProviderOptions &options);
199
200 static QSize loadSize(const QSize &originalSize, const QSize &requestedSize, const QByteArray &format, const QQuickImageProviderOptions &options,
201 qreal devicePixelRatio = 1.0);
202 static QQuickImageProviderWithOptions *checkedCast(QQuickImageProvider *provider);
203};
204
205QT_END_NAMESPACE
206
207#endif // QQUICKPIXMAP_H
bool autoTransform() const
ImageReaderError error() const
Returns the type of error that occurred last.
qreal width() const
Returns the width of the generated outlines.
bool isLoading() const
Returns true if the incubator's status() is Loading.
bool isError() const
Returns true if the incubator's status() is Error.
bool isNull() const
Returns true if the incubator's status() is Null.
Status status() const
Return the current status of the incubator.
bool isReady() const
Returns true if the incubator's status() is Ready.
The QQuickAsyncImageProvider class provides an interface for asynchronous control of QML image reques...
QImage image() const override
Returns an image version of this texture.
QSize textureSize() const override
Returns the size of the texture.
int textureByteCount() const override
Returns the number of bytes of memory the texture consumes.
QSGTexture * createTexture(QQuickWindow *window) const override
This function is called on the scene graph rendering thread to create a QSGTexture instance from the ...
QQuickImageProviderOptions::AutoTransform autoTransform
The QQuickImageProviderOptions class provides options for QQuickImageProviderWithOptions image reques...
The QQuickImageProvider class provides an interface for supporting pixmaps and threaded image request...
The QQuickImageResponse class provides an interface for asynchronous image loading in QQuickAsyncImag...
QColorSpace colorSpace() const
void clear(QObject *)
const QUrl & url() const
QQuickPixmap(QQmlEngine *, const QUrl &, const QRect &region, const QSize &)
QQuickPixmap(QQmlEngine *, const QUrl &, Options options)
void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize, QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions, int frame=0, int frameCount=1, qreal devicePixelRatio=1.0)
bool connectDownloadProgress(QObject *, const char *)
static bool isScalableImageFormat(const QUrl &url)
QQuickTextureFactory * textureFactory() const
qreal devicePixelRatio() const
void load(QQmlEngine *, const QUrl &, QQuickPixmap::Options options)
const QSize & requestSize() const
void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize, QQuickPixmap::Options options)
QQuickPixmap(QQmlEngine *, const QUrl &)
QQuickPixmap(const QUrl &, const QImage &image)
static bool isCached(const QUrl &url, const QRect &requestRegion, const QSize &requestSize, const int frame, const QQuickImageProviderOptions &options)
void load(QQmlEngine *, const QUrl &)
void loadImageFromDevice(QQmlEngine *engine, QIODevice *device, const QUrl &url, const QRect &requestRegion, const QSize &requestSize, const QQuickImageProviderOptions &providerOptions, int frame=0, int frameCount=1)
const QRect & requestRegion() const
const QSize & implicitSize() const
void setImage(const QImage &)
void setPixmap(const QQuickPixmap &other)
static const QLatin1String itemGrabberScheme
void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize)
bool connectFinished(QObject *, const char *)
bool connectFinished(QObject *, int)
static void purgeCache()
bool connectDownloadProgress(QObject *, int)
The QQuickTextureFactory class provides an interface for loading custom textures from QML....
void clear()
Clears the entire result set and releases any associated resources.
Combined button and popup list for selecting options.
QFixed height() const