1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKPIXMAPCACHE_H
41#define QQUICKPIXMAPCACHE_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtCore/qcoreapplication.h>
55#include <QtCore/qstring.h>
56#include <QtGui/qpixmap.h>
57#include <QtCore/qurl.h>
58#include <private/qtquickglobal_p.h>
59#include <QtQuick/qquickimageprovider.h>
60
61#include <private/qintrusivelist_p.h>
62
63QT_BEGIN_NAMESPACE
64
65class QQmlEngine;
66class QQuickPixmapData;
67class QQuickTextureFactory;
68class QQuickImageProviderOptionsPrivate;
69
70class QQuickDefaultTextureFactory : public QQuickTextureFactory
71{
72 Q_OBJECT
73public:
74 QQuickDefaultTextureFactory(const QImage &i);
75 QSGTexture *createTexture(QQuickWindow *window) const override;
76 QSize textureSize() const override { return size; }
77 int textureByteCount() const override { return size.width() * size.height() * 4; }
78 QImage image() const override { return im; }
79
80private:
81 QImage im;
82 QSize size;
83};
84
85class QQuickImageProviderPrivate
86{
87public:
88 QQuickImageProvider::ImageType type;
89 QQuickImageProvider::Flags flags;
90 bool isProviderWithOptions;
91};
92
93// ### Qt 6: Make public moving to qquickimageprovider.h
94class Q_QUICK_PRIVATE_EXPORT QQuickImageProviderOptions
95{
96public:
97 enum AutoTransform {
98 UsePluginDefaultTransform = -1,
99 ApplyTransform = 0,
100 DoNotApplyTransform = 1
101 };
102
103 QQuickImageProviderOptions();
104 ~QQuickImageProviderOptions();
105
106 QQuickImageProviderOptions(const QQuickImageProviderOptions&);
107 QQuickImageProviderOptions& operator=(const QQuickImageProviderOptions&);
108
109 bool operator==(const QQuickImageProviderOptions&) const;
110
111 AutoTransform autoTransform() const;
112 void setAutoTransform(AutoTransform autoTransform);
113
114 bool preserveAspectRatioCrop() const;
115 void setPreserveAspectRatioCrop(bool preserveAspectRatioCrop);
116
117 bool preserveAspectRatioFit() const;
118 void setPreserveAspectRatioFit(bool preserveAspectRatioFit);
119
120 QColorSpace targetColorSpace() const;
121 void setTargetColorSpace(const QColorSpace &colorSpace);
122
123private:
124 QSharedDataPointer<QQuickImageProviderOptionsPrivate> d;
125};
126
127class Q_QUICK_PRIVATE_EXPORT QQuickPixmap
128{
129 Q_DECLARE_TR_FUNCTIONS(QQuickPixmap)
130public:
131 QQuickPixmap();
132 QQuickPixmap(QQmlEngine *, const QUrl &);
133 QQuickPixmap(QQmlEngine *, const QUrl &, const QRect &region, const QSize &);
134 QQuickPixmap(const QUrl &, const QImage &image);
135 ~QQuickPixmap();
136
137 enum Status { Null, Ready, Error, Loading };
138
139 enum Option {
140 Asynchronous = 0x00000001,
141 Cache = 0x00000002
142 };
143 Q_DECLARE_FLAGS(Options, Option)
144
145 bool isNull() const;
146 bool isReady() const;
147 bool isError() const;
148 bool isLoading() const;
149
150 Status status() const;
151 QString error() const;
152 const QUrl &url() const;
153 const QSize &implicitSize() const;
154 const QRect &requestRegion() const;
155 const QSize &requestSize() const;
156 QQuickImageProviderOptions::AutoTransform autoTransform() const;
157 int frameCount() const;
158 QImage image() const;
159 void setImage(const QImage &);
160 void setPixmap(const QQuickPixmap &other);
161
162 QColorSpace colorSpace() const;
163
164 QQuickTextureFactory *textureFactory() const;
165
166 QRect rect() const;
167 int width() const;
168 int height() const;
169
170 void load(QQmlEngine *, const QUrl &);
171 void load(QQmlEngine *, const QUrl &, QQuickPixmap::Options options);
172 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize);
173 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize, QQuickPixmap::Options options);
174 void load(QQmlEngine *, const QUrl &, const QRect &requestRegion, const QSize &requestSize,
175 QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions, int frame = 0, int frameCount = 1);
176
177 void clear();
178 void clear(QObject *);
179
180 bool connectFinished(QObject *, const char *);
181 bool connectFinished(QObject *, int);
182 bool connectDownloadProgress(QObject *, const char *);
183 bool connectDownloadProgress(QObject *, int);
184
185 static void purgeCache();
186 static bool isCached(const QUrl &url, const QRect &requestRegion, const QSize &requestSize,
187 const int frame, const QQuickImageProviderOptions &options);
188
189 static const QLatin1String itemGrabberScheme;
190
191private:
192 Q_DISABLE_COPY(QQuickPixmap)
193 QQuickPixmapData *d;
194 QIntrusiveListNode dataListNode;
195 friend class QQuickPixmapData;
196};
197
198Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPixmap::Options)
199
200// This class will disappear with Qt6 and will just be the regular QQuickImageProvider
201// ### Qt 6: Remove this class and fold it with QQuickImageProvider
202class Q_QUICK_PRIVATE_EXPORT QQuickImageProviderWithOptions : public QQuickAsyncImageProvider
203{
204public:
205 QQuickImageProviderWithOptions(ImageType type, Flags flags = Flags());
206
207 QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize) override;
208 QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize) override;
209 QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize) override;
210 QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
211
212 virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
213 virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
214 virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options);
215 virtual QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize, const QQuickImageProviderOptions &options);
216
217 static QSize loadSize(const QSize &originalSize, const QSize &requestedSize, const QByteArray &format, const QQuickImageProviderOptions &options);
218 static QQuickImageProviderWithOptions *checkedCast(QQuickImageProvider *provider);
219};
220
221QT_END_NAMESPACE
222
223#endif // QQUICKPIXMAPCACHE_H
224

source code of qtdeclarative/src/quick/util/qquickpixmapcache_p.h