65aca0c83e22c9f5985b05cfcbfecad3a5c7bbe2
[profile/ivi/qtdeclarative.git] / src / declarative / particles / qsgparticleemitter_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Declarative module of the Qt Toolkit.
8 **
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
14 ** this package.
15 **
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.
23 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef PARTICLEEMITTER_H
43 #define PARTICLEEMITTER_H
44
45 #include <QSGItem>
46 #include <QDebug>
47 #include "qsgparticlesystem_p.h"
48 #include "qsgparticleextruder_p.h"
49 #include "qsgstochasticdirection_p.h"
50
51 #include <QList>
52 #include <QPair>
53 #include <QPointF>
54 QT_BEGIN_HEADER
55
56 QT_BEGIN_NAMESPACE
57
58 QT_MODULE(Declarative)
59
60 class QSGParticleEmitter : public QSGItem
61 {
62     Q_OBJECT
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)
68
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)
73
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)
77
78     Q_PROPERTY(QSGStochasticDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged)
79     Q_PROPERTY(QSGStochasticDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
80 public:
81     explicit QSGParticleEmitter(QSGItem *parent = 0);
82     virtual ~QSGParticleEmitter();
83     virtual void emitWindow(int timeStamp);
84
85     bool emitting() const
86     {
87         return m_emitting;
88     }
89
90     qreal particlesPerSecond() const
91     {
92         return m_particlesPerSecond;
93     }
94
95     int particleDuration() const
96     {
97         return m_particleDuration;
98     }
99
100     QSGParticleSystem* system() const
101     {
102         return m_system;
103     }
104
105     QString particle() const
106     {
107         return m_particle;
108     }
109
110     int particleDurationVariation() const
111     {
112         return m_particleDurationVariation;
113     }
114
115     virtual void componentComplete();
116 signals:
117     void particlesPerSecondChanged(qreal);
118     void particleDurationChanged(int);
119     void emittingChanged(bool);
120
121     void systemChanged(QSGParticleSystem* arg);
122
123     void particleChanged(QString arg);
124
125     void particleDurationVariationChanged(int arg);
126
127     void extruderChanged(QSGParticleExtruder* arg);
128
129     void particleSizeChanged(qreal arg);
130
131     void particleEndSizeChanged(qreal arg);
132
133     void particleSizeVariationChanged(qreal arg);
134
135     void speedChanged(QSGStochasticDirection * arg);
136
137     void accelerationChanged(QSGStochasticDirection * arg);
138
139     void maxParticleCountChanged(int arg);
140     void particleCountChanged();
141
142 public slots:
143     void pulse(qreal seconds);
144     void burst(int num);
145     void burst(int num, qreal x, qreal y);
146
147     void setEmitting(bool arg);
148
149     void setParticlesPerSecond(qreal arg)
150     {
151         if (m_particlesPerSecond != arg) {
152             m_particlesPerSecond = arg;
153             emit particlesPerSecondChanged(arg);
154         }
155     }
156
157     void setParticleDuration(int arg)
158     {
159         if (m_particleDuration != arg) {
160             m_particleDuration = arg;
161             emit particleDurationChanged(arg);
162         }
163     }
164
165        void setSystem(QSGParticleSystem* arg)
166     {
167         if (m_system != arg) {
168             m_system = arg;
169             m_system->registerParticleEmitter(this);
170             emit systemChanged(arg);
171         }
172        }
173
174        void setParticle(QString arg)
175        {
176            if (m_particle != arg) {
177                m_particle = arg;
178                emit particleChanged(arg);
179            }
180        }
181
182        void setParticleDurationVariation(int arg)
183        {
184            if (m_particleDurationVariation != arg) {
185                m_particleDurationVariation = arg;
186                emit particleDurationVariationChanged(arg);
187            }
188        }
189        void setExtruder(QSGParticleExtruder* arg)
190        {
191            if (m_extruder != arg) {
192                m_extruder = arg;
193                emit extruderChanged(arg);
194            }
195        }
196
197        void setParticleSize(qreal arg)
198        {
199            if (m_particleSize != arg) {
200                m_particleSize = arg;
201                emit particleSizeChanged(arg);
202            }
203        }
204
205        void setParticleEndSize(qreal arg)
206        {
207            if (m_particleEndSize != arg) {
208                m_particleEndSize = arg;
209                emit particleEndSizeChanged(arg);
210            }
211        }
212
213        void setParticleSizeVariation(qreal arg)
214        {
215            if (m_particleSizeVariation != arg) {
216                m_particleSizeVariation = arg;
217                emit particleSizeVariationChanged(arg);
218            }
219        }
220
221        void setSpeed(QSGStochasticDirection * arg)
222        {
223            if (m_speed != arg) {
224                m_speed = arg;
225                emit speedChanged(arg);
226            }
227        }
228
229        void setAcceleration(QSGStochasticDirection * arg)
230        {
231            if (m_acceleration != arg) {
232                m_acceleration = arg;
233                emit accelerationChanged(arg);
234            }
235        }
236
237        void setMaxParticleCount(int arg);
238
239 public:
240        int particleCount() const;
241
242        virtual void reset(){;}
243        QSGParticleExtruder* extruder() const
244        {
245            return m_extruder;
246        }
247
248        qreal particleSize() const
249        {
250            return m_particleSize;
251        }
252
253        qreal particleEndSize() const
254        {
255            return m_particleEndSize;
256        }
257
258        qreal particleSizeVariation() const
259        {
260            return m_particleSizeVariation;
261        }
262
263        QSGStochasticDirection * speed() const
264        {
265            return m_speed;
266        }
267
268        QSGStochasticDirection * acceleration() const
269        {
270            return m_acceleration;
271        }
272
273        int maxParticleCount() const
274        {
275            return m_maxParticleCount;
276        }
277
278 protected:
279        qreal m_particlesPerSecond;
280        int m_particleDuration;
281        int m_particleDurationVariation;
282        bool m_emitting;
283        QSGParticleSystem* m_system;
284        QString m_particle;
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;
293
294        int m_burstLeft;//TODO: Rename to pulse
295        QList<QPair<int, QPointF > > m_burstQueue;
296        int m_maxParticleCount;
297 private:
298        QSGStochasticDirection m_nullVector;
299 };
300
301 QT_END_NAMESPACE
302
303 QT_END_HEADER
304
305 #endif // PARTICLEEMITTER_H