Change copyrights from Nokia to Digia
[profile/ivi/qtdeclarative.git] / src / particles / qquickitemparticle_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 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.
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 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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef ITEMPARTICLE_H
43 #define ITEMPARTICLE_H
44 #include "qquickparticlepainter_p.h"
45 #include <QPointer>
46 #include <QSet>
47 #include <private/qquickanimation_p_p.h>
48 QT_BEGIN_HEADER
49
50 QT_BEGIN_NAMESPACE
51
52 class QQuickVisualDataModel;
53 class QQuickItemParticleAttached;
54
55 class QQuickItemParticle : public QQuickParticlePainter
56 {
57     Q_OBJECT
58     Q_PROPERTY(bool fade READ fade WRITE setFade NOTIFY fadeChanged)
59     Q_PROPERTY(QQmlComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
60 public:
61     explicit QQuickItemParticle(QQuickItem *parent = 0);
62     ~QQuickItemParticle();
63
64     bool fade() const { return m_fade; }
65
66     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
67
68     static QQuickItemParticleAttached *qmlAttachedProperties(QObject *object);
69     QQmlComponent* delegate() const
70     {
71         return m_delegate;
72     }
73
74 signals:
75     void fadeChanged();
76
77     void delegateChanged(QQmlComponent* arg);
78
79 public slots:
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
85
86     void setFade(bool arg){if (arg == m_fade) return; m_fade = arg; emit fadeChanged();}
87     void setDelegate(QQmlComponent* arg)
88     {
89         if (m_delegate != arg) {
90             m_delegate = arg;
91             emit delegateChanged(arg);
92         }
93     }
94
95 protected:
96     virtual void reset();
97     virtual void commit(int gIdx, int pIdx);
98     virtual void initialize(int gIdx, int pIdx);
99     void prepareNextFrame();
100 private:
101     void tick(int time = 0);
102     QList<QQuickItem* > m_deletables;
103     QList< QQuickParticleData* > m_loadables;
104     bool m_fade;
105
106     QList<QQuickItem*> m_pendingItems;
107     QList<int> m_available;
108     QSet<QQuickItem*> m_stasis;
109     qreal m_lastT;
110     int m_activeCount;
111     QQmlComponent* m_delegate;
112
113     typedef QTickAnimationProxy<QQuickItemParticle, &QQuickItemParticle::tick> Clock;
114     Clock *clock;
115 };
116
117 class QQuickItemParticleAttached : public QObject
118 {
119     Q_OBJECT
120     Q_PROPERTY(QQuickItemParticle* particle READ particle CONSTANT);
121 public:
122     QQuickItemParticleAttached(QObject* parent)
123         : QObject(parent), m_mp(0)
124     {;}
125     QQuickItemParticle* particle() {return m_mp;}
126     void detach(){emit detached();}
127     void attach(){emit attached();}
128 private:
129     QQuickItemParticle* m_mp;
130     friend class QQuickItemParticle;
131 Q_SIGNALS:
132     void detached();
133     void attached();
134 };
135
136 QT_END_NAMESPACE
137
138 QML_DECLARE_TYPEINFO(QQuickItemParticle, QML_HAS_ATTACHED_PROPERTIES)
139
140 QT_END_HEADER
141 #endif // ITEMPARTICLE_H