remove some unnecessary CONFIG additions
[profile/ivi/qtdeclarative.git] / src / particles / qquickparticlepainter.cpp
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 #include "qquickparticlepainter_p.h"
43 #include <QQuickWindow>
44 #include <QDebug>
45 QT_BEGIN_NAMESPACE
46 /*!
47     \qmltype ParticlePainter
48     \instantiates QQuickParticlePainter
49     \inqmlmodule QtQuick.Particles 2
50     \inherits Item
51     \brief For specifying how to paint particles
52     \ingroup qtquick-particles
53
54     The default implementation paints nothing. See the subclasses if you want to
55     paint something visible.
56
57 */
58 /*!
59     \qmlproperty ParticleSystem QtQuick.Particles2::ParticlePainter::system
60     This is the system whose particles can be painted by the element.
61     If the ParticlePainter is a direct child of a ParticleSystem, it will automatically be associated with it.
62 */
63 /*!
64     \qmlproperty list<string> QtQuick.Particles2::ParticlePainter::groups
65     Which logical particle groups will be painted.
66
67     If empty, it will paint the default particle group ("").
68 */
69 QQuickParticlePainter::QQuickParticlePainter(QQuickItem *parent) :
70     QQuickItem(parent),
71     m_system(0), m_count(0), m_pleaseReset(true), m_window(0)
72 {
73 }
74
75 void QQuickParticlePainter::itemChange(ItemChange change, const ItemChangeData &data)
76 {
77     if (change == QQuickItem::ItemSceneChange) {
78         if (m_window)
79             disconnect(m_window, SIGNAL(sceneGraphInvalidated()), this, SLOT(sceneGraphInvalidated()));
80         m_window = data.window;
81         if (m_window)
82             connect(m_window, SIGNAL(sceneGraphInvalidated()), this, SLOT(sceneGraphInvalidated()), Qt::DirectConnection);
83
84     }
85 }
86
87 void QQuickParticlePainter::componentComplete()
88 {
89     if (!m_system && qobject_cast<QQuickParticleSystem*>(parentItem()))
90         setSystem(qobject_cast<QQuickParticleSystem*>(parentItem()));
91     QQuickItem::componentComplete();
92 }
93
94
95 void QQuickParticlePainter::setSystem(QQuickParticleSystem *arg)
96 {
97     if (m_system != arg) {
98         m_system = arg;
99         if (m_system){
100             m_system->registerParticlePainter(this);
101             reset();
102         }
103         emit systemChanged(arg);
104     }
105 }
106
107 void QQuickParticlePainter::load(QQuickParticleData* d)
108 {
109     initialize(d->group, d->index);
110     if (m_pleaseReset)
111         return;
112     m_pendingCommits << qMakePair<int, int>(d->group, d->index);
113 }
114
115 void QQuickParticlePainter::reload(QQuickParticleData* d)
116 {
117     if (m_pleaseReset)
118         return;
119     m_pendingCommits << qMakePair<int, int>(d->group, d->index);
120 }
121
122 void QQuickParticlePainter::reset()
123 {
124     m_pendingCommits.clear();
125     m_pleaseReset = true;
126 }
127
128 void QQuickParticlePainter::setCount(int c)//### TODO: some resizeing so that particles can reallocate on size change instead of recreate
129 {
130     Q_ASSERT(c >= 0); //XXX
131     if (c == m_count)
132         return;
133     m_count = c;
134     emit countChanged();
135     reset();
136 }
137
138 int QQuickParticlePainter::count()
139 {
140     return m_count;
141 }
142
143 void QQuickParticlePainter::calcSystemOffset(bool resetPending)
144 {
145     if (!m_system || !parentItem())
146         return;
147     QPointF lastOffset = m_systemOffset;
148     m_systemOffset = -1 * this->mapFromItem(m_system, QPointF(0.0, 0.0));
149     if (lastOffset != m_systemOffset && !resetPending){
150         //Reload all particles//TODO: Necessary?
151         foreach (const QString &g, m_groups){
152             int gId = m_system->groupIds[g];
153             foreach (QQuickParticleData* d, m_system->groupData[gId]->data)
154                 reload(d);
155         }
156     }
157 }
158 typedef QPair<int,int> intPair;
159 void QQuickParticlePainter::performPendingCommits()
160 {
161     calcSystemOffset();
162     foreach (intPair p, m_pendingCommits)
163         commit(p.first, p.second);
164     m_pendingCommits.clear();
165 }
166
167 QT_END_NAMESPACE