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_PRIVATE_EXPORT QQuickImageBase : public QQuickImplicitSizeItem |
26 | { |
27 | Q_OBJECT |
28 | |
29 | Q_PROPERTY(Status status READ status NOTIFY statusChanged FINAL) |
30 | Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged FINAL) |
31 | Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) |
32 | Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged FINAL) |
33 | Q_PROPERTY(bool cache READ cache WRITE setCache NOTIFY cacheChanged FINAL) |
34 | Q_PROPERTY(bool mirror READ mirror WRITE setMirror NOTIFY mirrorChanged FINAL) |
35 | Q_PROPERTY(bool mirrorVertically READ mirrorVertically WRITE setMirrorVertically NOTIFY mirrorVerticallyChanged REVISION(6, 2) FINAL) |
36 | Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY currentFrameChanged REVISION(2, 14)) |
37 | Q_PROPERTY(int frameCount READ frameCount NOTIFY frameCountChanged REVISION(2, 14)) |
38 | Q_PROPERTY(QColorSpace colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged REVISION(2, 15) FINAL) |
39 | |
40 | QML_NAMED_ELEMENT(ImageBase); |
41 | QML_ADDED_IN_VERSION(2, 14) |
42 | QML_UNCREATABLE("ImageBase is an abstract base class." ) |
43 | |
44 | public: |
45 | enum LoadPixmapOption { |
46 | NoOption = 0x0000, |
47 | HandleDPR = 0x0001, |
48 | UseProviderOptions = 0x0002 |
49 | }; |
50 | |
51 | Q_DECLARE_FLAGS(LoadPixmapOptions, LoadPixmapOption) |
52 | Q_FLAG(LoadPixmapOptions) |
53 | |
54 | QQuickImageBase(QQuickItem *parent=nullptr); |
55 | ~QQuickImageBase(); |
56 | enum Status { Null, Ready, Loading, Error }; |
57 | Q_ENUM(Status) |
58 | Status status() const; |
59 | qreal progress() const; |
60 | |
61 | QUrl source() const; |
62 | virtual void setSource(const QUrl &url); |
63 | |
64 | bool asynchronous() const; |
65 | void setAsynchronous(bool); |
66 | |
67 | bool cache() const; |
68 | void setCache(bool); |
69 | |
70 | QImage image() const; |
71 | |
72 | virtual void setSourceSize(const QSize&); |
73 | QSize sourceSize() const; |
74 | void resetSourceSize(); |
75 | |
76 | QRectF sourceClipRect() const; |
77 | void setSourceClipRect(const QRectF &r); |
78 | void resetSourceClipRect(); |
79 | |
80 | virtual void setMirror(bool mirror); |
81 | bool mirror() const; |
82 | |
83 | virtual void setMirrorVertically(bool mirror); |
84 | bool mirrorVertically() const; |
85 | |
86 | virtual void setCurrentFrame(int frame); |
87 | virtual int currentFrame() const; |
88 | |
89 | virtual int frameCount() const; |
90 | |
91 | virtual void setAutoTransform(bool transform); |
92 | bool autoTransform() const; |
93 | |
94 | QColorSpace colorSpace() const; |
95 | virtual void setColorSpace(const QColorSpace &colorSpace); |
96 | |
97 | static void resolve2xLocalFile(const QUrl &url, qreal targetDevicePixelRatio, QUrl *sourceUrl, qreal *sourceDevicePixelRatio); |
98 | |
99 | // Use a virtual rather than a signal->signal to avoid the huge |
100 | // connect/conneciton overhead for this rare case. |
101 | virtual void emitAutoTransformBaseChanged() { } |
102 | |
103 | Q_SIGNALS: |
104 | void sourceChanged(const QUrl &); |
105 | void sourceSizeChanged(); |
106 | void statusChanged(QQuickImageBase::Status); |
107 | void progressChanged(qreal progress); |
108 | void asynchronousChanged(); |
109 | void cacheChanged(); |
110 | void mirrorChanged(); |
111 | Q_REVISION(2, 14) void currentFrameChanged(); |
112 | Q_REVISION(2, 14) void frameCountChanged(); |
113 | Q_REVISION(2, 15) void sourceClipRectChanged(); |
114 | Q_REVISION(2, 15) void colorSpaceChanged(); |
115 | Q_REVISION(6, 2) void mirrorVerticallyChanged(); |
116 | |
117 | protected: |
118 | void loadEmptyUrl(); |
119 | void loadPixmap(const QUrl &url, LoadPixmapOptions loadOptions = NoOption); |
120 | virtual void load(); |
121 | void componentComplete() override; |
122 | virtual void pixmapChange(); |
123 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
124 | QQuickImageBase(QQuickImageBasePrivate &dd, QQuickItem *parent); |
125 | |
126 | private Q_SLOTS: |
127 | virtual void requestFinished(); |
128 | void requestProgress(qint64,qint64); |
129 | |
130 | private: |
131 | Q_DISABLE_COPY(QQuickImageBase) |
132 | Q_DECLARE_PRIVATE(QQuickImageBase) |
133 | }; |
134 | |
135 | QT_END_NAMESPACE |
136 | |
137 | #endif // QQUICKIMAGEBASE_P_H |
138 | |