diff options
author | Danny Pope <daniel.pope@nokia.com> | 2012-05-02 10:45:27 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-02 03:05:09 +0200 |
commit | cf16f3ee149469c0203be082d32fbd9a93a00301 (patch) | |
tree | 7faa3c4e6124401620bd2716b3d6c613463a7793 | |
parent | 8a226a608f04e71ce56a3d496fe4127dd4035858 (diff) |
Fix for update signal on textures in QML.
Task-number: QTBUG-25401
Change-Id: Ide5584cb1e59cdd9fd8cab728f53c7d15ca846f0
Reviewed-by: Sergey Dubitskiy <sergey.dubitskiy@nokia.com>
-rw-r--r-- | src/quick3d/qdeclarativeeffect.cpp | 50 | ||||
-rw-r--r-- | src/quick3d/qdeclarativeeffect.h | 1 | ||||
-rw-r--r-- | src/threed/materials/qglmaterial.cpp | 3 |
3 files changed, 35 insertions, 19 deletions
diff --git a/src/quick3d/qdeclarativeeffect.cpp b/src/quick3d/qdeclarativeeffect.cpp index 932f01688..6dc88a625 100644 --- a/src/quick3d/qdeclarativeeffect.cpp +++ b/src/quick3d/qdeclarativeeffect.cpp @@ -107,18 +107,6 @@ public: QGLMaterialCollection *palette; int materialIndex; qreal progress; - inline void ensureMaterial() { - if (!palette) - { - palette = new QGLMaterialCollection(); - } - if (materialIndex == -1) - { - materialIndex = palette->addMaterial(new QGLMaterial(palette)); - palette->material(materialIndex)->setColor(color); - } - // TODO: decal & blending - } }; /*! @@ -155,7 +143,7 @@ QColor QDeclarativeEffect::color() const void QDeclarativeEffect::setColor(const QColor& value) { d->color = value; - d->ensureMaterial(); + ensureMaterial(); material()->setColor(value); emit effectChanged(); } @@ -269,7 +257,7 @@ void QDeclarativeEffect::setTexture(const QUrl& value) } else { - d->ensureMaterial(); + ensureMaterial(); // Warning: This will trigger the deletion of the old texure. material()->setTextureUrl(value); emit effectChanged(); @@ -309,7 +297,7 @@ QImage QDeclarativeEffect::textureImage() const void QDeclarativeEffect::setTextureImage(const QImage& value) { QGLTexture2D * tex; - d->ensureMaterial(); + ensureMaterial(); if (!material()->texture()) { tex = new QGLTexture2D(material()); @@ -349,7 +337,7 @@ QGLMaterial *QDeclarativeEffect::material() const */ void QDeclarativeEffect::setMaterial(QGLMaterial *value) { - d->ensureMaterial(); + ensureMaterial(); if (d->materialIndex != -1) d->palette->material(d->materialIndex)->disconnect(this); int newIndex = -1; @@ -358,10 +346,17 @@ void QDeclarativeEffect::setMaterial(QGLMaterial *value) if (newIndex != d->materialIndex) { d->materialIndex = newIndex; + QGLMaterial *current = d->palette->material(d->materialIndex); + if (current) { + disconnect(current, SIGNAL(materialChanged()), this, SIGNAL(effectChanged())); + + } + if (value) { + connect(value, SIGNAL(materialChanged()), this, SIGNAL(effectChanged())); + } + emit effectChanged(); // TODO: deleting old materials - if (value) - connect(value, SIGNAL(materialChanged()), this, SIGNAL(effectChanged())); } } @@ -373,6 +368,23 @@ void QDeclarativeEffect::setMaterial(QGLMaterial *value) */ /*! + \internal +*/ +void QDeclarativeEffect::ensureMaterial() { + if (!d->palette) + { + d->palette = new QGLMaterialCollection(); + } + if (d->materialIndex == -1) + { + QGLMaterial * newMaterial = new QGLMaterial(d->palette); + newMaterial->setColor(d->color); + connect(newMaterial, SIGNAL(materialChanged()), this, SIGNAL(effectChanged())); + d->materialIndex = d->palette->addMaterial(newMaterial); + } +} + +/*! \internal Enable the effect on for a given \a painter. */ @@ -437,7 +449,7 @@ void QDeclarativeEffect::disableEffect(QGLPainter *painter) */ void QDeclarativeEffect::applyTo(QGLSceneNode *node) { - d->ensureMaterial(); + ensureMaterial(); node->setPalette(d->palette); node->setMaterialIndex(d->materialIndex); diff --git a/src/quick3d/qdeclarativeeffect.h b/src/quick3d/qdeclarativeeffect.h index 88b5653f6..809ae2971 100644 --- a/src/quick3d/qdeclarativeeffect.h +++ b/src/quick3d/qdeclarativeeffect.h @@ -111,6 +111,7 @@ Q_SIGNALS: protected: QGLTexture2D *texture2D(); + inline void ensureMaterial(); private: QDeclarativeEffectPrivate *d; diff --git a/src/threed/materials/qglmaterial.cpp b/src/threed/materials/qglmaterial.cpp index 8367c6610..88145a40d 100644 --- a/src/threed/materials/qglmaterial.cpp +++ b/src/threed/materials/qglmaterial.cpp @@ -308,6 +308,8 @@ void QGLMaterial::setTexture(QGLTexture2D *value, int layer) if (prev != value) { delete prev; d->textures[layer] = value; + connect(value, SIGNAL(textureUpdated()), this, SIGNAL(texturesChanged())); + connect(value, SIGNAL(textureUpdated()), this, SIGNAL(materialChanged())); emit texturesChanged(); emit materialChanged(); } @@ -349,6 +351,7 @@ void QGLMaterial::setTextureUrl(const QUrl &url, int layer) { tex = new QGLTexture2D(this); connect(tex, SIGNAL(textureUpdated()), this, SIGNAL(texturesChanged())); + connect(tex, SIGNAL(textureUpdated()), this, SIGNAL(materialChanged())); tex->setUrl(url); } setTexture(tex, layer); |