aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2011-05-12 15:43:29 +1000
committerAlan Alpert <alan.alpert@nokia.com>2011-05-12 15:43:29 +1000
commit108f7cec20c105c07a34cded24fc1632b86e15c2 (patch)
tree38c012d199484a666a9d39f6715d39935066e6d4 /src/imports
parentf7d3d68c60f247f9b44ece7c9c41e51baf927b99 (diff)
Upgrade Flickr demo to QtQuick 2.
And throw in particle effects. Includes a variety of fixes to modelparticle and picture affector which were arrived at during this demo.
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/particles/modelparticle.cpp17
-rw-r--r--src/imports/particles/particles.pro2
-rw-r--r--src/imports/particles/particlesystem.cpp2
-rw-r--r--src/imports/particles/particlesystem.h5
-rw-r--r--src/imports/particles/pictureaffector.cpp27
-rw-r--r--src/imports/particles/pictureaffector.h10
6 files changed, 49 insertions, 14 deletions
diff --git a/src/imports/particles/modelparticle.cpp b/src/imports/particles/modelparticle.cpp
index ab952cb17b..9d326db83d 100644
--- a/src/imports/particles/modelparticle.cpp
+++ b/src/imports/particles/modelparticle.cpp
@@ -180,23 +180,26 @@ void ModelParticle::load(ParticleData* d)
}
if(m_available.isEmpty() && m_pendingItems.isEmpty())
return;
- ModelParticleAttached* mpa = qobject_cast<ModelParticleAttached*>(qmlAttachedPropertiesObject<ModelParticle>(m_items[pos]));
- if(mpa)
- qDebug() << (mpa->m_mp = this);
- else
- qDebug() << "Bugger";
if(m_pendingItems.isEmpty()){
m_items[pos] = m_model->item(m_available.first());
m_idx[pos] = m_available.first();
m_available.pop_front();
+ ModelParticleAttached* mpa = qobject_cast<ModelParticleAttached*>(qmlAttachedPropertiesObject<ModelParticle>(m_items[pos]));
+ if(mpa){
+ mpa->m_mp = this;
+ mpa->attach();
+ }
}else{
m_items[pos] = m_pendingItems.front();
m_pendingItems.pop_front();
m_items[pos]->setX(d->curX() - m_items[pos]->width()/2);
m_items[pos]->setY(d->curY() - m_items[pos]->height()/2);
- if(mpa)
- mpa->attach();
m_idx[pos] = -2;
+ ModelParticleAttached* mpa = qobject_cast<ModelParticleAttached*>(qmlAttachedPropertiesObject<ModelParticle>(m_items[pos]));
+ if(mpa){
+ mpa->m_mp = this;
+ mpa->attach();
+ }
}
m_items[pos]->setParentItem(this);
m_data[pos] = d;
diff --git a/src/imports/particles/particles.pro b/src/imports/particles/particles.pro
index 6eea892f83..56474b4b37 100644
--- a/src/imports/particles/particles.pro
+++ b/src/imports/particles/particles.pro
@@ -48,7 +48,7 @@ HEADERS += \
deformableparticle.h \
pictureaffector.h
-QT += core-private gui-private declarative-private
+QT += core-private gui-private declarative-private script-private
SOURCES += \
V1/qdeclarativeparticles.cpp \
diff --git a/src/imports/particles/particlesystem.cpp b/src/imports/particles/particlesystem.cpp
index 854d512630..f89eda4aaf 100644
--- a/src/imports/particles/particlesystem.cpp
+++ b/src/imports/particles/particlesystem.cpp
@@ -206,6 +206,8 @@ void ParticleSystem::reset()
initializeSystem();
foreach(ParticleType* p, m_particles)
p->update();
+ foreach(ParticleEmitter* e, m_emitters)
+ e->emitWindow(0);//Start, so that starttime factors appropriately
}
ParticleData* ParticleSystem::newDatum(int groupId)
diff --git a/src/imports/particles/particlesystem.h b/src/imports/particles/particlesystem.h
index 896f215bfc..fc5575d3a7 100644
--- a/src/imports/particles/particlesystem.h
+++ b/src/imports/particles/particlesystem.h
@@ -118,6 +118,11 @@ emit overwriteChanged(arg);
}
}
+void fastForward(int ms)
+{
+ m_startTime += ms;
+}
+
protected:
void componentComplete();
diff --git a/src/imports/particles/pictureaffector.cpp b/src/imports/particles/pictureaffector.cpp
index c05a553f39..d684b3fd80 100644
--- a/src/imports/particles/pictureaffector.cpp
+++ b/src/imports/particles/pictureaffector.cpp
@@ -42,11 +42,13 @@
#include "pictureaffector.h"
#include "coloredparticle.h"
#include <QDebug>
+#include <private/qsgtexture_p.h>
+#include <private/qdeclarativepixmapcache_p.h>
QT_BEGIN_NAMESPACE
PictureAffector::PictureAffector(QSGItem *parent) :
- ParticleAffector(parent)
+ ParticleAffector(parent), m_pix(0)
{
m_needsReset = true;
}
@@ -56,6 +58,27 @@ void PictureAffector::reset(int systemIdx)
ParticleAffector::reset(systemIdx);
}
+void PictureAffector::startLoadImage()
+{
+ if(m_pix)
+ m_pix->clear();
+ else
+ m_pix = new QDeclarativePixmap();
+ m_pix->load(qmlEngine(this), m_image, QDeclarativePixmap::Cache);
+ if(m_pix->isReady())
+ loadImage();
+ else
+ m_pix->connectFinished(this, SLOT(loadImage()));
+}
+void PictureAffector::loadImage()
+{
+ QSGPlainTexture* ptext = qobject_cast<QSGPlainTexture*>(m_pix->texture());
+ if(ptext)
+ m_loadedImage = ptext->image();
+ if(m_loadedImage.isNull())
+ qWarning() << "PictureAffector could not load picture " << m_image;
+}
+
bool PictureAffector::affectParticle(ParticleData *d, qreal dt)
{
Q_UNUSED(dt);
@@ -74,7 +97,7 @@ bool PictureAffector::affectParticle(ParticleData *d, qreal dt)
QPoint pos = QPoint(d->curX() - m_offset.x(), d->curY() - m_offset.y());
if(!QRect(0,0,width(),height()).contains(pos)){
//XXX: Just a debugging helper, as I don't think it can get here.
- qWarning() << "An unexpected situation has occurred. But don't worry, everything will be fine.";
+ qWarning() << "PictureAffector gives up.";
return false;
}
Color4ub c;
diff --git a/src/imports/particles/pictureaffector.h b/src/imports/particles/pictureaffector.h
index ca7d13f477..4e0141d00a 100644
--- a/src/imports/particles/pictureaffector.h
+++ b/src/imports/particles/pictureaffector.h
@@ -50,12 +50,12 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
+class QDeclarativePixmap;
class PictureAffector : public ParticleAffector
{
Q_OBJECT
//Usually want to use "particles" to target just colored stuff, and save performance
//Use onceOff (inherited) to determine if this is an emitter modification or a more constant enforcer
- //TODO: Onceoff isn't actually working right now...
Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
//TODO: Bool smooth, where it interpolates
public:
@@ -78,15 +78,17 @@ public slots:
{
if (m_image != arg) {
m_image = arg;
- m_loadedImage = QImage(m_image.toLocalFile());
- if(m_loadedImage.isNull())
- qWarning() << "PictureAffector could not load picture " << m_image.toLocalFile();
+ startLoadImage();
emit imageChanged(arg);
}
}
+private slots:
+ void loadImage();
private:
+ void startLoadImage();
QUrl m_image;
+ QDeclarativePixmap* m_pix;
QImage m_loadedImage;
};