1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef ITEMPARTICLE_H
41#define ITEMPARTICLE_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53#include "qquickparticlepainter_p.h"
54#include <QPointer>
55#include <QSet>
56#include <private/qquickanimation_p_p.h>
57QT_BEGIN_NAMESPACE
58
59class QQuickItemParticleAttached;
60
61class QQuickItemParticle : public QQuickParticlePainter
62{
63 Q_OBJECT
64 Q_PROPERTY(bool fade READ fade WRITE setFade NOTIFY fadeChanged)
65 Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
66 QML_NAMED_ELEMENT(ItemParticle)
67 QML_ATTACHED(QQuickItemParticleAttached)
68public:
69 explicit QQuickItemParticle(QQuickItem *parent = 0);
70 ~QQuickItemParticle();
71
72 bool fade() const { return m_fade; }
73
74 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
75
76 static QQuickItemParticleAttached *qmlAttachedProperties(QObject *object);
77 QQmlComponent* delegate() const
78 {
79 return m_delegate;
80 }
81
82Q_SIGNALS:
83 void fadeChanged();
84
85 void delegateChanged(QQmlComponent* arg);
86
87public Q_SLOTS:
88 //TODO: Add a follow mode, where moving the delegate causes the logical particle to go with it?
89 void freeze(QQuickItem* item);
90 void unfreeze(QQuickItem* item);
91 void take(QQuickItem* item,bool prioritize=false);//take by modelparticle
92 void give(QQuickItem* item);//give from modelparticle
93
94 void setFade(bool arg){if (arg == m_fade) return; m_fade = arg; Q_EMIT fadeChanged();}
95 void setDelegate(QQmlComponent* arg)
96 {
97 if (m_delegate != arg) {
98 m_delegate = arg;
99 Q_EMIT delegateChanged(arg);
100 }
101 }
102
103protected:
104 void reset() override;
105 void commit(int gIdx, int pIdx) override;
106 void initialize(int gIdx, int pIdx) override;
107 void prepareNextFrame();
108private:
109 void processDeletables();
110 void tick(int time = 0);
111 QSet<QQuickItem* > m_deletables;
112 QList<QQuickItem* > m_managed;
113 bool m_fade;
114
115 QList<QQuickItem*> m_pendingItems;
116 QList<int> m_available;
117 QSet<QQuickItem*> m_stasis;
118 qreal m_lastT;
119 int m_activeCount;
120 QQmlComponent* m_delegate;
121
122 typedef QTickAnimationProxy<QQuickItemParticle, &QQuickItemParticle::tick> Clock;
123 Clock *clock;
124};
125
126class QQuickItemParticleAttached : public QObject
127{
128 Q_OBJECT
129 Q_PROPERTY(QQuickItemParticle* particle READ particle CONSTANT);
130public:
131 QQuickItemParticleAttached(QObject* parent)
132 : QObject(parent), m_mp(0), m_parentItem(nullptr)
133 {;}
134 QQuickItemParticle* particle() const { return m_mp; }
135 void detach(){Q_EMIT detached();}
136 void attach(){Q_EMIT attached();}
137private:
138 QQuickItemParticle* m_mp;
139 QPointer<QQuickItem> m_parentItem;
140 friend class QQuickItemParticle;
141Q_SIGNALS:
142 void detached();
143 void attached();
144};
145
146QT_END_NAMESPACE
147
148#endif // ITEMPARTICLE_H
149

source code of qtdeclarative/src/particles/qquickitemparticle_p.h