~loic.molinari/+junk/qtdeclarative-shadereffectsource-changes

« back to all changes in this revision

Viewing changes to src/particles/qquickparticleemitter_p.h

  • Committer: Loïc Molinari
  • Date: 2012-04-21 17:59:51 UTC
  • Revision ID: loic.molinari@canonical.com-20120421175951-bqx68caaf5zrp76l
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/
 
5
**
 
6
** This file is part of the QtQuick module of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
20
**
 
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.
 
28
**
 
29
** Other Usage
 
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.
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef PARTICLEEMITTER_H
 
43
#define PARTICLEEMITTER_H
 
44
 
 
45
#include <QtQuick/QQuickItem>
 
46
#include <QDebug>
 
47
#include "qquickparticlesystem_p.h"
 
48
#include "qquickparticleextruder_p.h"
 
49
#include "qquickdirection_p.h"
 
50
 
 
51
#include <QList>
 
52
#include <QPair>
 
53
#include <QPointF>
 
54
QT_BEGIN_HEADER
 
55
 
 
56
QT_BEGIN_NAMESPACE
 
57
 
 
58
class QQuickParticleEmitter : public QQuickItem
 
59
{
 
60
    Q_OBJECT
 
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)
 
66
 
 
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)
 
71
 
 
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)
 
75
 
 
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)
 
79
 
 
80
    Q_ENUMS(Lifetime)
 
81
public:
 
82
    explicit QQuickParticleEmitter(QQuickItem *parent = 0);
 
83
    virtual ~QQuickParticleEmitter();
 
84
    virtual void emitWindow(int timeStamp);
 
85
 
 
86
    enum Lifetime {
 
87
        InfiniteLife = QQuickParticleSystem::maxLife
 
88
    };
 
89
 
 
90
    bool enabled() const
 
91
    {
 
92
        return m_enabled;
 
93
    }
 
94
 
 
95
    qreal particlesPerSecond() const
 
96
    {
 
97
        return m_particlesPerSecond;
 
98
    }
 
99
 
 
100
    int particleDuration() const
 
101
    {
 
102
        return m_particleDuration;
 
103
    }
 
104
 
 
105
    QQuickParticleSystem* system() const
 
106
    {
 
107
        return m_system;
 
108
    }
 
109
 
 
110
    QString group() const
 
111
    {
 
112
        return m_group;
 
113
    }
 
114
 
 
115
    int particleDurationVariation() const
 
116
    {
 
117
        return m_particleDurationVariation;
 
118
    }
 
119
 
 
120
    qreal speedFromMovement() const { return m_speed_from_movement; }
 
121
    void setSpeedFromMovement(qreal s);
 
122
    virtual void componentComplete();
 
123
signals:
 
124
    void emitParticles(QQmlV8Handle particles);
 
125
    void particlesPerSecondChanged(qreal);
 
126
    void particleDurationChanged(int);
 
127
    void enabledChanged(bool);
 
128
 
 
129
    void systemChanged(QQuickParticleSystem* arg);
 
130
 
 
131
    void groupChanged(QString arg);
 
132
 
 
133
    void particleDurationVariationChanged(int arg);
 
134
 
 
135
    void extruderChanged(QQuickParticleExtruder* arg);
 
136
 
 
137
    void particleSizeChanged(qreal arg);
 
138
 
 
139
    void particleEndSizeChanged(qreal arg);
 
140
 
 
141
    void particleSizeVariationChanged(qreal arg);
 
142
 
 
143
    void speedChanged(QQuickDirection * arg);
 
144
 
 
145
    void accelerationChanged(QQuickDirection * arg);
 
146
 
 
147
    void maximumEmittedChanged(int arg);
 
148
    void particleCountChanged();
 
149
 
 
150
    void speedFromMovementChanged();
 
151
 
 
152
    void startTimeChanged(int arg);
 
153
 
 
154
public slots:
 
155
    void pulse(int milliseconds);
 
156
    void burst(int num);
 
157
    void burst(int num, qreal x, qreal y);
 
158
 
 
159
    void setEnabled(bool arg);
 
160
 
 
161
    void setParticlesPerSecond(qreal arg)
 
162
    {
 
163
        if (m_particlesPerSecond != arg) {
 
164
            m_particlesPerSecond = arg;
 
165
            emit particlesPerSecondChanged(arg);
 
166
        }
 
167
    }
 
168
 
 
169
    void setParticleDuration(int arg)
 
170
    {
 
171
        if (m_particleDuration != arg) {
 
172
            m_particleDuration = arg;
 
173
            emit particleDurationChanged(arg);
 
174
        }
 
175
    }
 
176
 
 
177
    void setSystem(QQuickParticleSystem* arg)
 
178
    {
 
179
        if (m_system != arg) {
 
180
            m_system = arg;
 
181
            if (m_system)
 
182
                m_system->registerParticleEmitter(this);
 
183
            emit systemChanged(arg);
 
184
        }
 
185
    }
 
186
 
 
187
    void setGroup(QString arg)
 
188
    {
 
189
        if (m_group != arg) {
 
190
            m_group = arg;
 
191
            emit groupChanged(arg);
 
192
        }
 
193
    }
 
194
 
 
195
    void setParticleDurationVariation(int arg)
 
196
    {
 
197
        if (m_particleDurationVariation != arg) {
 
198
            m_particleDurationVariation = arg;
 
199
            emit particleDurationVariationChanged(arg);
 
200
        }
 
201
    }
 
202
    void setExtruder(QQuickParticleExtruder* arg)
 
203
    {
 
204
        if (m_extruder != arg) {
 
205
            m_extruder = arg;
 
206
            emit extruderChanged(arg);
 
207
        }
 
208
    }
 
209
 
 
210
    void setParticleSize(qreal arg)
 
211
    {
 
212
        if (m_particleSize != arg) {
 
213
            m_particleSize = arg;
 
214
            emit particleSizeChanged(arg);
 
215
        }
 
216
    }
 
217
 
 
218
    void setParticleEndSize(qreal arg)
 
219
    {
 
220
        if (m_particleEndSize != arg) {
 
221
            m_particleEndSize = arg;
 
222
            emit particleEndSizeChanged(arg);
 
223
        }
 
224
    }
 
225
 
 
226
    void setParticleSizeVariation(qreal arg)
 
227
    {
 
228
        if (m_particleSizeVariation != arg) {
 
229
            m_particleSizeVariation = arg;
 
230
            emit particleSizeVariationChanged(arg);
 
231
        }
 
232
    }
 
233
 
 
234
    void setSpeed(QQuickDirection * arg)
 
235
    {
 
236
        if (m_speed != arg) {
 
237
            m_speed = arg;
 
238
            emit speedChanged(arg);
 
239
        }
 
240
    }
 
241
 
 
242
    void setAcceleration(QQuickDirection * arg)
 
243
    {
 
244
        if (m_acceleration != arg) {
 
245
            m_acceleration = arg;
 
246
            emit accelerationChanged(arg);
 
247
        }
 
248
    }
 
249
 
 
250
    void setMaxParticleCount(int arg);
 
251
 
 
252
    void setStartTime(int arg)
 
253
    {
 
254
        if (m_startTime != arg) {
 
255
            m_startTime = arg;
 
256
            emit startTimeChanged(arg);
 
257
        }
 
258
    }
 
259
 
 
260
       virtual void reset();
 
261
public:
 
262
       int particleCount() const;
 
263
 
 
264
       QQuickParticleExtruder* extruder() const
 
265
       {
 
266
           return m_extruder;
 
267
       }
 
268
 
 
269
       qreal particleSize() const
 
270
       {
 
271
           return m_particleSize;
 
272
       }
 
273
 
 
274
       qreal particleEndSize() const
 
275
       {
 
276
           return m_particleEndSize;
 
277
       }
 
278
 
 
279
       qreal particleSizeVariation() const
 
280
       {
 
281
           return m_particleSizeVariation;
 
282
       }
 
283
 
 
284
       QQuickDirection * speed() const
 
285
       {
 
286
           return m_speed;
 
287
       }
 
288
 
 
289
       QQuickDirection * acceleration() const
 
290
       {
 
291
           return m_acceleration;
 
292
       }
 
293
 
 
294
       int maxParticleCount() const
 
295
       {
 
296
           return m_maxParticleCount;
 
297
       }
 
298
 
 
299
       int startTime() const
 
300
       {
 
301
           return m_startTime;
 
302
       }
 
303
 
 
304
protected:
 
305
       qreal m_particlesPerSecond;
 
306
       int m_particleDuration;
 
307
       int m_particleDurationVariation;
 
308
       bool m_enabled;
 
309
       QQuickParticleSystem* m_system;
 
310
       QString m_group;
 
311
       QQuickParticleExtruder* m_extruder;
 
312
       QQuickParticleExtruder* m_defaultExtruder;
 
313
       QQuickParticleExtruder* effectiveExtruder();
 
314
       QQuickDirection * m_speed;
 
315
       QQuickDirection * m_acceleration;
 
316
       qreal m_particleSize;
 
317
       qreal m_particleEndSize;
 
318
       qreal m_particleSizeVariation;
 
319
 
 
320
       qreal m_speedFromMovement;
 
321
       int m_startTime;
 
322
       bool m_overwrite;
 
323
 
 
324
       int m_pulseLeft;
 
325
       QList<QPair<int, QPointF > > m_burstQueue;
 
326
       int m_maxParticleCount;
 
327
 
 
328
       //Used in default implementation, but might be useful
 
329
       qreal m_speed_from_movement;
 
330
 
 
331
       int m_emitCap;
 
332
       bool m_reset_last;
 
333
       qreal m_last_timestamp;
 
334
       qreal m_last_emission;
 
335
 
 
336
       QPointF m_last_emitter;
 
337
       QPointF m_last_last_emitter;
 
338
       QPointF m_last_last_last_emitter;
 
339
 
 
340
       bool isEmitConnected();
 
341
private:
 
342
       QQuickDirection m_nullVector;
 
343
 
 
344
};
 
345
 
 
346
QT_END_NAMESPACE
 
347
 
 
348
QT_END_HEADER
 
349
 
 
350
#endif // PARTICLEEMITTER_H