diff options
author | Kim Motoyoshi Kalland <kim.kalland@nokia.com> | 2011-12-13 15:25:18 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-02 16:56:44 +0100 |
commit | 6aa535e39f79548934a5c3a142e13bb09333296a (patch) | |
tree | 7a4c12c6ac126fbe9cbffc3b68835ebe5b2cc3da /src/quick/items/qquickshadereffectsource.cpp | |
parent | 27a497b3a7581a0cd76407635afca91d1f42aeef (diff) |
Don't re-parent ShaderEffect source items.
ShaderEffect and ShaderEffectSource used to set themselves as
parent of and hide source items that don't already have a parent.
This was done in order to make sure the source items got a canvas.
This patch sets the canvas of the source items without re-parenting.
Task-number: QTBUG-23069
Change-Id: I24d56e6eb970590bca3adff7a61459d25e4983a0
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'src/quick/items/qquickshadereffectsource.cpp')
-rw-r--r-- | src/quick/items/qquickshadereffectsource.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/quick/items/qquickshadereffectsource.cpp b/src/quick/items/qquickshadereffectsource.cpp index e8be7bde85..c57d749153 100644 --- a/src/quick/items/qquickshadereffectsource.cpp +++ b/src/quick/items/qquickshadereffectsource.cpp @@ -601,16 +601,18 @@ void QQuickShaderEffectSource::setSourceItem(QQuickItem *item) d->removeItemChangeListener(this, QQuickItemPrivate::Geometry); } m_sourceItem = item; - if (m_sourceItem) { - // TODO: Find better solution. - // 'm_sourceItem' needs a canvas to get a scenegraph node. - // The easiest way to make sure it gets a canvas is to - // make it a part of the same item tree as 'this'. - if (m_sourceItem->parentItem() == 0) { - m_sourceItem->setParentItem(this); - m_sourceItem->setVisible(false); + + if (item) { + QQuickItemPrivate *d = QQuickItemPrivate::get(item); + // 'item' needs a canvas to get a scene graph node. It usually gets one through its + // parent, but if the source item is "inline" rather than a reference -- i.e. + // "sourceItem: Item { }" instead of "sourceItem: foo" -- it will not get a parent. + // In those cases, 'item' should get the canvas from 'this'. + if (!d->parentItem && canvas() && !d->canvas) { + QQuickItemPrivate::InitializationState initState; + initState.clear(); + d->initCanvas(&initState, canvas()); } - QQuickItemPrivate *d = QQuickItemPrivate::get(m_sourceItem); d->refFromEffectItem(m_hideSource); d->addItemChangeListener(this, QQuickItemPrivate::Geometry); } @@ -918,4 +920,18 @@ QSGNode *QQuickShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaint return node; } +void QQuickShaderEffectSource::itemChange(ItemChange change, const ItemChangeData &value) +{ + if (change == QQuickItem::ItemSceneChange && m_sourceItem) { + // See comment in QQuickShaderEffectSource::setSourceItem(). + QQuickItemPrivate *d = QQuickItemPrivate::get(m_sourceItem); + if (!d->parentItem && value.canvas != d->canvas) { + QQuickItemPrivate::InitializationState initState; + initState.clear(); + d->initCanvas(&initState, value.canvas); + } + } + QQuickItem::itemChange(change, value); +} + QT_END_NAMESPACE |