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