Rename Qt Quick-specific classes to QQuick*
[profile/ivi/qtdeclarative.git] / src / declarative / particles / qsgparticlepainter_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Declarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef PARTICLE_H
43 #define PARTICLE_H
44
45 #include <QObject>
46 #include <QDebug>
47 #include <QPair>
48 #include "qsgparticlesystem_p.h"
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 QT_MODULE(Declarative)
55
56
57 class QSGParticlePainter : public QQuickItem
58 {
59     Q_OBJECT
60     Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged)
61     Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged)
62
63 public:
64     explicit QSGParticlePainter(QQuickItem *parent = 0);
65     //Data Interface to system
66     void load(QSGParticleData*);
67     void reload(QSGParticleData*);
68     void setCount(int c);
69     int count();
70     void performPendingCommits();//Called from updatePaintNode
71     QSGParticleSystem* system() const
72     {
73         return m_system;
74     }
75
76
77     QStringList groups() const
78     {
79         return m_groups;
80     }
81
82 signals:
83     void countChanged();
84     void systemChanged(QSGParticleSystem* arg);
85
86     void groupsChanged(QStringList arg);
87
88 public slots:
89     void setSystem(QSGParticleSystem* arg);
90
91     void setGroups(QStringList arg)
92     {
93         if (m_groups != arg) {
94             m_groups = arg;
95             emit groupsChanged(arg);
96         }
97     }
98
99     void calcSystemOffset(bool resetPending = false);
100
101 protected:
102     /* Reset resets all your internal data structures. But anything attached to a particle should
103        be in attached data. So reset + reloads should have no visible effect.
104        ###Hunt down all cases where we do a complete reset for convenience and be more targeted
105     */
106     virtual void reset();
107
108     virtual void componentComplete();
109     virtual void initialize(int gIdx, int pIdx){//Called from main thread
110         Q_UNUSED(gIdx);
111         Q_UNUSED(pIdx);
112     }
113     virtual void commit(int gIdx, int pIdx){//Called in Render Thread
114         //###If you need to do something on size changed, check m_data size in this? Or we reset you every time?
115         Q_UNUSED(gIdx);
116         Q_UNUSED(pIdx);
117     }
118
119     QSGParticleSystem* m_system;
120     friend class QSGParticleSystem;
121     int m_count;
122     bool m_pleaseReset;//Used by subclasses, but it's a nice optimization to know when stuff isn't going to matter.
123     QStringList m_groups;
124     QPointF m_systemOffset;
125
126 private:
127     QSGParticleData* m_sentinel;
128     QSet<QPair<int,int> > m_pendingCommits;
129     //QVector<QSGParticleData*> m_shadowData;//For when we implement overwrite: false
130 };
131
132 QT_END_NAMESPACE
133 QT_END_HEADER
134 #endif // PARTICLE_H