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 QQUICKIMAGEPROVIDER_H
41#define QQUICKIMAGEPROVIDER_H
42
43#include <QtQuick/qtquickglobal.h>
44#include <QtGui/qimage.h>
45#include <QtGui/qpixmap.h>
46#include <QtQml/qqmlengine.h>
47
48QT_BEGIN_NAMESPACE
49
50
51class QQuickImageProviderPrivate;
52class QQuickAsyncImageProviderPrivate;
53class QQuickImageProviderOptionsPrivate;
54class QSGTexture;
55class QQuickWindow;
56
57class Q_QUICK_EXPORT QQuickTextureFactory : public QObject
58{
59 Q_OBJECT
60public:
61 QQuickTextureFactory();
62 ~QQuickTextureFactory() override;
63
64 virtual QSGTexture *createTexture(QQuickWindow *window) const = 0;
65 virtual QSize textureSize() const = 0;
66 virtual int textureByteCount() const = 0;
67 virtual QImage image() const;
68
69 static QQuickTextureFactory *textureFactoryForImage(const QImage &image);
70};
71
72class QQuickImageResponsePrivate;
73
74class Q_QUICK_EXPORT QQuickImageResponse : public QObject
75{
76Q_OBJECT
77public:
78 QQuickImageResponse();
79 ~QQuickImageResponse() override;
80
81 virtual QQuickTextureFactory *textureFactory() const = 0;
82 virtual QString errorString() const;
83
84public Q_SLOTS:
85 virtual void cancel();
86
87Q_SIGNALS:
88 void finished();
89
90private:
91 Q_DECLARE_PRIVATE(QQuickImageResponse)
92 Q_PRIVATE_SLOT(d_func(), void _q_finished())
93};
94
95class Q_QUICK_EXPORT QQuickImageProvider : public QQmlImageProviderBase
96{
97 friend class QQuickImageProviderWithOptions; // ### Qt 6 Remove
98public:
99 QQuickImageProvider(ImageType type, Flags flags = Flags());
100 ~QQuickImageProvider() override;
101
102 ImageType imageType() const override;
103 Flags flags() const override;
104
105#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
106 virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
107 virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
108 virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options);
109#else
110 virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize);
111 virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize);
112 virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize);
113#endif
114
115private:
116 QQuickImageProviderPrivate *d;
117};
118
119class Q_QUICK_EXPORT QQuickAsyncImageProvider : public QQuickImageProvider
120{
121public:
122 QQuickAsyncImageProvider();
123 ~QQuickAsyncImageProvider() override;
124
125#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
126 virtual QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize, const QQuickImageProviderOptions &options) = 0;
127#else
128 virtual QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) = 0;
129#endif
130
131private:
132 QQuickAsyncImageProviderPrivate *d;
133};
134
135QT_END_NAMESPACE
136
137#endif // QQUICKIMAGEPROVIDER_H
138

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