Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / particles / qquickparticleaffector_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 Declarative 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 PARTICLEAFFECTOR_H
43 #define PARTICLEAFFECTOR_H
44
45 #include <QObject>
46 #include "qquickparticlesystem_p.h"
47 #include "qquickparticleextruder_p.h"
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 class QQuickParticleAffector : public QQuickItem
54 {
55     Q_OBJECT
56     Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
57     Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged)
58     Q_PROPERTY(QStringList whenCollidingWith READ whenCollidingWith WRITE setWhenCollidingWith NOTIFY whenCollidingWithChanged)
59     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
60     Q_PROPERTY(bool once READ onceOff WRITE setOnceOff NOTIFY onceChanged)
61     Q_PROPERTY(QQuickParticleExtruder* shape READ shape WRITE setShape NOTIFY shapeChanged)
62
63 public:
64     explicit QQuickParticleAffector(QQuickItem *parent = 0);
65     virtual void affectSystem(qreal dt);
66     virtual void reset(QQuickParticleData*);//As some store their own data per particle?
67     QQuickParticleSystem* system() const
68     {
69         return m_system;
70     }
71
72     QStringList groups() const
73     {
74         return m_groups;
75     }
76
77     bool enabled() const
78     {
79         return m_enabled;
80     }
81
82     bool onceOff() const
83     {
84         return m_onceOff;
85     }
86
87     QQuickParticleExtruder* shape() const
88     {
89         return m_shape;
90     }
91
92     QStringList whenCollidingWith() const
93     {
94         return m_whenCollidingWith;
95     }
96
97 signals:
98
99     void systemChanged(QQuickParticleSystem* arg);
100
101     void groupsChanged(QStringList arg);
102
103     void enabledChanged(bool arg);
104
105     void onceChanged(bool arg);
106
107     void shapeChanged(QQuickParticleExtruder* arg);
108
109     void affected(qreal x, qreal y);
110
111     void whenCollidingWithChanged(QStringList arg);
112
113 public slots:
114 void setSystem(QQuickParticleSystem* arg)
115 {
116     if (m_system != arg) {
117         m_system = arg;
118         m_system->registerParticleAffector(this);
119         emit systemChanged(arg);
120     }
121 }
122
123 void setGroups(QStringList arg)
124 {
125     if (m_groups != arg) {
126         m_groups = arg;
127         m_updateIntSet = true;
128         emit groupsChanged(arg);
129     }
130 }
131
132 void setEnabled(bool arg)
133 {
134     if (m_enabled != arg) {
135         m_enabled = arg;
136         emit enabledChanged(arg);
137     }
138 }
139
140 void setOnceOff(bool arg)
141 {
142     if (m_onceOff != arg) {
143         m_onceOff = arg;
144         m_needsReset = true;
145         emit onceChanged(arg);
146     }
147 }
148
149 void setShape(QQuickParticleExtruder* arg)
150 {
151     if (m_shape != arg) {
152         m_shape = arg;
153         emit shapeChanged(arg);
154     }
155 }
156
157 void setWhenCollidingWith(QStringList arg)
158 {
159     if (m_whenCollidingWith != arg) {
160         m_whenCollidingWith = arg;
161         emit whenCollidingWithChanged(arg);
162     }
163 }
164 public slots:
165     void updateOffsets();
166
167 protected:
168     friend class QQuickParticleSystem;
169     virtual bool affectParticle(QQuickParticleData *d, qreal dt);
170     bool m_needsReset:1;//### What is this really saving?
171     bool m_ignoresTime:1;
172     bool m_onceOff:1;
173     bool m_enabled:1;
174
175     QQuickParticleSystem* m_system;
176     QStringList m_groups;
177     bool activeGroup(int g);
178     bool shouldAffect(QQuickParticleData* datum);//Call to do the logic on whether it is affecting that datum
179     void postAffect(QQuickParticleData* datum);//Call to do the post-affect logic on particles which WERE affected(once off, needs reset, affected signal)
180     virtual void componentComplete();
181     QPointF m_offset;
182     bool isAffectedConnected();
183     static const qreal simulationDelta;
184     static const qreal simulationCutoff;
185 private:
186     QSet<int> m_groupIds;
187     QSet<QPair<int, int> > m_onceOffed;
188     bool m_updateIntSet;
189
190     QQuickParticleExtruder* m_shape;
191
192     QStringList m_whenCollidingWith;
193
194     bool isColliding(QQuickParticleData* d);
195 };
196
197 QT_END_NAMESPACE
198 QT_END_HEADER
199 #endif // PARTICLEAFFECTOR_H