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 | |
63 | QT_BEGIN_NAMESPACE |
64 | |
65 | class QQmlEngine; |
66 | class QQuickPixmapData; |
67 | class QQuickTextureFactory; |
68 | class QQuickImageProviderOptionsPrivate; |
69 | |
70 | class QQuickDefaultTextureFactory : public QQuickTextureFactory |
71 | { |
72 | Q_OBJECT |
73 | public: |
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 | |
80 | private: |
81 | QImage im; |
82 | QSize size; |
83 | }; |
84 | |
85 | class QQuickImageProviderPrivate |
86 | { |
87 | public: |
88 | QQuickImageProvider::ImageType type; |
89 | QQuickImageProvider::Flags flags; |
90 | bool isProviderWithOptions; |
91 | }; |
92 | |
93 | // ### Qt 6: Make public moving to qquickimageprovider.h |
94 | class Q_QUICK_PRIVATE_EXPORT QQuickImageProviderOptions |
95 | { |
96 | public: |
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 | private: |
121 | QSharedDataPointer<QQuickImageProviderOptionsPrivate> d; |
122 | }; |
123 | |
124 | class Q_QUICK_PRIVATE_EXPORT QQuickPixmap |
125 | { |
126 | Q_DECLARE_TR_FUNCTIONS(QQuickPixmap) |
127 | public: |
128 | QQuickPixmap(); |
129 | QQuickPixmap(QQmlEngine *, const QUrl &); |
130 | QQuickPixmap(QQmlEngine *, const QUrl &, const QSize &); |
131 | QQuickPixmap(const QUrl &, const QImage &image); |
132 | ~QQuickPixmap(); |
133 | |
134 | enum Status { Null, Ready, Error, Loading }; |
135 | |
136 | enum Option { |
137 | Asynchronous = 0x00000001, |
138 | Cache = 0x00000002 |
139 | }; |
140 | Q_DECLARE_FLAGS(Options, Option) |
141 | |
142 | bool isNull() const; |
143 | bool isReady() const; |
144 | bool isError() const; |
145 | bool isLoading() const; |
146 | |
147 | Status status() const; |
148 | QString error() const; |
149 | const QUrl &url() const; |
150 | const QSize &implicitSize() const; |
151 | const QSize &requestSize() const; |
152 | QQuickImageProviderOptions::AutoTransform autoTransform() const; |
153 | QImage image() const; |
154 | void setImage(const QImage &); |
155 | void setPixmap(const QQuickPixmap &other); |
156 | |
157 | QQuickTextureFactory *textureFactory() const; |
158 | |
159 | QRect rect() const; |
160 | int width() const; |
161 | int height() const; |
162 | |
163 | void load(QQmlEngine *, const QUrl &); |
164 | void load(QQmlEngine *, const QUrl &, QQuickPixmap::Options options); |
165 | void load(QQmlEngine *, const QUrl &, const QSize &); |
166 | void load(QQmlEngine *, const QUrl &, const QSize &, QQuickPixmap::Options options); |
167 | void load(QQmlEngine *, const QUrl &, const QSize &, QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions); |
168 | |
169 | void clear(); |
170 | void clear(QObject *); |
171 | |
172 | bool connectFinished(QObject *, const char *); |
173 | bool connectFinished(QObject *, int); |
174 | bool connectDownloadProgress(QObject *, const char *); |
175 | bool connectDownloadProgress(QObject *, int); |
176 | |
177 | static void purgeCache(); |
178 | static bool isCached(const QUrl &url, const QSize &requestSize, const QQuickImageProviderOptions &options); |
179 | |
180 | static const QLatin1String itemGrabberScheme; |
181 | |
182 | private: |
183 | Q_DISABLE_COPY(QQuickPixmap) |
184 | QQuickPixmapData *d; |
185 | QIntrusiveListNode dataListNode; |
186 | friend class QQuickPixmapData; |
187 | }; |
188 | |
189 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPixmap::Options) |
190 | |
191 | // This class will disappear with Qt6 and will just be the regular QQuickImageProvider |
192 | // ### Qt 6: Remove this class and fold it with QQuickImageProvider |
193 | class Q_QUICK_PRIVATE_EXPORT QQuickImageProviderWithOptions : public QQuickAsyncImageProvider |
194 | { |
195 | public: |
196 | QQuickImageProviderWithOptions(ImageType type, Flags flags = Flags()); |
197 | |
198 | QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize) override; |
199 | QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize) override; |
200 | QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize) override; |
201 | QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override; |
202 | |
203 | virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options); |
204 | virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options); |
205 | virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options); |
206 | virtual QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize, const QQuickImageProviderOptions &options); |
207 | |
208 | static QSize loadSize(const QSize &originalSize, const QSize &requestedSize, const QByteArray &format, const QQuickImageProviderOptions &options); |
209 | static QQuickImageProviderWithOptions *checkedCast(QQuickImageProvider *provider); |
210 | }; |
211 | |
212 | QT_END_NAMESPACE |
213 | |
214 | #endif // QQUICKPIXMAPCACHE_H |
215 | |