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;
43
44 bool isImageDropped() const;
45
46private:
47 mutable QMutex mutex;
48 mutable QImage im;
49 QSize size;
50 mutable bool imageDropped = false;
51};
52
60
61// ### Qt 6: Make public moving to qquickimageprovider.h
62class Q_QUICK_EXPORT QQuickImageProviderOptions
63{
64public:
65 enum AutoTransform {
66 UsePluginDefaultTransform = -1,
67 ApplyTransform = 0,
68 DoNotApplyTransform = 1
69 };
70
71 QQuickImageProviderOptions();
72 ~QQuickImageProviderOptions();
73
74 QQuickImageProviderOptions(const QQuickImageProviderOptions&);
75 QQuickImageProviderOptions& operator=(const QQuickImageProviderOptions&);
76
77 bool operator==(const QQuickImageProviderOptions&) const;
78
79 AutoTransform autoTransform() const;
80 void setAutoTransform(AutoTransform autoTransform);
81
82 bool preserveAspectRatioCrop() const;
83 void setPreserveAspectRatioCrop(bool preserveAspectRatioCrop);
84
85 bool preserveAspectRatioFit() const;
86 void setPreserveAspectRatioFit(bool preserveAspectRatioFit);
87
88 QColorSpace targetColorSpace() const;
89 void setTargetColorSpace(const QColorSpace &colorSpace);
90
91 QRectF sourceClipRect() const;
92 void setSourceClipRect(const QRectF &rect);
93
94private:
95 QSharedDataPointer<QQuickImageProviderOptionsPrivate> d;
96};
97
98/*! \internal
99 A class that encapsulates the action of fetching a pixmap, as well as the
100 pixmap itself (indirectly via QQuickPixmapData::textureFactory) and the
101 responsibility of canceling outstanding requests. Rather than relying on
102 QPixmapCache which doesn't cache all the information Qt Quick needs,
103 QQuickPixmap implements its own cache, that correctly degrades over time.
104 (QQuickPixmapData::release() marks it as being not-currently-used, and
105 QQuickPixmapCache::shrinkCache() sweeps away the least-recently-released
106 instances until the remaining bytes are less than cache_limit.)
107*/
108class Q_QUICK_EXPORT QQuickPixmap
109{
110 Q_DECLARE_TR_FUNCTIONS(QQuickPixmap)
111public:
112 enum Status { Null, Ready, Error, Loading };
113
114 enum Option {
115 Asynchronous = 0x00000001,
116 Cache = 0x00000002
117 };
118 Q_DECLARE_FLAGS(Options, Option)
119
120 QQuickPixmap();
121 QQuickPixmap(QQmlEngine *, const QUrl &);
122 QQuickPixmap(QQmlEngine *, const QUrl &, Options options);
123 QQuickPixmap(QQmlEngine *, const QUrl &, const QRect &region, const QSize &);
124 QQuickPixmap(const QUrl &, const QImage &image);
125 ~QQuickPixmap();
126
127 bool isNull() const;
128 bool isReady() const;
129 bool isError() const;
130 bool isLoading() const;
131
132 Status status() const;
133 QString error() const;
134 const QUrl &url() const;
135 const QSize &implicitSize() const;
136 const QRect &requestRegion() const;
137 const QSize &requestSize() const;
139 int frameCount() const;
140 QImage image() const;
141 void setImage(const QImage &);
142 void setPixmap(const QQuickPixmap &other);
143
144 QColorSpace colorSpace() const;
145
146 QQuickTextureFactory *textureFactory() const;
147 bool hasDroppedTransientImage() const;
149
150 QRect rect() const;
151 int width() const;
152 int height() const;
153 qreal devicePixelRatio() const;
154
155 void load(QQmlEngine *, const QUrl &);
156 void load(QQmlEngine *, const QUrl &, QQuickPixmap::Options options);
157 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize);
158 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize, QQuickPixmap::Options options);
159 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize,
160 QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions, int frame = 0, int frameCount = 1,
161 qreal devicePixelRatio = 1.0);
162 void loadImageFromDevice(QQmlEngine *engine, QIODevice *device, const QUrl &url,
163 const QRect &requestRegion, const QSize &requestSize,
164 const QQuickImageProviderOptions &providerOptions, int frame = 0, int frameCount = 1);
165
166 void clear();
167 void clear(QObject *);
168
169 bool connectFinished(QObject *, const char *);
170 bool connectFinished(QObject *, int);
171 bool connectDownloadProgress(QObject *, const char *);
172 bool connectDownloadProgress(QObject *, int);
173
174 static void purgeCache();
175 static bool isCached(const QUrl &url, const QRect &requestRegion, const QSize &requestSize,
176 const int frame, const QQuickImageProviderOptions &options);
177 static bool isScalableImageFormat(const QUrl &url);
178
180
181private:
182 Q_DISABLE_COPY(QQuickPixmap)
183 QQuickPixmapData *d;
184 friend class QQuickPixmapData;
185};
186
187Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPixmap::Options)
188
189// ### Qt 6: This should be made public in Qt 6. It's functionality can't be merged into
190// QQuickImageProvider without breaking source compatibility.
191class Q_QUICK_EXPORT QQuickImageProviderWithOptions : public QQuickAsyncImageProvider
192{
193public:
194 QQuickImageProviderWithOptions(ImageType type, Flags flags = Flags());
195
196 QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize) override;
197 QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize) override;
198 QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize) override;
199 QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
200
201 virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
202 virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
203 virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options);
204 virtual QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize, const QQuickImageProviderOptions &options);
205
206 static QSize loadSize(const QSize &originalSize, const QSize &requestedSize, const QByteArray &format, const QQuickImageProviderOptions &options,
207 qreal devicePixelRatio = 1.0);
208 static QQuickImageProviderWithOptions *checkedCast(QQuickImageProvider *provider);
209};
210
211QT_END_NAMESPACE
212
213#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.
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)
void removeDroppedTransientImageFromCache()
static void purgeCache()
bool hasDroppedTransientImage() const
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.
bool isNull() const noexcept
Returns true if there are zero numerical segments, otherwise returns false.
Combined button and popup list for selecting options.
QFixed height() const