1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQuick module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qquickparticlegroup_p.h"
45 \qmltype ParticleGroup
46 \instantiates QQuickParticleGroup
47 \inqmlmodule QtQuick.Particles 2
48 \brief For setting attributes on a logical particle group
49 \ingroup qtquick-particles
51 This element allows you to set timed transitions on particle groups.
53 You can also use this element to group particle system elements related to the logical
54 particle group. Emitters, Affectors and Painters set as direct children of a ParticleGroup
55 will automatically apply to that logical particle group. TrailEmitters will automatically follow
58 If a ParticleGroup element is not defined for a group, the group will function normally as if
59 none of the transition properties were set.
62 \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::system
63 This is the system which will contain the group.
65 If the ParticleGroup is a direct child of a ParticleSystem, it will automatically be associated with it.
68 \qmlproperty string QtQuick.Particles2::ParticleGroup::name
69 This is the name of the particle group, and how it is generally referred to by other elements.
71 If elements refer to a name which does not have an explicit ParticleGroup created, it will
72 work normally (with no transitions specified for the group). If you do not need to assign
73 duration based transitions to a group, you do not need to create a ParticleGroup with that name (although you may).
76 \qmlproperty int QtQuick.Particles2::ParticleGroup::duration
77 The time in milliseconds before the group will attempt to transition.
81 \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::durationVariation
82 The maximum number of milliseconds that the duration of the transition cycle varies per particle in the group.
84 Default value is zero.
87 \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::to
88 The weighted list of transitions valid for this group.
90 If the chosen transition stays in this group, another duration (+/- up to durationVariation)
91 milliseconds will occur before another transition is attempted.
94 QQuickParticleGroup::QQuickParticleGroup(QObject* parent)
95 : QQuickStochasticState(parent)
101 void delayedRedirect(QQmlListProperty<QObject> *prop, QObject *value)
103 QQuickParticleGroup* pg = qobject_cast<QQuickParticleGroup*>(prop->object);
105 pg->delayRedirect(value);
108 QQmlListProperty<QObject> QQuickParticleGroup::particleChildren()
110 QQuickParticleSystem* system = qobject_cast<QQuickParticleSystem*>(parent());
112 return QQmlListProperty<QObject>(this, 0, &QQuickParticleSystem::statePropertyRedirect);
114 return QQmlListProperty<QObject>(this, 0, &delayedRedirect);
117 void QQuickParticleGroup::setSystem(QQuickParticleSystem* arg)
119 if (m_system != arg) {
121 m_system->registerParticleGroup(this);
122 performDelayedRedirects();
123 emit systemChanged(arg);
127 void QQuickParticleGroup::delayRedirect(QObject *obj)
129 m_delayedRedirects << obj;
132 void QQuickParticleGroup::performDelayedRedirects()
136 foreach (QObject* obj, m_delayedRedirects)
137 m_system->stateRedirect(this, m_system, obj);
139 m_delayedRedirects.clear();
142 void QQuickParticleGroup::componentComplete(){
143 if (!m_system && qobject_cast<QQuickParticleSystem*>(parent()))
144 setSystem(qobject_cast<QQuickParticleSystem*>(parent()));