1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQuick module of the Qt Toolkit.
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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