Doc: Changed \qmlclass to \qmltype and added \instantiates.
[profile/ivi/qtdeclarative.git] / src / particles / qquickage.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQuick module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qquickage_p.h"
43 #include "qquickparticleemitter_p.h"
44 QT_BEGIN_NAMESPACE
45 /*!
46     \qmltype Age
47     \instantiates QQuickAgeAffector
48     \inqmlmodule QtQuick.Particles 2
49     \inherits Affector
50     \brief For altering particle ages
51     \ingroup qtquick-particles
52
53     The Age affector allows you to alter where the particle is in its lifecycle. Common uses
54     are to expire particles prematurely, possibly giving them time to animate out.
55
56     The Age affector is also sometimes known as a 'Kill' affector, because with the default
57     parameters it will immediately expire all particles which it affects.
58
59     The Age affector only applies to particles which are still alive.
60 */
61 /*!
62     \qmlproperty int QtQuick.Particles2::Age::lifeLeft
63
64     The amount of life to set the particle to have. Affected particles
65     will advance to a point in their life where they will have this many
66     milliseconds left to live.
67 */
68
69 /*!
70     \qmlproperty bool QtQuick.Particles2::Age::advancePosition
71
72     advancePosition determines whether position, veclocity and acceleration are included in
73     the simulated aging done by the affector. If advancePosition is false,
74     then the position, velocity and acceleration will remain the same and only
75     other attributes (such as opacity) will advance in the simulation to where
76     it would normally be for that point in the particle's life. With advancePosition set to
77     true the position, velocity and acceleration will also advance to where it would
78     normally be by that point in the particle's life, making it advance its position
79     on screen.
80
81     Default value is true.
82 */
83
84 QQuickAgeAffector::QQuickAgeAffector(QQuickItem *parent) :
85     QQuickParticleAffector(parent), m_lifeLeft(0), m_advancePosition(true)
86 {
87 }
88
89
90 bool QQuickAgeAffector::affectParticle(QQuickParticleData *d, qreal dt)
91 {
92     Q_UNUSED(dt);
93     if (d->stillAlive()){
94         qreal curT = (qreal)m_system->timeInt/1000.0;
95         qreal ttl = (qreal)m_lifeLeft/1000.0;
96         if (!m_advancePosition && ttl > 0){
97             qreal x = d->curX();
98             qreal vx = d->curVX();
99             qreal ax = d->curAX();
100             qreal y = d->curY();
101             qreal vy = d->curVY();
102             qreal ay = d->curAY();
103             d->t = curT - (d->lifeSpan - ttl);
104             d->setInstantaneousX(x);
105             d->setInstantaneousVX(vx);
106             d->setInstantaneousAX(ax);
107             d->setInstantaneousY(y);
108             d->setInstantaneousVY(vy);
109             d->setInstantaneousAY(ay);
110         } else {
111             d->t = curT - (d->lifeSpan - ttl);
112         }
113         return true;
114     }
115     return false;
116 }
117 QT_END_NAMESPACE