Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / particles / qquickparticleemitter_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 PARTICLEEMITTER_H
43 #define PARTICLEEMITTER_H
44
45 #include <QtQuick/QQuickItem>
46 #include <QDebug>
47 #include "qquickparticlesystem_p.h"
48 #include "qquickparticleextruder_p.h"
49 #include "qquickdirection_p.h"
50
51 #include <QList>
52 #include <QPair>
53 #include <QPointF>
54 QT_BEGIN_HEADER
55
56 QT_BEGIN_NAMESPACE
57
58 class QQuickParticleEmitter : public QQuickItem
59 {
60     Q_OBJECT
61     Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
62     Q_PROPERTY(QString group READ group WRITE setGroup NOTIFY groupChanged)
63     Q_PROPERTY(QQuickParticleExtruder* shape READ extruder WRITE setExtruder NOTIFY extruderChanged)
64     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
65     Q_PROPERTY(int startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged)
66
67     Q_PROPERTY(qreal emitRate READ particlesPerSecond WRITE setParticlesPerSecond NOTIFY particlesPerSecondChanged)
68     Q_PROPERTY(int lifeSpan READ particleDuration WRITE setParticleDuration NOTIFY particleDurationChanged)
69     Q_PROPERTY(int lifeSpanVariation READ particleDurationVariation WRITE setParticleDurationVariation NOTIFY particleDurationVariationChanged)
70     Q_PROPERTY(int maximumEmitted READ maxParticleCount WRITE setMaxParticleCount NOTIFY maximumEmittedChanged)
71
72     Q_PROPERTY(qreal size READ particleSize WRITE setParticleSize NOTIFY particleSizeChanged)
73     Q_PROPERTY(qreal endSize READ particleEndSize WRITE setParticleEndSize NOTIFY particleEndSizeChanged)
74     Q_PROPERTY(qreal sizeVariation READ particleSizeVariation WRITE setParticleSizeVariation NOTIFY particleSizeVariationChanged)
75
76     Q_PROPERTY(QQuickDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged)
77     Q_PROPERTY(QQuickDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
78     Q_PROPERTY(qreal speedFromMovement READ speedFromMovement WRITE setSpeedFromMovement NOTIFY speedFromMovementChanged)
79
80     Q_ENUMS(Lifetime)
81 public:
82     explicit QQuickParticleEmitter(QQuickItem *parent = 0);
83     virtual ~QQuickParticleEmitter();
84     virtual void emitWindow(int timeStamp);
85
86     enum Lifetime {
87         InfiniteLife = QQuickParticleSystem::maxLife
88     };
89
90     bool enabled() const
91     {
92         return m_enabled;
93     }
94
95     qreal particlesPerSecond() const
96     {
97         return m_particlesPerSecond;
98     }
99
100     int particleDuration() const
101     {
102         return m_particleDuration;
103     }
104
105     QQuickParticleSystem* system() const
106     {
107         return m_system;
108     }
109
110     QString group() const
111     {
112         return m_group;
113     }
114
115     int particleDurationVariation() const
116     {
117         return m_particleDurationVariation;
118     }
119
120     qreal speedFromMovement() const { return m_speed_from_movement; }
121     void setSpeedFromMovement(qreal s);
122     virtual void componentComplete();
123 signals:
124     void emitParticles(QDeclarativeV8Handle particles);
125     void particlesPerSecondChanged(qreal);
126     void particleDurationChanged(int);
127     void enabledChanged(bool);
128
129     void systemChanged(QQuickParticleSystem* arg);
130
131     void groupChanged(QString arg);
132
133     void particleDurationVariationChanged(int arg);
134
135     void extruderChanged(QQuickParticleExtruder* arg);
136
137     void particleSizeChanged(qreal arg);
138
139     void particleEndSizeChanged(qreal arg);
140
141     void particleSizeVariationChanged(qreal arg);
142
143     void speedChanged(QQuickDirection * arg);
144
145     void accelerationChanged(QQuickDirection * arg);
146
147     void maximumEmittedChanged(int arg);
148     void particleCountChanged();
149
150     void speedFromMovementChanged();
151
152     void startTimeChanged(int arg);
153
154 public slots:
155     void pulse(int milliseconds);
156     void burst(int num);
157     void burst(int num, qreal x, qreal y);
158
159     void setEnabled(bool arg);
160
161     void setParticlesPerSecond(qreal arg)
162     {
163         if (m_particlesPerSecond != arg) {
164             m_particlesPerSecond = arg;
165             emit particlesPerSecondChanged(arg);
166         }
167     }
168
169     void setParticleDuration(int arg)
170     {
171         if (m_particleDuration != arg) {
172             m_particleDuration = arg;
173             emit particleDurationChanged(arg);
174         }
175     }
176
177     void setSystem(QQuickParticleSystem* arg)
178     {
179         if (m_system != arg) {
180             m_system = arg;
181             m_system->registerParticleEmitter(this);
182             emit systemChanged(arg);
183         }
184     }
185
186     void setGroup(QString arg)
187     {
188         if (m_group != arg) {
189             m_group = arg;
190             emit groupChanged(arg);
191         }
192     }
193
194     void setParticleDurationVariation(int arg)
195     {
196         if (m_particleDurationVariation != arg) {
197             m_particleDurationVariation = arg;
198             emit particleDurationVariationChanged(arg);
199         }
200     }
201     void setExtruder(QQuickParticleExtruder* arg)
202     {
203         if (m_extruder != arg) {
204             m_extruder = arg;
205             emit extruderChanged(arg);
206         }
207     }
208
209     void setParticleSize(qreal arg)
210     {
211         if (m_particleSize != arg) {
212             m_particleSize = arg;
213             emit particleSizeChanged(arg);
214         }
215     }
216
217     void setParticleEndSize(qreal arg)
218     {
219         if (m_particleEndSize != arg) {
220             m_particleEndSize = arg;
221             emit particleEndSizeChanged(arg);
222         }
223     }
224
225     void setParticleSizeVariation(qreal arg)
226     {
227         if (m_particleSizeVariation != arg) {
228             m_particleSizeVariation = arg;
229             emit particleSizeVariationChanged(arg);
230         }
231     }
232
233     void setSpeed(QQuickDirection * arg)
234     {
235         if (m_speed != arg) {
236             m_speed = arg;
237             emit speedChanged(arg);
238         }
239     }
240
241     void setAcceleration(QQuickDirection * arg)
242     {
243         if (m_acceleration != arg) {
244             m_acceleration = arg;
245             emit accelerationChanged(arg);
246         }
247     }
248
249     void setMaxParticleCount(int arg);
250
251     void setStartTime(int arg)
252     {
253         if (m_startTime != arg) {
254             m_startTime = arg;
255             emit startTimeChanged(arg);
256         }
257     }
258
259        virtual void reset();
260 public:
261        int particleCount() const;
262
263        QQuickParticleExtruder* extruder() const
264        {
265            return m_extruder;
266        }
267
268        qreal particleSize() const
269        {
270            return m_particleSize;
271        }
272
273        qreal particleEndSize() const
274        {
275            return m_particleEndSize;
276        }
277
278        qreal particleSizeVariation() const
279        {
280            return m_particleSizeVariation;
281        }
282
283        QQuickDirection * speed() const
284        {
285            return m_speed;
286        }
287
288        QQuickDirection * acceleration() const
289        {
290            return m_acceleration;
291        }
292
293        int maxParticleCount() const
294        {
295            return m_maxParticleCount;
296        }
297
298        int startTime() const
299        {
300            return m_startTime;
301        }
302
303 protected:
304        qreal m_particlesPerSecond;
305        int m_particleDuration;
306        int m_particleDurationVariation;
307        bool m_enabled;
308        QQuickParticleSystem* m_system;
309        QString m_group;
310        QQuickParticleExtruder* m_extruder;
311        QQuickParticleExtruder* m_defaultExtruder;
312        QQuickParticleExtruder* effectiveExtruder();
313        QQuickDirection * m_speed;
314        QQuickDirection * m_acceleration;
315        qreal m_particleSize;
316        qreal m_particleEndSize;
317        qreal m_particleSizeVariation;
318
319        qreal m_speedFromMovement;
320        int m_startTime;
321        bool m_overwrite;
322
323        int m_pulseLeft;
324        QList<QPair<int, QPointF > > m_burstQueue;
325        int m_maxParticleCount;
326
327        //Used in default implementation, but might be useful
328        qreal m_speed_from_movement;
329
330        int m_emitCap;
331        bool m_reset_last;
332        qreal m_last_timestamp;
333        qreal m_last_emission;
334
335        QPointF m_last_emitter;
336        QPointF m_last_last_emitter;
337        QPointF m_last_last_last_emitter;
338
339        bool isEmitConnected();
340 private:
341        QQuickDirection m_nullVector;
342
343 };
344
345 QT_END_NAMESPACE
346
347 QT_END_HEADER
348
349 #endif // PARTICLEEMITTER_H