diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-01-27 06:43:23 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2011-01-27 06:43:23 (GMT) |
commit | b427b69a8efc0502cb06c388c70c8877a13db2f4 (patch) | |
tree | 0154e9173a49e85e34638c5b1503fdb592ae3c03 /src/declarative/graphicsitems | |
parent | d9e4393ef212dba9eeba68277b270d68bcdbc733 (diff) | |
download | Qt-b427b69a8efc0502cb06c388c70c8877a13db2f4.zip Qt-b427b69a8efc0502cb06c388c70c8877a13db2f4.tar.gz Qt-b427b69a8efc0502cb06c388c70c8877a13db2f4.tar.bz2 |
Setting the size of a loader overwrote its implict size.
If the created item does not have a valid width/height then our
implictWidth/Height should be the same as the items implict size.
Task-number: QTBUG-16928
Reviewed-by: Bea Lam
Diffstat (limited to 'src/declarative/graphicsitems')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeloader.cpp | 22 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeloader_p_p.h | 3 |
2 files changed, 21 insertions, 4 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index 86d6404..b5f8b1d 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -48,7 +48,8 @@ QT_BEGIN_NAMESPACE QDeclarativeLoaderPrivate::QDeclarativeLoaderPrivate() - : item(0), component(0), ownComponent(false), isComponentComplete(false) + : item(0), component(0), ownComponent(false), isComponentComplete(false), updatingSize(false), + itemWidthValid(false), itemHeightValid(false) { } @@ -99,6 +100,10 @@ void QDeclarativeLoaderPrivate::initResize() QDeclarativeItemPrivate *p = static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(qmlItem)); p->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); + // We may override the item's size, so we need to remember + // whether the item provided its own valid size. + itemWidthValid = p->widthValid; + itemHeightValid = p->heightValid; } else if (item && item->isWidget()) { QGraphicsWidget *widget = static_cast<QGraphicsWidget*>(item); widget->installEventFilter(q); @@ -510,13 +515,21 @@ qreal QDeclarativeLoader::progress() const void QDeclarativeLoaderPrivate::_q_updateSize(bool loaderGeometryChanged) { Q_Q(QDeclarativeLoader); - if (!item) + if (!item || updatingSize) return; + + updatingSize = true; if (QDeclarativeItem *qmlItem = qobject_cast<QDeclarativeItem*>(item)) { - q->setImplicitWidth(qmlItem->width()); + if (!itemWidthValid) + q->setImplicitWidth(qmlItem->implicitWidth()); + else + q->setImplicitWidth(qmlItem->width()); if (loaderGeometryChanged && q->widthValid()) qmlItem->setWidth(q->width()); - q->setImplicitHeight(qmlItem->height()); + if (!itemHeightValid) + q->setImplicitHeight(qmlItem->implicitHeight()); + else + q->setImplicitHeight(qmlItem->height()); if (loaderGeometryChanged && q->heightValid()) qmlItem->setHeight(q->height()); } else if (item && item->isWidget()) { @@ -531,6 +544,7 @@ void QDeclarativeLoaderPrivate::_q_updateSize(bool loaderGeometryChanged) if (widget->size() != widgetSize) widget->resize(widgetSize); } + updatingSize = false; } /*! diff --git a/src/declarative/graphicsitems/qdeclarativeloader_p_p.h b/src/declarative/graphicsitems/qdeclarativeloader_p_p.h index 7f1a6da..6a40bf3 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeloader_p_p.h @@ -79,6 +79,9 @@ public: QDeclarativeComponent *component; bool ownComponent : 1; bool isComponentComplete : 1; + bool updatingSize: 1; + bool itemWidthValid : 1; + bool itemHeightValid : 1; void _q_sourceLoaded(); void _q_updateSize(bool loaderGeometryChanged = true); |