centralize load(qt_build_config)s in .qmake.conf
[profile/ivi/qtdeclarative.git] / src / particles / qquickitemparticle_p.h
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 #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