More documentation about importing LocalStorage module from Javascript
[profile/ivi/qtdeclarative.git] / src / quick / items / qquicksprite_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the Declarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKSPRITE_P_H
43 #define QQUICKSPRITE_P_H
44
45 #include <QObject>
46 #include <QUrl>
47 #include <QVariantMap>
48 #include <QDeclarativeListProperty>
49 #include <QtQuick/private/qdeclarativepixmapcache_p.h>
50 #include "qquickspriteengine_p.h"
51 #include <QDebug>
52
53 QT_BEGIN_HEADER
54
55 QT_BEGIN_NAMESPACE
56
57 class QQuickSprite : public QQuickStochasticState
58 {
59     Q_OBJECT
60     Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
61     //Renderers have to query this hint when advancing frames
62     Q_PROPERTY(bool reverse READ reverse WRITE setReverse NOTIFY reverseChanged)
63     Q_PROPERTY(bool frameSync READ frameSync WRITE setFrameSync NOTIFY frameSyncChanged)
64     Q_PROPERTY(int frames READ frames WRITE setFrames NOTIFY frameCountChanged)
65     Q_PROPERTY(int frameCount READ frameCount WRITE setFrameCount NOTIFY frameCountChanged)
66     //If frame height or width is not specified, it is assumed to be a single long row of square frames.
67     //Otherwise, it can be multiple contiguous rows, when one row runs out the next will be used.
68     Q_PROPERTY(int frameHeight READ frameHeight WRITE setFrameHeight NOTIFY frameHeightChanged)
69     Q_PROPERTY(int frameWidth READ frameWidth WRITE setFrameWidth NOTIFY frameWidthChanged)
70     Q_PROPERTY(int frameX READ frameX WRITE setFrameX NOTIFY frameXChanged)
71     Q_PROPERTY(int frameY READ frameY WRITE setFrameY NOTIFY frameYChanged)
72     //Precedence order: frameRate, frameDuration, duration
73     Q_PROPERTY(qreal frameRate READ frameRate WRITE setFrameRate NOTIFY frameRateChanged RESET resetFrameRate)
74     Q_PROPERTY(qreal frameRateVariation READ frameRateVariation WRITE setFrameRateVariation NOTIFY frameRateVariationChanged)
75     Q_PROPERTY(int frameDuration READ frameDuration WRITE setFrameDuration NOTIFY frameDurationChanged RESET resetFrameDuration)
76     Q_PROPERTY(int frameDurationVariation READ frameDurationVariation WRITE setFrameDurationVariation NOTIFY frameDurationVariationChanged)
77
78 public:
79     explicit QQuickSprite(QObject *parent = 0);
80
81     QUrl source() const
82     {
83         return m_source;
84     }
85
86     int frameHeight() const
87     {
88         return m_frameHeight;
89     }
90
91     int frameWidth() const
92     {
93         return m_frameWidth;
94     }
95
96     bool reverse() const
97     {
98         return m_reverse;
99     }
100
101     int frames() const
102     {
103         return m_frames;
104     }
105
106     int frameCount() const
107     {
108         return m_frames;
109     }
110
111     int frameX() const
112     {
113         return m_frameX;
114     }
115
116     int frameY() const
117     {
118         return m_frameY;
119     }
120
121     void resetFrameRate()
122     {
123         setFrameRate(-1);
124     }
125
126     qreal frameRate() const
127     {
128         return m_frameRate;
129     }
130
131     qreal frameRateVariation() const
132     {
133         return m_frameRateVariation;
134     }
135
136     void resetFrameDuration()
137     {
138         setFrameDuration(-1);
139     }
140
141     int frameDuration() const
142     {
143         return m_frameDuration;
144     }
145
146     int frameDurationVariation() const
147     {
148         return m_frameDurationVariation;
149     }
150
151     int variedDuration() const;
152
153     bool frameSync() const
154     {
155         return m_frameSync;
156     }
157
158 signals:
159
160     void sourceChanged(QUrl arg);
161
162     void frameHeightChanged(int arg);
163
164     void frameWidthChanged(int arg);
165
166     void reverseChanged(bool arg);
167
168     void frameCountChanged(int arg);
169
170     void frameXChanged(int arg);
171
172     void frameYChanged(int arg);
173
174     void frameRateChanged(qreal arg);
175
176     void frameRateVariationChanged(qreal arg);
177
178     void frameDurationChanged(int arg);
179
180     void frameDurationVariationChanged(int arg);
181
182     void frameSyncChanged(bool arg);
183
184 public slots:
185
186     void setSource(QUrl arg)
187     {
188         if (m_source != arg) {
189             m_source = arg;
190             emit sourceChanged(arg);
191             startImageLoading();
192         }
193     }
194
195     void setFrameHeight(int arg)
196     {
197         if (m_frameHeight != arg) {
198             m_frameHeight = arg;
199             emit frameHeightChanged(arg);
200         }
201     }
202
203     void setFrameWidth(int arg)
204     {
205         if (m_frameWidth != arg) {
206             m_frameWidth = arg;
207             emit frameWidthChanged(arg);
208         }
209     }
210
211     void setReverse(bool arg)
212     {
213         if (m_reverse != arg) {
214             m_reverse = arg;
215             emit reverseChanged(arg);
216         }
217     }
218
219     void setFrames(int arg)
220     {
221         qWarning() << "Sprite::frames has been renamed Sprite::frameCount";
222         setFrameCount(arg);
223     }
224
225     void setFrameCount(int arg)
226     {
227         if (m_frames != arg) {
228             m_frames = arg;
229             emit frameCountChanged(arg);
230         }
231     }
232
233     void setFrameX(int arg)
234     {
235         if (m_frameX != arg) {
236             m_frameX = arg;
237             emit frameXChanged(arg);
238         }
239     }
240
241     void setFrameY(int arg)
242     {
243         if (m_frameY != arg) {
244             m_frameY = arg;
245             emit frameYChanged(arg);
246         }
247     }
248
249     void setFrameRate(qreal arg)
250     {
251         if (m_frameRate != arg) {
252             m_frameRate = arg;
253             emit frameRateChanged(arg);
254         }
255     }
256
257     void setFrameRateVariation(qreal arg)
258     {
259         if (m_frameRateVariation != arg) {
260             m_frameRateVariation = arg;
261             emit frameRateVariationChanged(arg);
262         }
263     }
264
265     void setFrameDuration(int arg)
266     {
267         if (m_frameDuration != arg) {
268             m_frameDuration = arg;
269             emit frameDurationChanged(arg);
270         }
271     }
272
273     void setFrameDurationVariation(int arg)
274     {
275         if (m_frameDurationVariation != arg) {
276             m_frameDurationVariation = arg;
277             emit frameDurationVariationChanged(arg);
278         }
279     }
280
281     void setFrameSync(bool arg)
282     {
283         if (m_frameSync != arg) {
284             m_frameSync = arg;
285             emit frameSyncChanged(arg);
286         }
287     }
288
289 private slots:
290     void startImageLoading();
291
292 private:
293     friend class QQuickImageParticle;
294     friend class QQuickSpriteSequence;
295     friend class QQuickAnimatedSprite;
296     friend class QQuickSpriteEngine;
297     friend class QQuickStochasticEngine;
298     int m_generatedCount;
299     int m_framesPerRow;
300     int m_rowY;
301     int m_rowStartX;
302
303     QUrl m_source;
304     bool m_reverse;
305     int m_frameHeight;
306     int m_frameWidth;
307     int m_frames;
308     int m_frameX;
309     int m_frameY;
310     qreal m_frameRate;
311     qreal m_frameRateVariation;
312     int m_frameDuration;
313     int m_frameDurationVariation;
314     bool m_frameSync;
315     QDeclarativePixmap m_pix;
316 };
317
318 QT_END_NAMESPACE
319 QT_END_HEADER
320 #endif // QQUICKSPRITE_P_H