1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative 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 QDECLARATIVEPARTICLES_H
43 #define QDECLARATIVEPARTICLES_H
45 #include <QtQuick1/qdeclarativeitem.h>
52 class QDeclarativeParticle;
53 class QDeclarativeParticles;
54 class QDeclarativeParticleMotion : public QObject
58 QDeclarativeParticleMotion(QObject *parent=0);
60 virtual void advance(QDeclarativeParticle &, int interval);
61 virtual void created(QDeclarativeParticle &);
62 virtual void destroy(QDeclarativeParticle &);
65 class QDeclarativeParticleMotionLinear : public QDeclarativeParticleMotion
69 QDeclarativeParticleMotionLinear(QObject *parent=0)
70 : QDeclarativeParticleMotion(parent) {}
72 virtual void advance(QDeclarativeParticle &, int interval);
75 class QDeclarativeParticleMotionGravity : public QDeclarativeParticleMotion
79 Q_PROPERTY(qreal xattractor READ xAttractor WRITE setXAttractor NOTIFY xattractorChanged)
80 Q_PROPERTY(qreal yattractor READ yAttractor WRITE setYAttractor NOTIFY yattractorChanged)
81 Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
83 QDeclarativeParticleMotionGravity(QObject *parent=0)
84 : QDeclarativeParticleMotion(parent), _xAttr(0.0), _yAttr(0.0), _accel(0.00005) {}
86 qreal xAttractor() const { return _xAttr; }
87 void setXAttractor(qreal x);
89 qreal yAttractor() const { return _yAttr; }
90 void setYAttractor(qreal y);
92 qreal acceleration() const { return _accel * 1000000; }
93 void setAcceleration(qreal accel);
95 virtual void advance(QDeclarativeParticle &, int interval);
98 void xattractorChanged();
99 void yattractorChanged();
100 void accelerationChanged();
108 class QDeclarativeParticleMotionWander : public QDeclarativeParticleMotion
112 QDeclarativeParticleMotionWander()
113 : QDeclarativeParticleMotion(), particles(0), _xvariance(0), _yvariance(0), _pace(100) {}
115 virtual void advance(QDeclarativeParticle &, int interval);
116 virtual void created(QDeclarativeParticle &);
117 virtual void destroy(QDeclarativeParticle &);
128 Q_PROPERTY(qreal xvariance READ xVariance WRITE setXVariance NOTIFY xvarianceChanged)
129 qreal xVariance() const { return _xvariance * 1000.0; }
130 void setXVariance(qreal var);
132 Q_PROPERTY(qreal yvariance READ yVariance WRITE setYVariance NOTIFY yvarianceChanged)
133 qreal yVariance() const { return _yvariance * 1000.0; }
134 void setYVariance(qreal var);
136 Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged)
137 qreal pace() const { return _pace * 1000.0; }
138 void setPace(qreal pace);
141 void xvarianceChanged();
142 void yvarianceChanged();
146 QDeclarativeParticles *particles;
152 class QDeclarativeParticlesPrivate;
153 class QDeclarativeParticles : public QDeclarativeItem
157 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
158 Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
159 Q_PROPERTY(int emissionRate READ emissionRate WRITE setEmissionRate NOTIFY emissionRateChanged)
160 Q_PROPERTY(qreal emissionVariance READ emissionVariance WRITE setEmissionVariance NOTIFY emissionVarianceChanged)
161 Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan NOTIFY lifeSpanChanged)
162 Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation NOTIFY lifeSpanDeviationChanged)
163 Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration NOTIFY fadeInDurationChanged)
164 Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration NOTIFY fadeOutDurationChanged)
165 Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
166 Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation NOTIFY angleDeviationChanged)
167 Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged)
168 Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation NOTIFY velocityDeviationChanged)
169 Q_PROPERTY(QDeclarativeParticleMotion *motion READ motion WRITE setMotion NOTIFY motionChanged)
170 Q_CLASSINFO("DefaultProperty", "motion")
173 QDeclarativeParticles(QDeclarativeItem *parent=0);
174 ~QDeclarativeParticles();
177 void setSource(const QUrl &);
180 void setCount(int cnt);
182 int emissionRate() const;
183 void setEmissionRate(int);
185 qreal emissionVariance() const;
186 void setEmissionVariance(qreal);
188 int lifeSpan() const;
189 void setLifeSpan(int);
191 int lifeSpanDeviation() const;
192 void setLifeSpanDeviation(int);
194 int fadeInDuration() const;
195 void setFadeInDuration(int);
197 int fadeOutDuration() const;
198 void setFadeOutDuration(int);
201 void setAngle(qreal);
203 qreal angleDeviation() const;
204 void setAngleDeviation(qreal);
206 qreal velocity() const;
207 void setVelocity(qreal);
209 qreal velocityDeviation() const;
210 void setVelocityDeviation(qreal);
212 QDeclarativeParticleMotion *motion() const;
213 void setMotion(QDeclarativeParticleMotion *);
215 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
218 void burst(int count, int emissionRate=-1);
221 virtual void componentComplete();
224 void sourceChanged();
226 void emissionRateChanged();
227 void emissionVarianceChanged();
228 void lifeSpanChanged();
229 void lifeSpanDeviationChanged();
230 void fadeInDurationChanged();
231 void fadeOutDurationChanged();
233 void angleDeviationChanged();
234 void velocityChanged();
235 void velocityDeviationChanged();
236 void emittingChanged();
237 void motionChanged();
243 Q_DISABLE_COPY(QDeclarativeParticles)
244 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeParticles)
249 QML_DECLARE_TYPE(QDeclarativeParticleMotion)
250 QML_DECLARE_TYPE(QDeclarativeParticleMotionLinear)
251 QML_DECLARE_TYPE(QDeclarativeParticleMotionGravity)
252 QML_DECLARE_TYPE(QDeclarativeParticleMotionWander)
253 QML_DECLARE_TYPE(QDeclarativeParticles)