1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
7 | ** |
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 The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qquickparticlegroup_p.h" |
41 | |
42 | /*! |
43 | \qmltype ParticleGroup |
44 | \instantiates QQuickParticleGroup |
45 | \inqmlmodule QtQuick.Particles |
46 | \brief For setting attributes on a logical particle group. |
47 | \ingroup qtquick-particles |
48 | |
49 | This element allows you to set timed transitions on particle groups. |
50 | |
51 | You can also use this element to group particle system elements related to the logical |
52 | particle group. Emitters, Affectors and Painters set as direct children of a ParticleGroup |
53 | will automatically apply to that logical particle group. TrailEmitters will automatically follow |
54 | the group. |
55 | |
56 | If a ParticleGroup element is not defined for a group, the group will function normally as if |
57 | none of the transition properties were set. |
58 | */ |
59 | /*! |
60 | \qmlproperty ParticleSystem QtQuick.Particles::ParticleGroup::system |
61 | This is the system which will contain the group. |
62 | |
63 | If the ParticleGroup is a direct child of a ParticleSystem, it will automatically be associated with it. |
64 | */ |
65 | /*! |
66 | \qmlproperty string QtQuick.Particles::ParticleGroup::name |
67 | This is the name of the particle group, and how it is generally referred to by other elements. |
68 | |
69 | If elements refer to a name which does not have an explicit ParticleGroup created, it will |
70 | work normally (with no transitions specified for the group). If you do not need to assign |
71 | duration based transitions to a group, you do not need to create a ParticleGroup with that name (although you may). |
72 | */ |
73 | /*! |
74 | \qmlproperty int QtQuick.Particles::ParticleGroup::duration |
75 | The time in milliseconds before the group will attempt to transition. |
76 | |
77 | */ |
78 | /*! |
79 | \qmlproperty ParticleSystem QtQuick.Particles::ParticleGroup::durationVariation |
80 | The maximum number of milliseconds that the duration of the transition cycle varies per particle in the group. |
81 | |
82 | Default value is zero. |
83 | */ |
84 | /*! |
85 | \qmlproperty ParticleSystem QtQuick.Particles::ParticleGroup::to |
86 | The weighted list of transitions valid for this group. |
87 | |
88 | If the chosen transition stays in this group, another duration (+/- up to durationVariation) |
89 | milliseconds will occur before another transition is attempted. |
90 | */ |
91 | |
92 | QQuickParticleGroup::QQuickParticleGroup(QObject* parent) |
93 | : QQuickStochasticState(parent) |
94 | , m_system(nullptr) |
95 | { |
96 | |
97 | } |
98 | |
99 | void delayedRedirect(QQmlListProperty<QObject> *prop, QObject *value) |
100 | { |
101 | QQuickParticleGroup* pg = qobject_cast<QQuickParticleGroup*>(object: prop->object); |
102 | if (pg) |
103 | pg->delayRedirect(obj: value); |
104 | } |
105 | |
106 | QQmlListProperty<QObject> QQuickParticleGroup::particleChildren() |
107 | { |
108 | QQuickParticleSystem* system = qobject_cast<QQuickParticleSystem*>(object: parent()); |
109 | if (system) { |
110 | return QQmlListProperty<QObject>(this, nullptr, |
111 | &QQuickParticleSystem::statePropertyRedirect, nullptr, |
112 | nullptr, nullptr, nullptr, nullptr); |
113 | } else { |
114 | return QQmlListProperty<QObject>(this, nullptr, |
115 | &delayedRedirect, nullptr, nullptr, |
116 | nullptr, nullptr, nullptr); |
117 | } |
118 | } |
119 | |
120 | void QQuickParticleGroup::setSystem(QQuickParticleSystem* arg) |
121 | { |
122 | if (m_system != arg) { |
123 | m_system = arg; |
124 | m_system->registerParticleGroup(g: this); |
125 | performDelayedRedirects(); |
126 | emit systemChanged(arg); |
127 | } |
128 | } |
129 | |
130 | void QQuickParticleGroup::delayRedirect(QObject *obj) |
131 | { |
132 | m_delayedRedirects << obj; |
133 | } |
134 | |
135 | void QQuickParticleGroup::performDelayedRedirects() |
136 | { |
137 | if (!m_system) |
138 | return; |
139 | foreach (QObject* obj, m_delayedRedirects) |
140 | m_system->stateRedirect(group: this, sys: m_system, value: obj); |
141 | |
142 | m_delayedRedirects.clear(); |
143 | } |
144 | |
145 | void QQuickParticleGroup::componentComplete(){ |
146 | if (!m_system && qobject_cast<QQuickParticleSystem*>(object: parent())) |
147 | setSystem(qobject_cast<QQuickParticleSystem*>(object: parent())); |
148 | } |
149 | |
150 | #include "moc_qquickparticlegroup_p.cpp" |
151 | |