1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQuick module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef PARTICLEAFFECTOR_H
43 #define PARTICLEAFFECTOR_H
46 #include "qquickparticlesystem_p.h"
47 #include "qquickparticleextruder_p.h"
53 class QQuickParticleAffector : public QQuickItem
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)
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
72 QStringList groups() const
87 QQuickParticleExtruder* shape() const
92 QStringList whenCollidingWith() const
94 return m_whenCollidingWith;
99 void systemChanged(QQuickParticleSystem* arg);
101 void groupsChanged(QStringList arg);
103 void enabledChanged(bool arg);
105 void onceChanged(bool arg);
107 void shapeChanged(QQuickParticleExtruder* arg);
109 void affected(qreal x, qreal y);
111 void whenCollidingWithChanged(QStringList arg);
114 void setSystem(QQuickParticleSystem* arg)
116 if (m_system != arg) {
118 m_system->registerParticleAffector(this);
119 emit systemChanged(arg);
123 void setGroups(QStringList arg)
125 if (m_groups != arg) {
127 m_updateIntSet = true;
128 emit groupsChanged(arg);
132 void setEnabled(bool arg)
134 if (m_enabled != arg) {
136 emit enabledChanged(arg);
140 void setOnceOff(bool arg)
142 if (m_onceOff != arg) {
145 emit onceChanged(arg);
149 void setShape(QQuickParticleExtruder* arg)
151 if (m_shape != arg) {
153 emit shapeChanged(arg);
157 void setWhenCollidingWith(QStringList arg)
159 if (m_whenCollidingWith != arg) {
160 m_whenCollidingWith = arg;
161 emit whenCollidingWithChanged(arg);
165 void updateOffsets();
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;
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 bool isAffectedConnected();
182 static const qreal simulationDelta;
183 static const qreal simulationCutoff;
186 QSet<QPair<int, int> > m_onceOffed;
188 QSet<int> m_groupIds;
191 QQuickParticleExtruder* m_shape;
193 QStringList m_whenCollidingWith;
195 bool isColliding(QQuickParticleData* d);
200 #endif // PARTICLEAFFECTOR_H