Rename Qt Quick-specific classes to QQuick*
[profile/ivi/qtdeclarative.git] / src / declarative / particles / qsgparticleemitter_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Declarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef PARTICLEEMITTER_H
43 #define PARTICLEEMITTER_H
44
45 #include <QQuickItem>
46 #include <QDebug>
47 #include "qsgparticlesystem_p.h"
48 #include "qsgparticleextruder_p.h"
49 #include "qsgdirection_p.h"
50
51 #include <QList>
52 #include <QPair>
53 #include <QPointF>
54 QT_BEGIN_HEADER
55
56 QT_BEGIN_NAMESPACE
57
58 QT_MODULE(Declarative)
59
60 class QSGParticleEmitter : public QQuickItem
61 {
62     Q_OBJECT
63     Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
64     Q_PROPERTY(QString group READ group WRITE setGroup NOTIFY groupChanged)
65     Q_PROPERTY(QSGParticleExtruder* shape READ extruder WRITE setExtruder NOTIFY extruderChanged)
66     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
67     Q_PROPERTY(int startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged)
68
69     Q_PROPERTY(qreal emitRate READ particlesPerSecond WRITE setParticlesPerSecond NOTIFY particlesPerSecondChanged)
70     Q_PROPERTY(int lifeSpan READ particleDuration WRITE setParticleDuration NOTIFY particleDurationChanged)
71     Q_PROPERTY(int lifeSpanVariation READ particleDurationVariation WRITE setParticleDurationVariation NOTIFY particleDurationVariationChanged)
72     Q_PROPERTY(int maximumEmitted READ maxParticleCount WRITE setMaxParticleCount NOTIFY maximumEmittedChanged)
73
74     Q_PROPERTY(qreal size READ particleSize WRITE setParticleSize NOTIFY particleSizeChanged)
75     Q_PROPERTY(qreal endSize READ particleEndSize WRITE setParticleEndSize NOTIFY particleEndSizeChanged)
76     Q_PROPERTY(qreal sizeVariation READ particleSizeVariation WRITE setParticleSizeVariation NOTIFY particleSizeVariationChanged)
77
78     Q_PROPERTY(QSGDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged)
79     Q_PROPERTY(QSGDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
80     Q_PROPERTY(qreal speedFromMovement READ speedFromMovement WRITE setSpeedFromMovement NOTIFY speedFromMovementChanged)
81
82     Q_ENUMS(Lifetime)
83 public:
84     explicit QSGParticleEmitter(QQuickItem *parent = 0);
85     virtual ~QSGParticleEmitter();
86     virtual void emitWindow(int timeStamp);
87
88     enum Lifetime {
89         InfiniteLife = QSGParticleSystem::maxLife
90     };
91
92     bool enabled() const
93     {
94         return m_enabled;
95     }
96
97     qreal particlesPerSecond() const
98     {
99         return m_particlesPerSecond;
100     }
101
102     int particleDuration() const
103     {
104         return m_particleDuration;
105     }
106
107     QSGParticleSystem* system() const
108     {
109         return m_system;
110     }
111
112     QString group() const
113     {
114         return m_group;
115     }
116
117     int particleDurationVariation() const
118     {
119         return m_particleDurationVariation;
120     }
121
122     qreal speedFromMovement() const { return m_speed_from_movement; }
123     void setSpeedFromMovement(qreal s);
124     virtual void componentComplete();
125 signals:
126     void emitParticles(QDeclarativeV8Handle particles);
127     void particlesPerSecondChanged(qreal);
128     void particleDurationChanged(int);
129     void enabledChanged(bool);
130
131     void systemChanged(QSGParticleSystem* arg);
132
133     void groupChanged(QString arg);
134
135     void particleDurationVariationChanged(int arg);
136
137     void extruderChanged(QSGParticleExtruder* arg);
138
139     void particleSizeChanged(qreal arg);
140
141     void particleEndSizeChanged(qreal arg);
142
143     void particleSizeVariationChanged(qreal arg);
144
145     void speedChanged(QSGDirection * arg);
146
147     void accelerationChanged(QSGDirection * arg);
148
149     void maximumEmittedChanged(int arg);
150     void particleCountChanged();
151
152     void speedFromMovementChanged();
153
154     void startTimeChanged(int arg);
155
156 public slots:
157     void pulse(int milliseconds);
158     void burst(int num);
159     void burst(int num, qreal x, qreal y);
160
161     void setEnabled(bool arg);
162
163     void setParticlesPerSecond(qreal arg)
164     {
165         if (m_particlesPerSecond != arg) {
166             m_particlesPerSecond = arg;
167             emit particlesPerSecondChanged(arg);
168         }
169     }
170
171     void setParticleDuration(int arg)
172     {
173         if (m_particleDuration != arg) {
174             m_particleDuration = arg;
175             emit particleDurationChanged(arg);
176         }
177     }
178
179     void setSystem(QSGParticleSystem* arg)
180     {
181         if (m_system != arg) {
182             m_system = arg;
183             m_system->registerParticleEmitter(this);
184             emit systemChanged(arg);
185         }
186     }
187
188     void setGroup(QString arg)
189     {
190         if (m_group != arg) {
191             m_group = arg;
192             emit groupChanged(arg);
193         }
194     }
195
196     void setParticleDurationVariation(int arg)
197     {
198         if (m_particleDurationVariation != arg) {
199             m_particleDurationVariation = arg;
200             emit particleDurationVariationChanged(arg);
201         }
202     }
203     void setExtruder(QSGParticleExtruder* arg)
204     {
205         if (m_extruder != arg) {
206             m_extruder = arg;
207             emit extruderChanged(arg);
208         }
209     }
210
211     void setParticleSize(qreal arg)
212     {
213         if (m_particleSize != arg) {
214             m_particleSize = arg;
215             emit particleSizeChanged(arg);
216         }
217     }
218
219     void setParticleEndSize(qreal arg)
220     {
221         if (m_particleEndSize != arg) {
222             m_particleEndSize = arg;
223             emit particleEndSizeChanged(arg);
224         }
225     }
226
227     void setParticleSizeVariation(qreal arg)
228     {
229         if (m_particleSizeVariation != arg) {
230             m_particleSizeVariation = arg;
231             emit particleSizeVariationChanged(arg);
232         }
233     }
234
235     void setSpeed(QSGDirection * arg)
236     {
237         if (m_speed != arg) {
238             m_speed = arg;
239             emit speedChanged(arg);
240         }
241     }
242
243     void setAcceleration(QSGDirection * arg)
244     {
245         if (m_acceleration != arg) {
246             m_acceleration = arg;
247             emit accelerationChanged(arg);
248         }
249     }
250
251     void setMaxParticleCount(int arg);
252
253     void setStartTime(int arg)
254     {
255         if (m_startTime != arg) {
256             m_startTime = arg;
257             emit startTimeChanged(arg);
258         }
259     }
260
261        virtual void reset();
262 public:
263        int particleCount() const;
264
265        QSGParticleExtruder* extruder() const
266        {
267            return m_extruder;
268        }
269
270        qreal particleSize() const
271        {
272            return m_particleSize;
273        }
274
275        qreal particleEndSize() const
276        {
277            return m_particleEndSize;
278        }
279
280        qreal particleSizeVariation() const
281        {
282            return m_particleSizeVariation;
283        }
284
285        QSGDirection * speed() const
286        {
287            return m_speed;
288        }
289
290        QSGDirection * acceleration() const
291        {
292            return m_acceleration;
293        }
294
295        int maxParticleCount() const
296        {
297            return m_maxParticleCount;
298        }
299
300        int startTime() const
301        {
302            return m_startTime;
303        }
304
305 protected:
306        qreal m_particlesPerSecond;
307        int m_particleDuration;
308        int m_particleDurationVariation;
309        bool m_enabled;
310        QSGParticleSystem* m_system;
311        QString m_group;
312        QSGParticleExtruder* m_extruder;
313        QSGParticleExtruder* m_defaultExtruder;
314        QSGParticleExtruder* effectiveExtruder();
315        QSGDirection * m_speed;
316        QSGDirection * m_acceleration;
317        qreal m_particleSize;
318        qreal m_particleEndSize;
319        qreal m_particleSizeVariation;
320
321        qreal m_speedFromMovement;
322        int m_startTime;
323        bool m_overwrite;
324
325        int m_pulseLeft;
326        QList<QPair<int, QPointF > > m_burstQueue;
327        int m_maxParticleCount;
328
329        //Used in default implementation, but might be useful
330        qreal m_speed_from_movement;
331
332        int m_emitCap;
333        bool m_reset_last;
334        qreal m_last_timestamp;
335        qreal m_last_emission;
336
337        QPointF m_last_emitter;
338        QPointF m_last_last_emitter;
339        QPointF m_last_last_last_emitter;
340
341        bool isEmitConnected();
342 private:
343        QSGDirection m_nullVector;
344
345 };
346
347 QT_END_NAMESPACE
348
349 QT_END_HEADER
350
351 #endif // PARTICLEEMITTER_H