Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquicksprite_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKSPRITE_P_H
6#define QQUICKSPRITE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qtquickglobal_p.h>
20
22
23#include <QObject>
24#include <QUrl>
25#include <QVariantMap>
26#include <QQmlListProperty>
27#include <QtQuick/private/qquickpixmap_p.h>
29#include <QDebug>
30
32
33// exported, since it's used in QtQuickParticles
34class Q_QUICK_EXPORT QQuickSprite : public QQuickStochasticState
35{
36 Q_OBJECT
37 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
38 //Renderers have to query this hint when advancing frames
39 Q_PROPERTY(bool reverse READ reverse WRITE setReverse NOTIFY reverseChanged)
40 Q_PROPERTY(bool frameSync READ frameSync WRITE setFrameSync NOTIFY frameSyncChanged)
41 Q_PROPERTY(int frames READ frames WRITE setFrames NOTIFY frameCountChanged)
42 Q_PROPERTY(int frameCount READ frameCount WRITE setFrameCount NOTIFY frameCountChanged)
43 //If frame height or width is not specified, it is assumed to be a single long row of square frames.
44 //Otherwise, it can be multiple contiguous rows, when one row runs out the next will be used.
45 Q_PROPERTY(int frameHeight READ frameHeight WRITE setFrameHeight NOTIFY frameHeightChanged)
46 Q_PROPERTY(int frameWidth READ frameWidth WRITE setFrameWidth NOTIFY frameWidthChanged)
47 Q_PROPERTY(int frameX READ frameX WRITE setFrameX NOTIFY frameXChanged)
48 Q_PROPERTY(int frameY READ frameY WRITE setFrameY NOTIFY frameYChanged)
49 //Precedence order: frameRate, frameDuration, duration
50 Q_PROPERTY(qreal frameRate READ frameRate WRITE setFrameRate NOTIFY frameRateChanged RESET resetFrameRate)
51 Q_PROPERTY(qreal frameRateVariation READ frameRateVariation WRITE setFrameRateVariation NOTIFY frameRateVariationChanged)
52 Q_PROPERTY(int frameDuration READ frameDuration WRITE setFrameDuration NOTIFY frameDurationChanged RESET resetFrameDuration)
53 Q_PROPERTY(int frameDurationVariation READ frameDurationVariation WRITE setFrameDurationVariation NOTIFY frameDurationVariationChanged)
54 QML_NAMED_ELEMENT(Sprite)
55 QML_ADDED_IN_VERSION(2, 0)
56
57public:
58 explicit QQuickSprite(QObject *parent = nullptr);
59 ~QQuickSprite() override;
60
61 QUrl source() const
62 {
63 return m_source;
64 }
65
66 int frameHeight() const
67 {
68 return m_frameHeight;
69 }
70
71 int frameWidth() const
72 {
73 return m_frameWidth;
74 }
75
76 bool reverse() const
77 {
78 return m_reverse;
79 }
80
81 int frames() const
82 {
83 return m_frames;
84 }
85
86 int frameCount() const
87 {
88 return m_frames;
89 }
90
91 int frameX() const
92 {
93 return m_frameX;
94 }
95
96 int frameY() const
97 {
98 return m_frameY;
99 }
100
101 void resetFrameRate()
102 {
103 setFrameRate(-1);
104 }
105
106 qreal frameRate() const
107 {
108 return m_frameRate;
109 }
110
111 qreal frameRateVariation() const
112 {
113 return m_frameRateVariation;
114 }
115
116 void resetFrameDuration()
117 {
118 setFrameDuration(-1);
119 }
120
121 int frameDuration() const
122 {
123 return m_frameDuration;
124 }
125
126 int frameDurationVariation() const
127 {
128 return m_frameDurationVariation;
129 }
130
131 int variedDuration() const override;
132
133 bool frameSync() const
134 {
135 return m_frameSync;
136 }
137
138 void setDevicePixelRatio(qreal dpr)
139 {
140 m_devicePixelRatio = dpr;
141 }
142
143 qreal devicePixelRatio() const
144 {
145 return m_devicePixelRatio;
146 }
147
148Q_SIGNALS:
149
150 void sourceChanged(QUrl arg);
151
152 void frameHeightChanged(int arg);
153
154 void frameWidthChanged(int arg);
155
156 void reverseChanged(bool arg);
157
158 void frameCountChanged(int arg);
159
160 void frameXChanged(int arg);
161
162 void frameYChanged(int arg);
163
164 void frameRateChanged(qreal arg);
165
166 void frameRateVariationChanged(qreal arg);
167
168 void frameDurationChanged(int arg);
169
170 void frameDurationVariationChanged(int arg);
171
172 void frameSyncChanged(bool arg);
173
174public Q_SLOTS:
175
176 void setSource(QUrl arg)
177 {
178 if (m_source != arg) {
179 m_source = arg;
180 Q_EMIT sourceChanged(arg);
181 startImageLoading();
182 }
183 }
184
185 void setFrameHeight(int arg)
186 {
187 if (m_frameHeight != arg) {
188 m_frameHeight = arg;
189 Q_EMIT frameHeightChanged(arg);
190 }
191 }
192
193 void setFrameWidth(int arg)
194 {
195 if (m_frameWidth != arg) {
196 m_frameWidth = arg;
197 Q_EMIT frameWidthChanged(arg);
198 }
199 }
200
201 void setReverse(bool arg)
202 {
203 if (m_reverse != arg) {
204 m_reverse = arg;
205 Q_EMIT reverseChanged(arg);
206 }
207 }
208
209 void setFrames(int arg)
210 {
211 qWarning() << "Sprite::frames has been renamed Sprite::frameCount";
212 setFrameCount(arg);
213 }
214
215 void setFrameCount(int arg)
216 {
217 if (m_frames != arg) {
218 m_frames = arg;
219 Q_EMIT frameCountChanged(arg);
220 }
221 }
222
223 void setFrameX(int arg)
224 {
225 if (m_frameX != arg) {
226 m_frameX = arg;
227 Q_EMIT frameXChanged(arg);
228 }
229 }
230
231 void setFrameY(int arg)
232 {
233 if (m_frameY != arg) {
234 m_frameY = arg;
235 Q_EMIT frameYChanged(arg);
236 }
237 }
238
239 void setFrameRate(qreal arg)
240 {
241 if (m_frameRate != arg) {
242 m_frameRate = arg;
243 Q_EMIT frameRateChanged(arg);
244 }
245 }
246
247 void setFrameRateVariation(qreal arg)
248 {
249 if (m_frameRateVariation != arg) {
250 m_frameRateVariation = arg;
251 Q_EMIT frameRateVariationChanged(arg);
252 }
253 }
254
255 void setFrameDuration(int arg)
256 {
257 if (m_frameDuration != arg) {
258 m_frameDuration = arg;
259 Q_EMIT frameDurationChanged(arg);
260 }
261 }
262
263 void setFrameDurationVariation(int arg)
264 {
265 if (m_frameDurationVariation != arg) {
266 m_frameDurationVariation = arg;
267 Q_EMIT frameDurationVariationChanged(arg);
268 }
269 }
270
271 void setFrameSync(bool arg)
272 {
273 if (m_frameSync != arg) {
274 m_frameSync = arg;
275 Q_EMIT frameSyncChanged(arg);
276 }
277 }
278
279private Q_SLOTS:
280 void startImageLoading();
281
282private:
283 friend class QQuickImageParticle;
284 //friend class QQuickSpriteSequence;
285 friend class QQuickAnimatedSprite;
286 friend class QQuickSpriteEngine;
287 friend class QQuickStochasticEngine;
288
289 int m_generatedCount;
290 int m_framesPerRow;
291 int m_rowY;
292 int m_rowStartX;
293
294 QUrl m_source;
295 bool m_reverse;
296 int m_frameHeight;
297 int m_frameWidth;
298 int m_frames;
299 int m_frameX;
300 int m_frameY;
301 qreal m_frameRate;
302 qreal m_frameRateVariation;
303 int m_frameDuration;
304 int m_frameDurationVariation;
305 bool m_frameSync;
306 qreal m_devicePixelRatio;
307 QQuickPixmap m_pix;
308};
309
310QT_END_NAMESPACE
311
312#endif // QQUICKSPRITE_P_H
QT_REQUIRE_CONFIG(animation)
QT_REQUIRE_CONFIG(quick_sprite)