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 WANDERAFFECTOR_H
5#define WANDERAFFECTOR_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#include <QHash>
18#include "qquickparticleaffector_p.h"
19
20QT_BEGIN_NAMESPACE
21
22struct WanderData{
23 qreal x_vel;
24 qreal y_vel;
25 qreal x_peak;
26 qreal x_var;
27 qreal y_peak;
28 qreal y_var;
29};
30
31class Q_QUICKPARTICLES_PRIVATE_EXPORT QQuickWanderAffector : public QQuickParticleAffector
32{
33 Q_OBJECT
34 Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged FINAL)
35 Q_PROPERTY(qreal xVariance READ xVariance WRITE setXVariance NOTIFY xVarianceChanged FINAL)
36 Q_PROPERTY(qreal yVariance READ yVariance WRITE setYVariance NOTIFY yVarianceChanged FINAL)
37 Q_PROPERTY(AffectableParameters affectedParameter READ affectedParameter WRITE setAffectedParameter NOTIFY affectedParameterChanged FINAL)
38 QML_NAMED_ELEMENT(Wander)
39 QML_ADDED_IN_VERSION(2, 0)
40
41public:
42 enum AffectableParameters {
43 Position,
44 Velocity,
45 Acceleration
46 };
47 Q_ENUM(AffectableParameters)
48
49 explicit QQuickWanderAffector(QQuickItem *parent = nullptr);
50 ~QQuickWanderAffector();
51// virtual void reset(int systemIdx);
52
53 qreal xVariance() const
54 {
55 return m_xVariance;
56 }
57
58 qreal yVariance() const
59 {
60 return m_yVariance;
61 }
62
63 qreal pace() const
64 {
65 return m_pace;
66 }
67
68 AffectableParameters affectedParameter() const
69 {
70 return m_affectedParameter;
71 }
72
73protected:
74 bool affectParticle(QQuickParticleData *d, qreal dt) override;
75
76Q_SIGNALS:
77
78 void xVarianceChanged(qreal arg);
79
80 void yVarianceChanged(qreal arg);
81
82 void paceChanged(qreal arg);
83
84
85 void affectedParameterChanged(AffectableParameters arg);
86
87public Q_SLOTS:
88void setXVariance(qreal arg)
89{
90 if (m_xVariance != arg) {
91 m_xVariance = arg;
92 Q_EMIT xVarianceChanged(arg);
93 }
94}
95
96void setYVariance(qreal arg)
97{
98 if (m_yVariance != arg) {
99 m_yVariance = arg;
100 Q_EMIT yVarianceChanged(arg);
101 }
102}
103
104void setPace(qreal arg)
105{
106 if (m_pace != arg) {
107 m_pace = arg;
108 Q_EMIT paceChanged(arg);
109 }
110}
111
112
113void setAffectedParameter(AffectableParameters arg)
114{
115 if (m_affectedParameter != arg) {
116 m_affectedParameter = arg;
117 Q_EMIT affectedParameterChanged(arg);
118 }
119}
120
121private:
122 WanderData* getData(int idx);
123 QHash<int, WanderData*> m_wanderData;
124 qreal m_xVariance;
125 qreal m_yVariance;
126 qreal m_pace;
127 AffectableParameters m_affectedParameter;
128};
129
130QT_END_NAMESPACE
131#endif // WANDERAFFECTOR_H
132

source code of qtdeclarative/src/particles/qquickwander_p.h