Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickparticleaffector_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef PARTICLEAFFECTOR_H
5#define PARTICLEAFFECTOR_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QObject>
19#include <QSet>
23
25
26class Q_QUICKPARTICLES_EXPORT QQuickParticleAffector : public QQuickItem
27{
28 Q_OBJECT
29 Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
30 Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged)
31 Q_PROPERTY(QStringList whenCollidingWith READ whenCollidingWith WRITE setWhenCollidingWith NOTIFY whenCollidingWithChanged)
32 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged OVERRIDE)
33 Q_PROPERTY(bool once READ onceOff WRITE setOnceOff NOTIFY onceChanged)
34 Q_PROPERTY(QQuickParticleExtruder* shape READ shape WRITE setShape NOTIFY shapeChanged)
35
36 QML_NAMED_ELEMENT(ParticleAffector)
37 QML_ADDED_IN_VERSION(2, 0)
38 QML_UNCREATABLE("Abstract type. Use one of the inheriting types instead.")
39
40public:
41 explicit QQuickParticleAffector(QQuickItem *parent = nullptr);
42 virtual void affectSystem(qreal dt);
43 virtual void reset(QQuickParticleData*);//As some store their own data per particle?
44 QQuickParticleSystem* system() const
45 {
46 return m_system;
47 }
48
49 QStringList groups() const
50 {
51 return m_groups;
52 }
53
54 bool enabled() const
55 {
56 return m_enabled;
57 }
58
59 bool onceOff() const
60 {
61 return m_onceOff;
62 }
63
64 QQuickParticleExtruder* shape() const
65 {
66 return m_shape;
67 }
68
69 QStringList whenCollidingWith() const
70 {
71 return m_whenCollidingWith;
72 }
73
74Q_SIGNALS:
75
76 void systemChanged(QQuickParticleSystem* arg);
77
78 void groupsChanged(const QStringList &arg);
79
80 void enabledChanged(bool arg);
81
82 void onceChanged(bool arg);
83
84 void shapeChanged(QQuickParticleExtruder* arg);
85
86 void affected(qreal x, qreal y);
87
88 void whenCollidingWithChanged(const QStringList &arg);
89
90public Q_SLOTS:
91void setSystem(QQuickParticleSystem* arg)
92{
93 if (m_system != arg) {
94 if (m_system)
95 m_system->unregisterParticleAffector(this);
96 m_system = arg;
97 if (m_system)
98 m_system->registerParticleAffector(this);
99 Q_EMIT systemChanged(arg);
100 }
101}
102
103void setGroups(const QStringList &arg)
104{
105 if (m_groups != arg) {
106 m_groups = arg;
107 m_updateIntSet = true;
108 Q_EMIT groupsChanged(arg);
109 }
110}
111
112void setEnabled(bool arg)
113{
114 if (m_enabled != arg) {
115 m_enabled = arg;
116 Q_EMIT enabledChanged(arg);
117 }
118}
119
120void setOnceOff(bool arg)
121{
122 if (m_onceOff != arg) {
123 m_onceOff = arg;
124 m_needsReset = true;
125 Q_EMIT onceChanged(arg);
126 }
127}
128
129void setShape(QQuickParticleExtruder* arg)
130{
131 if (m_shape != arg) {
132 m_shape = arg;
133 Q_EMIT shapeChanged(arg);
134 }
135}
136
137void setWhenCollidingWith(const QStringList &arg)
138{
139 if (m_whenCollidingWith != arg) {
140 m_whenCollidingWith = arg;
141 Q_EMIT whenCollidingWithChanged(arg);
142 }
143}
144public Q_SLOTS:
145 void updateOffsets();
146
147protected:
148 friend class QQuickParticleSystem;
149 virtual bool affectParticle(QQuickParticleData *d, qreal dt);
150 bool m_needsReset:1;//### What is this really saving?
151 bool m_ignoresTime:1;
152 bool m_onceOff:1;
153 bool m_enabled:1;
154
155 QQuickParticleSystem* m_system;
156 QStringList m_groups;
157 bool activeGroup(int g);
158 bool shouldAffect(QQuickParticleData* datum);//Call to do the logic on whether it is affecting that datum
159 void postAffect(QQuickParticleData* datum);//Call to do the post-affect logic on particles which WERE affected(once off, needs reset, affected signal)
160 void componentComplete() override;
161 bool isAffectedConnected();
162 static const qreal simulationDelta;
163 static const qreal simulationCutoff;
164
165 QPointF m_offset;
166 QSet<std::pair<int, int>> m_onceOffed;
167private:
168 QSet<int> m_groupIds;
169 bool m_updateIntSet;
170
171 QQuickParticleExtruder* m_shape;
172
173 QStringList m_whenCollidingWith;
174
175 bool isColliding(QQuickParticleData* d) const;
176};
177
178QT_END_NAMESPACE
179#endif // PARTICLEAFFECTOR_H
Combined button and popup list for selecting options.