1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQuick module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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