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 QQUICKIMAGEBASE_P_H
41#define QQUICKIMAGEBASE_P_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 "qquickimplicitsizeitem_p.h"
55#include <private/qtquickglobal_p.h>
56#include <QtGui/qcolorspace.h>
57
58QT_BEGIN_NAMESPACE
59
60class QQuickImageBasePrivate;
61class Q_QUICK_PRIVATE_EXPORT QQuickImageBase : public QQuickImplicitSizeItem
62{
63 Q_OBJECT
64
65 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
66 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
67 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
68 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
69 Q_PROPERTY(bool cache READ cache WRITE setCache NOTIFY cacheChanged)
70 Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize RESET resetSourceSize NOTIFY sourceSizeChanged)
71 Q_PROPERTY(bool mirror READ mirror WRITE setMirror NOTIFY mirrorChanged)
72 Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY currentFrameChanged REVISION 14)
73 Q_PROPERTY(int frameCount READ frameCount NOTIFY frameCountChanged REVISION 14)
74 Q_PROPERTY(QColorSpace colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged REVISION 15)
75
76 QML_NAMED_ELEMENT(ImageBase);
77 QML_ADDED_IN_MINOR_VERSION(14)
78 QML_UNCREATABLE("ImageBase is an abstract base class.")
79
80public:
81 enum LoadPixmapOption {
82 NoOption = 0x0000,
83 HandleDPR = 0x0001,
84 UseProviderOptions = 0x0002
85 };
86
87 Q_DECLARE_FLAGS(LoadPixmapOptions, LoadPixmapOption)
88 Q_FLAG(LoadPixmapOptions)
89
90 QQuickImageBase(QQuickItem *parent=nullptr);
91 ~QQuickImageBase();
92 enum Status { Null, Ready, Loading, Error };
93 Q_ENUM(Status)
94 Status status() const;
95 qreal progress() const;
96
97 QUrl source() const;
98 virtual void setSource(const QUrl &url);
99
100 bool asynchronous() const;
101 void setAsynchronous(bool);
102
103 bool cache() const;
104 void setCache(bool);
105
106 QImage image() const;
107
108 virtual void setSourceSize(const QSize&);
109 QSize sourceSize() const;
110 void resetSourceSize();
111
112 QRectF sourceClipRect() const;
113 void setSourceClipRect(const QRectF &r);
114 void resetSourceClipRect();
115
116 virtual void setMirror(bool mirror);
117 bool mirror() const;
118
119 virtual void setCurrentFrame(int frame);
120 virtual int currentFrame() const;
121
122 virtual int frameCount() const;
123
124 virtual void setAutoTransform(bool transform);
125 bool autoTransform() const;
126
127 QColorSpace colorSpace() const;
128 virtual void setColorSpace(const QColorSpace &colorSpace);
129
130 static void resolve2xLocalFile(const QUrl &url, qreal targetDevicePixelRatio, QUrl *sourceUrl, qreal *sourceDevicePixelRatio);
131
132 // Use a virtual rather than a signal->signal to avoid the huge
133 // connect/conneciton overhead for this rare case.
134 virtual void emitAutoTransformBaseChanged() { }
135
136Q_SIGNALS:
137 void sourceChanged(const QUrl &);
138 void sourceSizeChanged();
139 void statusChanged(QQuickImageBase::Status);
140 void progressChanged(qreal progress);
141 void asynchronousChanged();
142 void cacheChanged();
143 void mirrorChanged();
144 Q_REVISION(14) void currentFrameChanged();
145 Q_REVISION(14) void frameCountChanged();
146 Q_REVISION(15) void sourceClipRectChanged();
147 Q_REVISION(15) void colorSpaceChanged();
148
149protected:
150 void loadEmptyUrl();
151 void loadPixmap(const QUrl &url, LoadPixmapOptions loadOptions = NoOption);
152 virtual void load();
153 void componentComplete() override;
154 virtual void pixmapChange();
155 void itemChange(ItemChange change, const ItemChangeData &value) override;
156 QQuickImageBase(QQuickImageBasePrivate &dd, QQuickItem *parent);
157
158private Q_SLOTS:
159 virtual void requestFinished();
160 void requestProgress(qint64,qint64);
161
162private:
163 Q_DISABLE_COPY(QQuickImageBase)
164 Q_DECLARE_PRIVATE(QQuickImageBase)
165};
166
167QT_END_NAMESPACE
168
169#endif // QQUICKIMAGEBASE_P_H
170

source code of qtdeclarative/src/quick/items/qquickimagebase_p.h