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 QtDeclarative 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 #ifndef QDECLARATIVEPARTICLES_H
43 #define QDECLARATIVEPARTICLES_H
45 #include <QtDeclarative/qdeclarativeitem.h>
51 QT_MODULE(Declarative)
53 class QDeclarativeParticle;
54 class QDeclarativeParticles;
55 class QDeclarativeParticleMotion : public QObject
59 QDeclarativeParticleMotion(QObject *parent=0);
61 virtual void advance(QDeclarativeParticle &, int interval);
62 virtual void created(QDeclarativeParticle &);
63 virtual void destroy(QDeclarativeParticle &);
66 class QDeclarativeParticleMotionLinear : public QDeclarativeParticleMotion
70 QDeclarativeParticleMotionLinear(QObject *parent=0)
71 : QDeclarativeParticleMotion(parent) {}
73 virtual void advance(QDeclarativeParticle &, int interval);
76 class QDeclarativeParticleMotionGravity : public QDeclarativeParticleMotion
80 Q_PROPERTY(qreal xattractor READ xAttractor WRITE setXAttractor NOTIFY xattractorChanged)
81 Q_PROPERTY(qreal yattractor READ yAttractor WRITE setYAttractor NOTIFY yattractorChanged)
82 Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
84 QDeclarativeParticleMotionGravity(QObject *parent=0)
85 : QDeclarativeParticleMotion(parent), _xAttr(0.0), _yAttr(0.0), _accel(0.00005) {}
87 qreal xAttractor() const { return _xAttr; }
88 void setXAttractor(qreal x);
90 qreal yAttractor() const { return _yAttr; }
91 void setYAttractor(qreal y);
93 qreal acceleration() const { return _accel * 1000000; }
94 void setAcceleration(qreal accel);
96 virtual void advance(QDeclarativeParticle &, int interval);
99 void xattractorChanged();
100 void yattractorChanged();
101 void accelerationChanged();
109 class QDeclarativeParticleMotionWander : public QDeclarativeParticleMotion
113 QDeclarativeParticleMotionWander()
114 : QDeclarativeParticleMotion(), particles(0), _xvariance(0), _yvariance(0), _pace(100) {}
116 virtual void advance(QDeclarativeParticle &, int interval);
117 virtual void created(QDeclarativeParticle &);
118 virtual void destroy(QDeclarativeParticle &);
129 Q_PROPERTY(qreal xvariance READ xVariance WRITE setXVariance NOTIFY xvarianceChanged)
130 qreal xVariance() const { return _xvariance * 1000.0; }
131 void setXVariance(qreal var);
133 Q_PROPERTY(qreal yvariance READ yVariance WRITE setYVariance NOTIFY yvarianceChanged)
134 qreal yVariance() const { return _yvariance * 1000.0; }
135 void setYVariance(qreal var);
137 Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged)
138 qreal pace() const { return _pace * 1000.0; }
139 void setPace(qreal pace);
142 void xvarianceChanged();
143 void yvarianceChanged();
147 QDeclarativeParticles *particles;
153 class QDeclarativeParticlesPrivate;
154 class QDeclarativeParticles : public QDeclarativeItem
158 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
159 Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
160 Q_PROPERTY(int emissionRate READ emissionRate WRITE setEmissionRate NOTIFY emissionRateChanged)
161 Q_PROPERTY(qreal emissionVariance READ emissionVariance WRITE setEmissionVariance NOTIFY emissionVarianceChanged)
162 Q_PROPERTY(int lifeSpan READ lifeSpan WRITE setLifeSpan NOTIFY lifeSpanChanged)
163 Q_PROPERTY(int lifeSpanDeviation READ lifeSpanDeviation WRITE setLifeSpanDeviation NOTIFY lifeSpanDeviationChanged)
164 Q_PROPERTY(int fadeInDuration READ fadeInDuration WRITE setFadeInDuration NOTIFY fadeInDurationChanged)
165 Q_PROPERTY(int fadeOutDuration READ fadeOutDuration WRITE setFadeOutDuration NOTIFY fadeOutDurationChanged)
166 Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
167 Q_PROPERTY(qreal angleDeviation READ angleDeviation WRITE setAngleDeviation NOTIFY angleDeviationChanged)
168 Q_PROPERTY(qreal velocity READ velocity WRITE setVelocity NOTIFY velocityChanged)
169 Q_PROPERTY(qreal velocityDeviation READ velocityDeviation WRITE setVelocityDeviation NOTIFY velocityDeviationChanged)
170 Q_PROPERTY(QDeclarativeParticleMotion *motion READ motion WRITE setMotion NOTIFY motionChanged)
171 Q_CLASSINFO("DefaultProperty", "motion")
174 QDeclarativeParticles(QDeclarativeItem *parent=0);
175 ~QDeclarativeParticles();
178 void setSource(const QUrl &);
181 void setCount(int cnt);
183 int emissionRate() const;
184 void setEmissionRate(int);
186 qreal emissionVariance() const;
187 void setEmissionVariance(qreal);
189 int lifeSpan() const;
190 void setLifeSpan(int);
192 int lifeSpanDeviation() const;
193 void setLifeSpanDeviation(int);
195 int fadeInDuration() const;
196 void setFadeInDuration(int);
198 int fadeOutDuration() const;
199 void setFadeOutDuration(int);
202 void setAngle(qreal);
204 qreal angleDeviation() const;
205 void setAngleDeviation(qreal);
207 qreal velocity() const;
208 void setVelocity(qreal);
210 qreal velocityDeviation() const;
211 void setVelocityDeviation(qreal);
213 QDeclarativeParticleMotion *motion() const;
214 void setMotion(QDeclarativeParticleMotion *);
216 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
219 void burst(int count, int emissionRate=-1);
222 virtual void componentComplete();
225 void sourceChanged();
227 void emissionRateChanged();
228 void emissionVarianceChanged();
229 void lifeSpanChanged();
230 void lifeSpanDeviationChanged();
231 void fadeInDurationChanged();
232 void fadeOutDurationChanged();
234 void angleDeviationChanged();
235 void velocityChanged();
236 void velocityDeviationChanged();
237 void emittingChanged();
238 void motionChanged();
244 Q_DISABLE_COPY(QDeclarativeParticles)
245 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeParticles)
250 QML_DECLARE_TYPE(QDeclarativeParticleMotion)
251 QML_DECLARE_TYPE(QDeclarativeParticleMotionLinear)
252 QML_DECLARE_TYPE(QDeclarativeParticleMotionGravity)
253 QML_DECLARE_TYPE(QDeclarativeParticleMotionWander)
254 QML_DECLARE_TYPE(QDeclarativeParticles)