diff options
author | mae <qt-info@nokia.com> | 2010-05-03 17:44:52 (GMT) |
---|---|---|
committer | mae <qt-info@nokia.com> | 2010-05-03 18:45:46 (GMT) |
commit | e0c8fc977738ca4ac6d31e45bdd2aa1b32828f54 (patch) | |
tree | a3265117e7ad1638fa4b33a2876b5dc37215d0f0 /src/declarative | |
parent | 6103c282707bac2d585473d45900d69d475cf0c2 (diff) | |
download | Qt-e0c8fc977738ca4ac6d31e45bdd2aa1b32828f54.zip Qt-e0c8fc977738ca4ac6d31e45bdd2aa1b32828f54.tar.gz Qt-e0c8fc977738ca4ac6d31e45bdd2aa1b32828f54.tar.bz2 |
Remove QDeclarativeLoader::resizeMode
The explicit resizeMode is superfluous, all usecases could be achieved
with the corrected default behaviour of the former ResizeLoaderToItem
mode. The NoResize usecase is covered by wrapping the loader in an extra
item.
That means: A loader automatically gets its size from the item loaded
unless the loader has an explicit size itself.
Go-ahead-by: Michael Brasser
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeloader.cpp | 118 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeloader_p.h | 7 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeloader_p_p.h | 3 |
3 files changed, 27 insertions, 101 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index bdd2c87..62fa4db 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -49,7 +49,6 @@ QT_BEGIN_NAMESPACE QDeclarativeLoaderPrivate::QDeclarativeLoaderPrivate() : item(0), component(0), ownComponent(false) - , resizeMode(QDeclarativeLoader::SizeLoaderToItem) { } @@ -59,9 +58,8 @@ QDeclarativeLoaderPrivate::~QDeclarativeLoaderPrivate() void QDeclarativeLoaderPrivate::itemGeometryChanged(QDeclarativeItem *resizeItem, const QRectF &newGeometry, const QRectF &oldGeometry) { - if (resizeItem == item && resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - _q_updateSize(); - } + if (resizeItem == item) + _q_updateSize(false); QDeclarativeItemChangeListener::itemGeometryChanged(resizeItem, newGeometry, oldGeometry); } @@ -76,11 +74,9 @@ void QDeclarativeLoaderPrivate::clear() if (item) { if (QDeclarativeItem *qmlItem = qobject_cast<QDeclarativeItem*>(item)) { - if (resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - QDeclarativeItemPrivate *p = + QDeclarativeItemPrivate *p = static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(qmlItem)); - p->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry); - } + p->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry); } // We can't delete immediately because our item may have triggered @@ -96,16 +92,12 @@ void QDeclarativeLoaderPrivate::initResize() { Q_Q(QDeclarativeLoader); if (QDeclarativeItem *qmlItem = qobject_cast<QDeclarativeItem*>(item)) { - if (resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - QDeclarativeItemPrivate *p = + QDeclarativeItemPrivate *p = static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(qmlItem)); - p->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); - } + p->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); } else if (item && item->isWidget()) { QGraphicsWidget *widget = static_cast<QGraphicsWidget*>(item); - if (resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - widget->installEventFilter(q); - } + widget->installEventFilter(q); } _q_updateSize(); } @@ -390,83 +382,30 @@ qreal QDeclarativeLoader::progress() const return 0.0; } -/*! - \qmlproperty enumeration Loader::resizeMode - - This property determines how the Loader or item are resized: - \list - \o NoResize - no item will be resized - \o SizeLoaderToItem - the Loader will be sized to the size of the item, unless the size of the Loader has been otherwise specified. - \o SizeItemToLoader - the item will be sized to the size of the Loader. - \endlist - - Note that changing from SizeItemToLoader to SizeLoaderToItem - after the component is loaded will not return the item or Loader - to it's original size. This is due to the item size being adjusted - to the Loader size, thereby losing the original size of the item. - Future changes to the item's size will affect the loader, however. - - The default resizeMode is SizeLoaderToItem. -*/ -QDeclarativeLoader::ResizeMode QDeclarativeLoader::resizeMode() const -{ - Q_D(const QDeclarativeLoader); - return d->resizeMode; -} - -void QDeclarativeLoader::setResizeMode(ResizeMode mode) -{ - Q_D(QDeclarativeLoader); - if (mode == d->resizeMode) - return; - - if (QDeclarativeItem *qmlItem = qobject_cast<QDeclarativeItem*>(d->item)) { - if (d->resizeMode == SizeLoaderToItem) { - QDeclarativeItemPrivate *p = - static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(qmlItem)); - p->removeItemChangeListener(d, QDeclarativeItemPrivate::Geometry); - } - } else if (d->item && d->item->isWidget()) { - if (d->resizeMode == SizeLoaderToItem) - d->item->removeEventFilter(this); - } - d->resizeMode = mode; - emit resizeModeChanged(); - d->initResize(); -} - -void QDeclarativeLoaderPrivate::_q_updateSize() +void QDeclarativeLoaderPrivate::_q_updateSize(bool loaderGeometryChanged) { Q_Q(QDeclarativeLoader); if (!item) return; if (QDeclarativeItem *qmlItem = qobject_cast<QDeclarativeItem*>(item)) { - if (resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - q->setWidth(qmlItem->width()); - q->setHeight(qmlItem->height()); - } else if (resizeMode == QDeclarativeLoader::SizeItemToLoader) { + q->setImplicitWidth(qmlItem->width()); + if (loaderGeometryChanged && q->widthValid()) qmlItem->setWidth(q->width()); + q->setImplicitHeight(qmlItem->height()); + if (loaderGeometryChanged && q->heightValid()) qmlItem->setHeight(q->height()); - } } else if (item && item->isWidget()) { QGraphicsWidget *widget = static_cast<QGraphicsWidget*>(item); - if (resizeMode == QDeclarativeLoader::SizeLoaderToItem) { - QSizeF newSize = widget->size(); - if (newSize.isValid()) { - q->setWidth(newSize.width()); - q->setHeight(newSize.height()); - } - } else if (resizeMode == QDeclarativeLoader::SizeItemToLoader) { - QSizeF oldSize = widget->size(); - QSizeF newSize = oldSize; - if (q->heightValid()) - newSize.setHeight(q->height()); - if (q->widthValid()) - newSize.setWidth(q->width()); - if (oldSize != newSize) - widget->resize(newSize); - } + QSizeF widgetSize = widget->size(); + q->setImplicitWidth(widgetSize.width()); + if (loaderGeometryChanged && q->widthValid()) + widgetSize.setWidth(q->width()); + q->setImplicitHeight(widgetSize.height()); + if (loaderGeometryChanged && q->heightValid()) + widgetSize.setHeight(q->height()); + if (widget->size() != widgetSize) + widget->resize(widgetSize); } } @@ -484,9 +423,7 @@ void QDeclarativeLoader::geometryChanged(const QRectF &newGeometry, const QRectF { Q_D(QDeclarativeLoader); if (newGeometry != oldGeometry) { - if (d->resizeMode == SizeItemToLoader) { - d->_q_updateSize(); - } + d->_q_updateSize(); } QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); } @@ -496,10 +433,8 @@ QVariant QDeclarativeLoader::itemChange(GraphicsItemChange change, const QVarian Q_D(QDeclarativeLoader); if (change == ItemSceneHasChanged) { if (d->item && d->item->isWidget()) { - if (d->resizeMode == SizeLoaderToItem) { - d->item->removeEventFilter(this); - d->item->installEventFilter(this); - } + d->item->removeEventFilter(this); + d->item->installEventFilter(this); } } return QDeclarativeItem::itemChange(change, value); @@ -509,9 +444,8 @@ bool QDeclarativeLoader::eventFilter(QObject *watched, QEvent *e) { Q_D(QDeclarativeLoader); if (watched == d->item && e->type() == QEvent::GraphicsSceneResize) { - if (d->item && d->item->isWidget() && d->resizeMode == SizeLoaderToItem) { - d->_q_updateSize(); - } + if (d->item && d->item->isWidget()) + d->_q_updateSize(false); } return QDeclarativeItem::eventFilter(watched, e); } diff --git a/src/declarative/graphicsitems/qdeclarativeloader_p.h b/src/declarative/graphicsitems/qdeclarativeloader_p.h index e9fd8e9..49dfa11 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader_p.h +++ b/src/declarative/graphicsitems/qdeclarativeloader_p.h @@ -55,11 +55,9 @@ class Q_DECLARATIVE_EXPORT QDeclarativeLoader : public QDeclarativeItem { Q_OBJECT Q_ENUMS(Status) - Q_ENUMS(ResizeMode) Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(QDeclarativeComponent *sourceComponent READ sourceComponent WRITE setSourceComponent RESET resetSourceComponent NOTIFY sourceChanged) - Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode NOTIFY resizeModeChanged) Q_PROPERTY(QGraphicsObject *item READ item NOTIFY itemChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) @@ -79,10 +77,6 @@ public: Status status() const; qreal progress() const; - enum ResizeMode { NoResize, SizeLoaderToItem, SizeItemToLoader }; - ResizeMode resizeMode() const; - void setResizeMode(ResizeMode mode); - QGraphicsObject *item() const; Q_SIGNALS: @@ -90,7 +84,6 @@ Q_SIGNALS: void sourceChanged(); void statusChanged(); void progressChanged(); - void resizeModeChanged(); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); diff --git a/src/declarative/graphicsitems/qdeclarativeloader_p_p.h b/src/declarative/graphicsitems/qdeclarativeloader_p_p.h index 49069f9..0d4c4d0 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeloader_p_p.h @@ -77,10 +77,9 @@ public: QGraphicsObject *item; QDeclarativeComponent *component; bool ownComponent : 1; - QDeclarativeLoader::ResizeMode resizeMode; void _q_sourceLoaded(); - void _q_updateSize(); + void _q_updateSize(bool loaderGeometryChanged = true); }; QT_END_NAMESPACE |