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 | #include "qquickparticlegroup_p.h" |
5 | |
6 | /*! |
7 | \qmltype ParticleGroup |
8 | \instantiates QQuickParticleGroup |
9 | \inqmlmodule QtQuick.Particles |
10 | \brief For setting attributes on a logical particle group. |
11 | \ingroup qtquick-particles |
12 | |
13 | This element allows you to set timed transitions on particle groups. |
14 | |
15 | You can also use this element to group particle system elements related to the logical |
16 | particle group. Emitters, Affectors and Painters set as direct children of a ParticleGroup |
17 | will automatically apply to that logical particle group. TrailEmitters will automatically follow |
18 | the group. |
19 | |
20 | If a ParticleGroup element is not defined for a group, the group will function normally as if |
21 | none of the transition properties were set. |
22 | */ |
23 | /*! |
24 | \qmlproperty ParticleSystem QtQuick.Particles::ParticleGroup::system |
25 | This is the system which will contain the group. |
26 | |
27 | If the ParticleGroup is a direct child of a ParticleSystem, it will automatically be associated with it. |
28 | */ |
29 | /*! |
30 | \qmlproperty string QtQuick.Particles::ParticleGroup::name |
31 | This is the name of the particle group, and how it is generally referred to by other elements. |
32 | |
33 | If elements refer to a name which does not have an explicit ParticleGroup created, it will |
34 | work normally (with no transitions specified for the group). If you do not need to assign |
35 | duration based transitions to a group, you do not need to create a ParticleGroup with that name (although you may). |
36 | */ |
37 | /*! |
38 | \qmlproperty int QtQuick.Particles::ParticleGroup::duration |
39 | The time in milliseconds before the group will attempt to transition. |
40 | |
41 | */ |
42 | /*! |
43 | \qmlproperty ParticleSystem QtQuick.Particles::ParticleGroup::durationVariation |
44 | The maximum number of milliseconds that the duration of the transition cycle varies per particle in the group. |
45 | |
46 | Default value is zero. |
47 | */ |
48 | /*! |
49 | \qmlproperty ParticleSystem QtQuick.Particles::ParticleGroup::to |
50 | The weighted list of transitions valid for this group. |
51 | |
52 | If the chosen transition stays in this group, another duration (+/- up to durationVariation) |
53 | milliseconds will occur before another transition is attempted. |
54 | */ |
55 | |
56 | QQuickParticleGroup::QQuickParticleGroup(QObject* parent) |
57 | : QQuickStochasticState(parent) |
58 | , m_system(nullptr) |
59 | { |
60 | |
61 | } |
62 | |
63 | void delayedRedirect(QQmlListProperty<QObject> *prop, QObject *value) |
64 | { |
65 | QQuickParticleGroup* pg = qobject_cast<QQuickParticleGroup*>(object: prop->object); |
66 | if (pg) |
67 | pg->delayRedirect(obj: value); |
68 | } |
69 | |
70 | QQmlListProperty<QObject> QQuickParticleGroup::particleChildren() |
71 | { |
72 | QQuickParticleSystem* system = qobject_cast<QQuickParticleSystem*>(object: parent()); |
73 | if (system) { |
74 | return QQmlListProperty<QObject>(this, nullptr, |
75 | &QQuickParticleSystem::statePropertyRedirect, nullptr, |
76 | nullptr, nullptr, nullptr, nullptr); |
77 | } else { |
78 | return QQmlListProperty<QObject>(this, nullptr, |
79 | &delayedRedirect, nullptr, nullptr, |
80 | nullptr, nullptr, nullptr); |
81 | } |
82 | } |
83 | |
84 | void QQuickParticleGroup::setSystem(QQuickParticleSystem* arg) |
85 | { |
86 | if (m_system != arg) { |
87 | m_system = arg; |
88 | m_system->registerParticleGroup(g: this); |
89 | performDelayedRedirects(); |
90 | emit systemChanged(arg); |
91 | } |
92 | } |
93 | |
94 | void QQuickParticleGroup::delayRedirect(QObject *obj) |
95 | { |
96 | m_delayedRedirects << obj; |
97 | } |
98 | |
99 | void QQuickParticleGroup::performDelayedRedirects() |
100 | { |
101 | if (!m_system) |
102 | return; |
103 | foreach (QObject* obj, m_delayedRedirects) |
104 | m_system->stateRedirect(group: this, sys: m_system, value: obj); |
105 | |
106 | m_delayedRedirects.clear(); |
107 | } |
108 | |
109 | void QQuickParticleGroup::componentComplete(){ |
110 | if (!m_system && qobject_cast<QQuickParticleSystem*>(object: parent())) |
111 | setSystem(qobject_cast<QQuickParticleSystem*>(object: parent())); |
112 | } |
113 | |
114 | #include "moc_qquickparticlegroup_p.cpp" |
115 | |