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 #include "particleemitter.h"
44 ParticleEmitter::ParticleEmitter(QSGItem *parent) :
46 , m_particlesPerSecond(10)
47 , m_particleDuration(1000)
48 , m_particleDurationVariation(0)
52 , m_defaultExtruder(0)
53 , m_speed(&m_nullVector)
54 , m_acceleration(&m_nullVector)
56 , m_particleEndSize(-1)
57 , m_particleSizeVariation(0)
58 , m_maxParticleCount(-1)
63 //TODO: Reset speed/acc back to null vector? Or allow null pointer?
64 connect(this, SIGNAL(maxParticleCountChanged(int)),
65 this, SIGNAL(particleCountChanged()));
66 connect(this, SIGNAL(particlesPerSecondChanged(qreal)),
67 this, SIGNAL(particleCountChanged()));
68 connect(this, SIGNAL(particleDurationChanged(int)),
69 this, SIGNAL(particleCountChanged()));
72 ParticleEmitter::~ParticleEmitter()
75 delete m_defaultExtruder;
78 void ParticleEmitter::componentComplete()
81 qWarning() << "Emitter created without a particle system specified";//TODO: useful QML warnings, like line number?
82 QSGItem::componentComplete();
84 void ParticleEmitter::emitWindow(int timeStamp)
90 void ParticleEmitter::setEmitting(bool arg)
92 if (m_emitting != arg) {
94 emit emittingChanged(arg);
99 ParticleExtruder* ParticleEmitter::effectiveExtruder()
103 if(!m_defaultExtruder)
104 m_defaultExtruder = new ParticleExtruder;
105 return m_defaultExtruder;
108 void ParticleEmitter::pulse(qreal seconds)
111 qWarning() << "pulse called on an emitter with a particle count of zero";
113 m_burstLeft = seconds*1000.0;//TODO: Change name to match
116 void ParticleEmitter::burst(int num)
119 qWarning() << "burst called on an emitter with a particle count of zero";
123 void ParticleEmitter::setMaxParticleCount(int arg)
125 if (m_maxParticleCount != arg) {
126 if(arg < 0 && m_maxParticleCount >= 0){
127 connect(this, SIGNAL(particlesPerSecondChanged(qreal)),
128 this, SIGNAL(particleCountChanged()));
129 connect(this, SIGNAL(particleDurationChanged(int)),
130 this, SIGNAL(particleCountChanged()));
131 }else if(arg >= 0 && m_maxParticleCount < 0){
132 disconnect(this, SIGNAL(particlesPerSecondChanged(qreal)),
133 this, SIGNAL(particleCountChanged()));
134 disconnect(this, SIGNAL(particleDurationChanged(int)),
135 this, SIGNAL(particleCountChanged()));
137 m_maxParticleCount = arg;
138 emit maxParticleCountChanged(arg);
142 int ParticleEmitter::particleCount() const
144 if(m_maxParticleCount >= 0)
145 return m_maxParticleCount;
146 return m_particlesPerSecond*((m_particleDuration+m_particleDurationVariation)/1000.0);