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 #ifndef ITEMPARTICLE_H
43 #define ITEMPARTICLE_H
44 #include "qquickparticlepainter_p.h"
47 #include <private/qquickanimation_p_p.h>
52 class QQuickVisualDataModel;
53 class QQuickItemParticleAttached;
55 class QQuickItemParticle : public QQuickParticlePainter
58 Q_PROPERTY(bool fade READ fade WRITE setFade NOTIFY fadeChanged)
59 Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
61 explicit QQuickItemParticle(QQuickItem *parent = 0);
62 ~QQuickItemParticle();
64 bool fade() const { return m_fade; }
66 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
68 static QQuickItemParticleAttached *qmlAttachedProperties(QObject *object);
69 QQmlComponent* delegate() const
77 void delegateChanged(QQmlComponent* arg);
80 //TODO: Add a follow mode, where moving the delegate causes the logical particle to go with it?
81 void freeze(QQuickItem* item);
82 void unfreeze(QQuickItem* item);
83 void take(QQuickItem* item,bool prioritize=false);//take by modelparticle
84 void give(QQuickItem* item);//give from modelparticle
86 void setFade(bool arg){if (arg == m_fade) return; m_fade = arg; emit fadeChanged();}
87 void setDelegate(QQmlComponent* arg)
89 if (m_delegate != arg) {
91 emit delegateChanged(arg);
97 virtual void commit(int gIdx, int pIdx);
98 virtual void initialize(int gIdx, int pIdx);
99 void prepareNextFrame();
101 void tick(int time = 0);
102 QList<QQuickItem* > m_deletables;
103 QList< QQuickParticleData* > m_loadables;
106 QList<QQuickItem*> m_pendingItems;
107 QList<int> m_available;
108 QSet<QQuickItem*> m_stasis;
111 QQmlComponent* m_delegate;
113 typedef QTickAnimationProxy<QQuickItemParticle, &QQuickItemParticle::tick> Clock;
117 class QQuickItemParticleAttached : public QObject
120 Q_PROPERTY(QQuickItemParticle* particle READ particle CONSTANT);
122 QQuickItemParticleAttached(QObject* parent)
123 : QObject(parent), m_mp(0)
125 QQuickItemParticle* particle() {return m_mp;}
126 void detach(){emit detached();}
127 void attach(){emit attached();}
129 QQuickItemParticle* m_mp;
130 friend class QQuickItemParticle;
138 QML_DECLARE_TYPEINFO(QQuickItemParticle, QML_HAS_ATTACHED_PROPERTIES)
141 #endif // ITEMPARTICLE_H