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 ** 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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef PARTICLEEMITTER_H
43 #define PARTICLEEMITTER_H
47 #include "qsgparticlesystem_p.h"
48 #include "qsgparticleextruder_p.h"
49 #include "qsgdirection_p.h"
58 QT_MODULE(Declarative)
60 class QSGParticleEmitter : public QQuickItem
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)
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)
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(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)
84 explicit QSGParticleEmitter(QQuickItem *parent = 0);
85 virtual ~QSGParticleEmitter();
86 virtual void emitWindow(int timeStamp);
89 InfiniteLife = QSGParticleSystem::maxLife
97 qreal particlesPerSecond() const
99 return m_particlesPerSecond;
102 int particleDuration() const
104 return m_particleDuration;
107 QSGParticleSystem* system() const
112 QString group() const
117 int particleDurationVariation() const
119 return m_particleDurationVariation;
122 qreal speedFromMovement() const { return m_speed_from_movement; }
123 void setSpeedFromMovement(qreal s);
124 virtual void componentComplete();
126 void emitParticles(QDeclarativeV8Handle particles);
127 void particlesPerSecondChanged(qreal);
128 void particleDurationChanged(int);
129 void enabledChanged(bool);
131 void systemChanged(QSGParticleSystem* arg);
133 void groupChanged(QString arg);
135 void particleDurationVariationChanged(int arg);
137 void extruderChanged(QSGParticleExtruder* arg);
139 void particleSizeChanged(qreal arg);
141 void particleEndSizeChanged(qreal arg);
143 void particleSizeVariationChanged(qreal arg);
145 void speedChanged(QSGDirection * arg);
147 void accelerationChanged(QSGDirection * arg);
149 void maximumEmittedChanged(int arg);
150 void particleCountChanged();
152 void speedFromMovementChanged();
154 void startTimeChanged(int arg);
157 void pulse(int milliseconds);
159 void burst(int num, qreal x, qreal y);
161 void setEnabled(bool arg);
163 void setParticlesPerSecond(qreal arg)
165 if (m_particlesPerSecond != arg) {
166 m_particlesPerSecond = arg;
167 emit particlesPerSecondChanged(arg);
171 void setParticleDuration(int arg)
173 if (m_particleDuration != arg) {
174 m_particleDuration = arg;
175 emit particleDurationChanged(arg);
179 void setSystem(QSGParticleSystem* arg)
181 if (m_system != arg) {
183 m_system->registerParticleEmitter(this);
184 emit systemChanged(arg);
188 void setGroup(QString arg)
190 if (m_group != arg) {
192 emit groupChanged(arg);
196 void setParticleDurationVariation(int arg)
198 if (m_particleDurationVariation != arg) {
199 m_particleDurationVariation = arg;
200 emit particleDurationVariationChanged(arg);
203 void setExtruder(QSGParticleExtruder* arg)
205 if (m_extruder != arg) {
207 emit extruderChanged(arg);
211 void setParticleSize(qreal arg)
213 if (m_particleSize != arg) {
214 m_particleSize = arg;
215 emit particleSizeChanged(arg);
219 void setParticleEndSize(qreal arg)
221 if (m_particleEndSize != arg) {
222 m_particleEndSize = arg;
223 emit particleEndSizeChanged(arg);
227 void setParticleSizeVariation(qreal arg)
229 if (m_particleSizeVariation != arg) {
230 m_particleSizeVariation = arg;
231 emit particleSizeVariationChanged(arg);
235 void setSpeed(QSGDirection * arg)
237 if (m_speed != arg) {
239 emit speedChanged(arg);
243 void setAcceleration(QSGDirection * arg)
245 if (m_acceleration != arg) {
246 m_acceleration = arg;
247 emit accelerationChanged(arg);
251 void setMaxParticleCount(int arg);
253 void setStartTime(int arg)
255 if (m_startTime != arg) {
257 emit startTimeChanged(arg);
261 virtual void reset();
263 int particleCount() const;
265 QSGParticleExtruder* extruder() const
270 qreal particleSize() const
272 return m_particleSize;
275 qreal particleEndSize() const
277 return m_particleEndSize;
280 qreal particleSizeVariation() const
282 return m_particleSizeVariation;
285 QSGDirection * speed() const
290 QSGDirection * acceleration() const
292 return m_acceleration;
295 int maxParticleCount() const
297 return m_maxParticleCount;
300 int startTime() const
306 qreal m_particlesPerSecond;
307 int m_particleDuration;
308 int m_particleDurationVariation;
310 QSGParticleSystem* m_system;
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;
321 qreal m_speedFromMovement;
326 QList<QPair<int, QPointF > > m_burstQueue;
327 int m_maxParticleCount;
329 //Used in default implementation, but might be useful
330 qreal m_speed_from_movement;
334 qreal m_last_timestamp;
335 qreal m_last_emission;
337 QPointF m_last_emitter;
338 QPointF m_last_last_emitter;
339 QPointF m_last_last_last_emitter;
341 bool isEmitConnected();
343 QSGDirection m_nullVector;
351 #endif // PARTICLEEMITTER_H