1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the Declarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef PARTICLEEMITTER_H
43 #define PARTICLEEMITTER_H
45 #include <QtQuick/QQuickItem>
47 #include "qquickparticlesystem_p.h"
48 #include "qquickparticleextruder_p.h"
49 #include "qquickdirection_p.h"
58 class QQuickParticleEmitter : public QQuickItem
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)
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)
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)
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)
82 explicit QQuickParticleEmitter(QQuickItem *parent = 0);
83 virtual ~QQuickParticleEmitter();
84 virtual void emitWindow(int timeStamp);
87 InfiniteLife = QQuickParticleSystem::maxLife
95 qreal particlesPerSecond() const
97 return m_particlesPerSecond;
100 int particleDuration() const
102 return m_particleDuration;
105 QQuickParticleSystem* system() const
110 QString group() const
115 int particleDurationVariation() const
117 return m_particleDurationVariation;
120 qreal speedFromMovement() const { return m_speed_from_movement; }
121 void setSpeedFromMovement(qreal s);
122 virtual void componentComplete();
124 void emitParticles(QDeclarativeV8Handle particles);
125 void particlesPerSecondChanged(qreal);
126 void particleDurationChanged(int);
127 void enabledChanged(bool);
129 void systemChanged(QQuickParticleSystem* arg);
131 void groupChanged(QString arg);
133 void particleDurationVariationChanged(int arg);
135 void extruderChanged(QQuickParticleExtruder* arg);
137 void particleSizeChanged(qreal arg);
139 void particleEndSizeChanged(qreal arg);
141 void particleSizeVariationChanged(qreal arg);
143 void speedChanged(QQuickDirection * arg);
145 void accelerationChanged(QQuickDirection * arg);
147 void maximumEmittedChanged(int arg);
148 void particleCountChanged();
150 void speedFromMovementChanged();
152 void startTimeChanged(int arg);
155 void pulse(int milliseconds);
157 void burst(int num, qreal x, qreal y);
159 void setEnabled(bool arg);
161 void setParticlesPerSecond(qreal arg)
163 if (m_particlesPerSecond != arg) {
164 m_particlesPerSecond = arg;
165 emit particlesPerSecondChanged(arg);
169 void setParticleDuration(int arg)
171 if (m_particleDuration != arg) {
172 m_particleDuration = arg;
173 emit particleDurationChanged(arg);
177 void setSystem(QQuickParticleSystem* arg)
179 if (m_system != arg) {
181 m_system->registerParticleEmitter(this);
182 emit systemChanged(arg);
186 void setGroup(QString arg)
188 if (m_group != arg) {
190 emit groupChanged(arg);
194 void setParticleDurationVariation(int arg)
196 if (m_particleDurationVariation != arg) {
197 m_particleDurationVariation = arg;
198 emit particleDurationVariationChanged(arg);
201 void setExtruder(QQuickParticleExtruder* arg)
203 if (m_extruder != arg) {
205 emit extruderChanged(arg);
209 void setParticleSize(qreal arg)
211 if (m_particleSize != arg) {
212 m_particleSize = arg;
213 emit particleSizeChanged(arg);
217 void setParticleEndSize(qreal arg)
219 if (m_particleEndSize != arg) {
220 m_particleEndSize = arg;
221 emit particleEndSizeChanged(arg);
225 void setParticleSizeVariation(qreal arg)
227 if (m_particleSizeVariation != arg) {
228 m_particleSizeVariation = arg;
229 emit particleSizeVariationChanged(arg);
233 void setSpeed(QQuickDirection * arg)
235 if (m_speed != arg) {
237 emit speedChanged(arg);
241 void setAcceleration(QQuickDirection * arg)
243 if (m_acceleration != arg) {
244 m_acceleration = arg;
245 emit accelerationChanged(arg);
249 void setMaxParticleCount(int arg);
251 void setStartTime(int arg)
253 if (m_startTime != arg) {
255 emit startTimeChanged(arg);
259 virtual void reset();
261 int particleCount() const;
263 QQuickParticleExtruder* extruder() const
268 qreal particleSize() const
270 return m_particleSize;
273 qreal particleEndSize() const
275 return m_particleEndSize;
278 qreal particleSizeVariation() const
280 return m_particleSizeVariation;
283 QQuickDirection * speed() const
288 QQuickDirection * acceleration() const
290 return m_acceleration;
293 int maxParticleCount() const
295 return m_maxParticleCount;
298 int startTime() const
304 qreal m_particlesPerSecond;
305 int m_particleDuration;
306 int m_particleDurationVariation;
308 QQuickParticleSystem* m_system;
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;
319 qreal m_speedFromMovement;
324 QList<QPair<int, QPointF > > m_burstQueue;
325 int m_maxParticleCount;
327 //Used in default implementation, but might be useful
328 qreal m_speed_from_movement;
332 qreal m_last_timestamp;
333 qreal m_last_emission;
335 QPointF m_last_emitter;
336 QPointF m_last_last_emitter;
337 QPointF m_last_last_last_emitter;
339 bool isEmitConnected();
341 QQuickDirection m_nullVector;
349 #endif // PARTICLEEMITTER_H