Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / imports / particles / V1 / qdeclarativeparticles_p.h
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 QtDeclarative 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 QDECLARATIVEPARTICLES_H
43 #define QDECLARATIVEPARTICLES_H
44
45 #include <QtQuick1/qdeclarativeitem.h>
46
47 QT_BEGIN_HEADER
48
49 QT_BEGIN_NAMESPACE
50
51
52 class QDeclarativeParticle;
53 class QDeclarativeParticles;
54 class QDeclarativeParticleMotion : public QObject
55 {
56     Q_OBJECT
57 public:
58     QDeclarativeParticleMotion(QObject *parent=0);
59
60     virtual void advance(QDeclarativeParticle &, int interval);
61     virtual void created(QDeclarativeParticle &);
62     virtual void destroy(QDeclarativeParticle &);
63 };
64
65 class QDeclarativeParticleMotionLinear : public QDeclarativeParticleMotion
66 {
67     Q_OBJECT
68 public:
69     QDeclarativeParticleMotionLinear(QObject *parent=0)
70         : QDeclarativeParticleMotion(parent) {}
71
72     virtual void advance(QDeclarativeParticle &, int interval);
73 };
74
75 class QDeclarativeParticleMotionGravity : public QDeclarativeParticleMotion
76 {
77     Q_OBJECT
78
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)
82 public:
83     QDeclarativeParticleMotionGravity(QObject *parent=0)
84         : QDeclarativeParticleMotion(parent), _xAttr(0.0), _yAttr(0.0), _accel(0.00005) {}
85
86     qreal xAttractor() const { return _xAttr; }
87     void setXAttractor(qreal x);
88
89     qreal yAttractor() const { return _yAttr; }
90     void setYAttractor(qreal y);
91
92     qreal acceleration() const { return _accel * 1000000; }
93     void setAcceleration(qreal accel);
94
95     virtual void advance(QDeclarativeParticle &, int interval);
96
97 Q_SIGNALS:
98     void xattractorChanged();
99     void yattractorChanged();
100     void accelerationChanged();
101
102 private:
103     qreal _xAttr;
104     qreal _yAttr;
105     qreal _accel;
106 };
107
108 class QDeclarativeParticleMotionWander : public QDeclarativeParticleMotion
109 {
110     Q_OBJECT
111 public:
112     QDeclarativeParticleMotionWander()
113         : QDeclarativeParticleMotion(), particles(0), _xvariance(0), _yvariance(0), _pace(100) {}
114
115     virtual void advance(QDeclarativeParticle &, int interval);
116     virtual void created(QDeclarativeParticle &);
117     virtual void destroy(QDeclarativeParticle &);
118
119     struct Data {
120         qreal x_targetV;
121         qreal y_targetV;
122         qreal x_peak;
123         qreal y_peak;
124         qreal x_var;
125         qreal y_var;
126     };
127
128     Q_PROPERTY(qreal xvariance READ xVariance WRITE setXVariance NOTIFY xvarianceChanged)
129     qreal xVariance() const { return _xvariance * 1000.0; }
130     void setXVariance(qreal var);
131
132     Q_PROPERTY(qreal yvariance READ yVariance WRITE setYVariance NOTIFY yvarianceChanged)
133     qreal yVariance() const { return _yvariance * 1000.0; }
134     void setYVariance(qreal var);
135
136     Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged)
137     qreal pace() const { return _pace * 1000.0; }
138     void setPace(qreal pace);
139
140 Q_SIGNALS:
141     void xvarianceChanged();
142     void yvarianceChanged();
143     void paceChanged();
144
145 private:
146     QDeclarativeParticles *particles;
147     qreal _xvariance;
148     qreal _yvariance;
149     qreal _pace;
150 };
151
152 class QDeclarativeParticlesPrivate;
153 class QDeclarativeParticles : public QDeclarativeItem
154 {
155     Q_OBJECT
156
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")
171
172 public:
173     QDeclarativeParticles(QDeclarativeItem *parent=0);
174     ~QDeclarativeParticles();
175
176     QUrl source() const;
177     void setSource(const QUrl &);
178
179     int count() const;
180     void setCount(int cnt);
181
182     int emissionRate() const;
183     void setEmissionRate(int);
184
185     qreal emissionVariance() const;
186     void setEmissionVariance(qreal);
187
188     int lifeSpan() const;
189     void setLifeSpan(int);
190
191     int lifeSpanDeviation() const;
192     void setLifeSpanDeviation(int);
193
194     int fadeInDuration() const;
195     void setFadeInDuration(int);
196
197     int fadeOutDuration() const;
198     void setFadeOutDuration(int);
199
200     qreal angle() const;
201     void setAngle(qreal);
202
203     qreal angleDeviation() const;
204     void setAngleDeviation(qreal);
205
206     qreal velocity() const;
207     void setVelocity(qreal);
208
209     qreal velocityDeviation() const;
210     void setVelocityDeviation(qreal);
211
212     QDeclarativeParticleMotion *motion() const;
213     void setMotion(QDeclarativeParticleMotion *);
214
215     void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
216
217 public Q_SLOTS:
218     void burst(int count, int emissionRate=-1);
219
220 protected:
221     virtual void componentComplete();
222
223 Q_SIGNALS:
224     void sourceChanged();
225     void countChanged();
226     void emissionRateChanged();
227     void emissionVarianceChanged();
228     void lifeSpanChanged();
229     void lifeSpanDeviationChanged();
230     void fadeInDurationChanged();
231     void fadeOutDurationChanged();
232     void angleChanged();
233     void angleDeviationChanged();
234     void velocityChanged();
235     void velocityDeviationChanged();
236     void emittingChanged();
237     void motionChanged();
238
239 private Q_SLOTS:
240     void imageLoaded();
241
242 private:
243     Q_DISABLE_COPY(QDeclarativeParticles)
244     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeParticles)
245 };
246
247 QT_END_NAMESPACE
248
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)
254
255 QT_END_HEADER
256
257 #endif