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
148 void load(QQmlEngine *, const QUrl &);
149 void load(QQmlEngine *, const QUrl &, QQuickPixmap::Options options);
150 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize);
151 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize, QQuickPixmap::Options options);
152 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize,
153 QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions, int frame = 0, int frameCount = 1,
154 qreal devicePixelRatio = 1.0);
155 void loadImageFromDevice(QQmlEngine *engine, QIODevice *device, const QUrl &url,
156 const QRect &requestRegion, const QSize &requestSize,
157 const QQuickImageProviderOptions &providerOptions, int frame = 0, int frameCount = 1);
158
159 void clear();
160 void clear(QObject *);
161
162 bool connectFinished(QObject *, const char *);
163 bool connectFinished(QObject *, int);
164 bool connectDownloadProgress(QObject *, const char *);
165 bool connectDownloadProgress(QObject *, int);
166
167 static void purgeCache();
168 static bool isCached(const QUrl &url, const QRect &requestRegion, const QSize &requestSize,
169 const int frame, const QQuickImageProviderOptions &options);
170 static bool isScalableImageFormat(const QUrl &url);
171
173
174private:
175 Q_DISABLE_COPY(QQuickPixmap)
176 QQuickPixmapData *d;
177 friend class QQuickPixmapData;
178};
179
180Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPixmap::Options)
181
182// ### Qt 6: This should be made public in Qt 6. It's functionality can't be merged into
183// QQuickImageProvider without breaking source compatibility.
184class Q_QUICK_EXPORT QQuickImageProviderWithOptions : public QQuickAsyncImageProvider
185{
186public:
187 QQuickImageProviderWithOptions(ImageType type, Flags flags = Flags());
188
189 QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize) override;
190 QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize) override;
191 QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize) override;
192 QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
193
194 virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
195 virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
196 virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options);
197 virtual QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize, const QQuickImageProviderOptions &options);
198
199 static QSize loadSize(const QSize &originalSize, const QSize &requestedSize, const QByteArray &format, const QQuickImageProviderOptions &options,
200 qreal devicePixelRatio = 1.0);
201 static QQuickImageProviderWithOptions *checkedCast(QQuickImageProvider *provider);
202};
203
204QT_END_NAMESPACE
205
206#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
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.
QFixed height() const