1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Declarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef PARTICLEEMITTER_H
43 #define PARTICLEEMITTER_H
47 #include "qsgparticlesystem_p.h"
48 #include "qsgparticleextruder_p.h"
49 #include "qsgstochasticdirection_p.h"
58 QT_MODULE(Declarative)
60 class QSGParticleEmitter : public QSGItem
63 //###currently goes in emitters OR sets system. Pick one?
64 Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
65 Q_PROPERTY(QString particle READ particle WRITE setParticle NOTIFY particleChanged)
66 Q_PROPERTY(QSGParticleExtruder* shape READ extruder WRITE setExtruder NOTIFY extruderChanged)
67 Q_PROPERTY(bool emitting READ emitting WRITE setEmitting NOTIFY emittingChanged)
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 emitCap READ maxParticleCount WRITE setMaxParticleCount NOTIFY maxParticleCountChanged)
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)
78 Q_PROPERTY(QSGStochasticDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged)
79 Q_PROPERTY(QSGStochasticDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
81 explicit QSGParticleEmitter(QSGItem *parent = 0);
82 virtual ~QSGParticleEmitter();
83 virtual void emitWindow(int timeStamp);
90 qreal particlesPerSecond() const
92 return m_particlesPerSecond;
95 int particleDuration() const
97 return m_particleDuration;
100 QSGParticleSystem* system() const
105 QString particle() const
110 int particleDurationVariation() const
112 return m_particleDurationVariation;
115 virtual void componentComplete();
117 void particlesPerSecondChanged(qreal);
118 void particleDurationChanged(int);
119 void emittingChanged(bool);
121 void systemChanged(QSGParticleSystem* arg);
123 void particleChanged(QString arg);
125 void particleDurationVariationChanged(int arg);
127 void extruderChanged(QSGParticleExtruder* arg);
129 void particleSizeChanged(qreal arg);
131 void particleEndSizeChanged(qreal arg);
133 void particleSizeVariationChanged(qreal arg);
135 void speedChanged(QSGStochasticDirection * arg);
137 void accelerationChanged(QSGStochasticDirection * arg);
139 void maxParticleCountChanged(int arg);
140 void particleCountChanged();
143 void pulse(qreal seconds);
145 void burst(int num, qreal x, qreal y);
147 void setEmitting(bool arg);
149 void setParticlesPerSecond(qreal arg)
151 if (m_particlesPerSecond != arg) {
152 m_particlesPerSecond = arg;
153 emit particlesPerSecondChanged(arg);
157 void setParticleDuration(int arg)
159 if (m_particleDuration != arg) {
160 m_particleDuration = arg;
161 emit particleDurationChanged(arg);
165 void setSystem(QSGParticleSystem* arg)
167 if (m_system != arg) {
169 m_system->registerParticleEmitter(this);
170 emit systemChanged(arg);
174 void setParticle(QString arg)
176 if (m_particle != arg) {
178 emit particleChanged(arg);
182 void setParticleDurationVariation(int arg)
184 if (m_particleDurationVariation != arg) {
185 m_particleDurationVariation = arg;
186 emit particleDurationVariationChanged(arg);
189 void setExtruder(QSGParticleExtruder* arg)
191 if (m_extruder != arg) {
193 emit extruderChanged(arg);
197 void setParticleSize(qreal arg)
199 if (m_particleSize != arg) {
200 m_particleSize = arg;
201 emit particleSizeChanged(arg);
205 void setParticleEndSize(qreal arg)
207 if (m_particleEndSize != arg) {
208 m_particleEndSize = arg;
209 emit particleEndSizeChanged(arg);
213 void setParticleSizeVariation(qreal arg)
215 if (m_particleSizeVariation != arg) {
216 m_particleSizeVariation = arg;
217 emit particleSizeVariationChanged(arg);
221 void setSpeed(QSGStochasticDirection * arg)
223 if (m_speed != arg) {
225 emit speedChanged(arg);
229 void setAcceleration(QSGStochasticDirection * arg)
231 if (m_acceleration != arg) {
232 m_acceleration = arg;
233 emit accelerationChanged(arg);
237 void setMaxParticleCount(int arg);
240 int particleCount() const;
242 virtual void reset(){;}
243 QSGParticleExtruder* extruder() const
248 qreal particleSize() const
250 return m_particleSize;
253 qreal particleEndSize() const
255 return m_particleEndSize;
258 qreal particleSizeVariation() const
260 return m_particleSizeVariation;
263 QSGStochasticDirection * speed() const
268 QSGStochasticDirection * acceleration() const
270 return m_acceleration;
273 int maxParticleCount() const
275 return m_maxParticleCount;
279 qreal m_particlesPerSecond;
280 int m_particleDuration;
281 int m_particleDurationVariation;
283 QSGParticleSystem* m_system;
285 QSGParticleExtruder* m_extruder;
286 QSGParticleExtruder* m_defaultExtruder;
287 QSGParticleExtruder* effectiveExtruder();
288 QSGStochasticDirection * m_speed;
289 QSGStochasticDirection * m_acceleration;
290 qreal m_particleSize;
291 qreal m_particleEndSize;
292 qreal m_particleSizeVariation;
294 int m_burstLeft;//TODO: Rename to pulse
295 QList<QPair<int, QPointF > > m_burstQueue;
296 int m_maxParticleCount;
298 QSGStochasticDirection m_nullVector;
305 #endif // PARTICLEEMITTER_H