1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the Declarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qquickparticlegroup_p.h"
45 \qmlclass ParticleGroup QQuickParticleGroup
46 \inqmlmodule QtQuick.Particles 2
47 \brief ParticleGroup elements allow you to set attributes on a logical particle group.
49 This element allows you to set timed transitions on particle groups.
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
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.
60 \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::system
61 This is the system which will contain the group.
63 If the ParticleGroup is a direct child of a ParticleSystem, it will automatically be associated with it.
66 \qmlproperty string QtQuick.Particles2::ParticleGroup::name
67 This is the name of the particle group, and how it is generally referred to by other elements.
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).
74 \qmlproperty int QtQuick.Particles2::ParticleGroup::duration
75 The time in milliseconds before the group will attempt to transition.
79 \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::durationVariation
80 The maximum number of milliseconds that the duration of the transition cycle varies per particle in the group.
82 Default value is zero.
85 \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::to
86 The weighted list of transitions valid for this group.
88 If the chosen transition stays in this group, another duration (+/- up to durationVariation)
89 milliseconds will occur before another transition is attempted.
92 QQuickParticleGroup::QQuickParticleGroup(QObject* parent)
93 : QQuickStochasticState(parent)
99 void delayedRedirect(QDeclarativeListProperty<QObject> *prop, QObject *value)
101 QQuickParticleGroup* pg = qobject_cast<QQuickParticleGroup*>(prop->object);
103 pg->delayRedirect(value);
106 QDeclarativeListProperty<QObject> QQuickParticleGroup::particleChildren()
108 QQuickParticleSystem* system = qobject_cast<QQuickParticleSystem*>(parent());
110 return QDeclarativeListProperty<QObject>(this, 0, &QQuickParticleSystem::statePropertyRedirect);
112 return QDeclarativeListProperty<QObject>(this, 0, &delayedRedirect);
115 void QQuickParticleGroup::setSystem(QQuickParticleSystem* arg)
117 if (m_system != arg) {
119 m_system->registerParticleGroup(this);
120 performDelayedRedirects();
121 emit systemChanged(arg);
125 void QQuickParticleGroup::delayRedirect(QObject *obj)
127 m_delayedRedirects << obj;
130 void QQuickParticleGroup::performDelayedRedirects()
134 foreach (QObject* obj, m_delayedRedirects)
135 m_system->stateRedirect(this, m_system, obj);
137 m_delayedRedirects.clear();
140 void QQuickParticleGroup::componentComplete(){
141 if (!m_system && qobject_cast<QQuickParticleSystem*>(parent()))
142 setSystem(qobject_cast<QQuickParticleSystem*>(parent()));