1 | // Copyright (C) 2016 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 | |
4 | #ifndef QQUICKIMAGEBASE_P_H |
5 | #define QQUICKIMAGEBASE_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qquickimplicitsizeitem_p.h" |
19 | #include <private/qtquickglobal_p.h> |
20 | #include <QtGui/qcolorspace.h> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | class QQuickImageBasePrivate; |
25 | class Q_QUICK_EXPORT QQuickImageBase : public QQuickImplicitSizeItem |
26 | { |
27 | Q_OBJECT |
28 | |
29 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
30 | Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) |
31 | Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) |
32 | Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged) |
33 | Q_PROPERTY(bool cache READ cache WRITE setCache NOTIFY cacheChanged) |
34 | Q_PROPERTY(bool mirror READ mirror WRITE setMirror NOTIFY mirrorChanged) |
35 | Q_PROPERTY(bool mirrorVertically READ mirrorVertically WRITE setMirrorVertically NOTIFY mirrorVerticallyChanged REVISION(6, 2)) |
36 | Q_PROPERTY(bool retainWhileLoading READ retainWhileLoading WRITE setRetainWhileLoading NOTIFY retainWhileLoadingChanged REVISION(6, 8)) |
37 | Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY currentFrameChanged REVISION(2, 14)) |
38 | Q_PROPERTY(int frameCount READ frameCount NOTIFY frameCountChanged REVISION(2, 14)) |
39 | Q_PROPERTY(QColorSpace colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged REVISION(2, 15)) |
40 | |
41 | QML_NAMED_ELEMENT(ImageBase); |
42 | QML_ADDED_IN_VERSION(2, 14) |
43 | QML_UNCREATABLE("ImageBase is an abstract base class." ) |
44 | |
45 | public: |
46 | enum LoadPixmapOption { |
47 | NoOption = 0x0000, |
48 | HandleDPR = 0x0001, |
49 | UseProviderOptions = 0x0002 |
50 | }; |
51 | |
52 | Q_DECLARE_FLAGS(LoadPixmapOptions, LoadPixmapOption) |
53 | Q_FLAG(LoadPixmapOptions) |
54 | |
55 | QQuickImageBase(QQuickItem *parent=nullptr); |
56 | ~QQuickImageBase(); |
57 | enum Status { Null, Ready, Loading, Error }; |
58 | Q_ENUM(Status) |
59 | Status status() const; |
60 | qreal progress() const; |
61 | |
62 | QUrl source() const; |
63 | virtual void setSource(const QUrl &url); |
64 | |
65 | bool asynchronous() const; |
66 | void setAsynchronous(bool); |
67 | |
68 | bool cache() const; |
69 | void setCache(bool); |
70 | |
71 | QImage image() const; |
72 | |
73 | virtual void setSourceSize(const QSize&); |
74 | QSize sourceSize() const; |
75 | void resetSourceSize(); |
76 | |
77 | QRectF sourceClipRect() const; |
78 | void setSourceClipRect(const QRectF &r); |
79 | void resetSourceClipRect(); |
80 | |
81 | virtual void setMirror(bool mirror); |
82 | bool mirror() const; |
83 | |
84 | virtual void setMirrorVertically(bool mirror); |
85 | bool mirrorVertically() const; |
86 | |
87 | virtual void setCurrentFrame(int frame); |
88 | virtual int currentFrame() const; |
89 | |
90 | virtual int frameCount() const; |
91 | |
92 | virtual void setAutoTransform(bool transform); |
93 | bool autoTransform() const; |
94 | |
95 | QColorSpace colorSpace() const; |
96 | virtual void setColorSpace(const QColorSpace &colorSpace); |
97 | |
98 | bool retainWhileLoading() const; |
99 | void setRetainWhileLoading(bool retain); |
100 | |
101 | static void resolve2xLocalFile(const QUrl &url, qreal targetDevicePixelRatio, QUrl *sourceUrl, qreal *sourceDevicePixelRatio); |
102 | |
103 | // Use a virtual rather than a signal->signal to avoid the huge |
104 | // connect/conneciton overhead for this rare case. |
105 | virtual void emitAutoTransformBaseChanged() { } |
106 | |
107 | Q_SIGNALS: |
108 | void sourceChanged(const QUrl &); |
109 | void sourceSizeChanged(); |
110 | void statusChanged(QQuickImageBase::Status); |
111 | void progressChanged(qreal progress); |
112 | void asynchronousChanged(); |
113 | void cacheChanged(); |
114 | void mirrorChanged(); |
115 | Q_REVISION(2, 14) void currentFrameChanged(); |
116 | Q_REVISION(2, 14) void frameCountChanged(); |
117 | Q_REVISION(2, 15) void sourceClipRectChanged(); |
118 | Q_REVISION(2, 15) void colorSpaceChanged(); |
119 | Q_REVISION(6, 2) void mirrorVerticallyChanged(); |
120 | Q_REVISION(6, 8) void retainWhileLoadingChanged(); |
121 | |
122 | protected: |
123 | void loadEmptyUrl(); |
124 | void loadPixmap(const QUrl &url, LoadPixmapOptions loadOptions = NoOption); |
125 | virtual void load(); |
126 | void componentComplete() override; |
127 | virtual void pixmapChange(); |
128 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
129 | QQuickImageBase(QQuickImageBasePrivate &dd, QQuickItem *parent); |
130 | |
131 | private Q_SLOTS: |
132 | virtual void requestFinished(); |
133 | void requestProgress(qint64,qint64); |
134 | |
135 | private: |
136 | Q_DISABLE_COPY(QQuickImageBase) |
137 | Q_DECLARE_PRIVATE(QQuickImageBase) |
138 | }; |
139 | |
140 | QT_END_NAMESPACE |
141 | |
142 | #endif // QQUICKIMAGEBASE_P_H |
143 | |