diff options
10 files changed, 133 insertions, 55 deletions
diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index 728c9c0..5199c5d 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -48,6 +48,7 @@ HEADERS += \ $$PWD/qmlgraphicsgraphicsobjectcontainer_p.h \ $$PWD/qmlgraphicsparticles_p.h \ $$PWD/qmlgraphicslayoutitem_p.h \ + $$PWD/qmlgraphicsitemgeometrylistener_p.h \ $$PWD/qmlgraphicseffects.cpp SOURCES += \ diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp index 96d76cf..0febf08 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp @@ -241,22 +241,20 @@ void QmlGraphicsAnchorsPrivate::clearItem(QmlGraphicsItem *item) void QmlGraphicsAnchorsPrivate::addDepend(QmlGraphicsItem *item) { - Q_Q(QmlGraphicsAnchors); if (!item) return; QmlGraphicsItemPrivate *p = static_cast<QmlGraphicsItemPrivate *>(QGraphicsItemPrivate::get(item)); - p->dependantAnchors.append(q); + p->addGeometryListener(this); } void QmlGraphicsAnchorsPrivate::remDepend(QmlGraphicsItem *item) { - Q_Q(QmlGraphicsAnchors); if (!item) return; QmlGraphicsItemPrivate *p = static_cast<QmlGraphicsItemPrivate *>(QGraphicsItemPrivate::get(item)); - p->dependantAnchors.removeOne(q); + p->removeGeometryListener(this); } bool QmlGraphicsAnchorsPrivate::isItemComplete() const @@ -332,7 +330,7 @@ void QmlGraphicsAnchorsPrivate::updateOnComplete() updateVerticalAnchors(); } -void QmlGraphicsAnchorsPrivate::update(QmlGraphicsItem *, const QRectF &newG, const QRectF &oldG) +void QmlGraphicsAnchorsPrivate::itemGeometryChanged(QmlGraphicsItem *, const QRectF &newG, const QRectF &oldG) { fillChanged(); centerInChanged(); diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h b/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h index 4f7fde0..91c8ff1 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h @@ -54,7 +54,7 @@ // #include "qmlgraphicsanchors_p.h" - +#include "qmlgraphicsitemgeometrylistener_p.h" #include <private/qobject_p.h> QT_BEGIN_NAMESPACE @@ -91,7 +91,7 @@ Q_DECLARE_METATYPE(QmlGraphicsAnchorLine) -class QmlGraphicsAnchorsPrivate : public QObjectPrivate +class QmlGraphicsAnchorsPrivate : public QObjectPrivate, public QmlGraphicsItemGeometryListener { Q_DECLARE_PUBLIC(QmlGraphicsAnchors) public: @@ -128,7 +128,10 @@ public: void updateOnComplete(); void updateMe(); - void update(QmlGraphicsItem *, const QRectF &, const QRectF &); + + // QmlGraphicsItemGeometryListener interface + void itemGeometryChanged(QmlGraphicsItem *, const QRectF &, const QRectF &); + QmlGraphicsAnchorsPrivate *anchorPrivate() { return this; } bool checkHValid() const; bool checkVValid() const; diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index ef4dfc2..0315c69 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -1478,17 +1478,18 @@ QmlGraphicsItem::QmlGraphicsItem(QmlGraphicsItemPrivate &dd, QmlGraphicsItem *pa QmlGraphicsItem::~QmlGraphicsItem() { Q_D(QmlGraphicsItem); - for (int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); - anchor->d_func()->clearItem(this); + for (int ii = 0; ii < d->geometryListeners.count(); ++ii) { + QmlGraphicsAnchorsPrivate *anchor = d->geometryListeners.at(ii)->anchorPrivate(); + if (anchor) + anchor->clearItem(this); } if (!d->parent || (parentItem() && !parentItem()->QGraphicsItem::d_ptr->inDestructor)) - for (int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); - if (anchor->d_func()->item && anchor->d_func()->item->parentItem() != this) //child will be deleted anyway - anchor->d_func()->updateOnComplete(); + for (int ii = 0; ii < d->geometryListeners.count(); ++ii) { + QmlGraphicsAnchorsPrivate *anchor = d->geometryListeners.at(ii)->anchorPrivate(); + if (anchor && anchor->item && anchor->item->parentItem() != this) //child will be deleted anyway + anchor->updateOnComplete(); } - d->dependantAnchors.clear(); + d->geometryListeners.clear(); delete d->_anchorLines; d->_anchorLines = 0; delete d->_anchors; d->_anchors = 0; delete d->_stateGroup; d->_stateGroup = 0; @@ -1974,12 +1975,22 @@ void QmlGraphicsItem::geometryChanged(const QRectF &newGeometry, if (newGeometry.height() != oldGeometry.height()) emit heightChanged(); - for(int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); - anchor->d_func()->update(this, newGeometry, oldGeometry); + for(int ii = 0; ii < d->geometryListeners.count(); ++ii) { + QmlGraphicsItemGeometryListener *listener = d->geometryListeners.at(ii); + listener->itemGeometryChanged(this, newGeometry, oldGeometry); } } +void QmlGraphicsItemPrivate::addGeometryListener(QmlGraphicsItemGeometryListener *listener) +{ + geometryListeners.append(listener); +} + +void QmlGraphicsItemPrivate::removeGeometryListener(QmlGraphicsItemGeometryListener *listener) +{ + geometryListeners.removeAll(listener); +} + /*! \internal */ void QmlGraphicsItem::keyPressEvent(QKeyEvent *event) { @@ -2227,9 +2238,10 @@ void QmlGraphicsItem::setBaselineOffset(qreal offset) d->_baselineOffset = offset; emit baselineOffsetChanged(); - for(int ii = 0; ii < d->dependantAnchors.count(); ++ii) { - QmlGraphicsAnchors *anchor = d->dependantAnchors.at(ii); - anchor->d_func()->updateVerticalAnchors(); + for(int ii = 0; ii < d->geometryListeners.count(); ++ii) { + QmlGraphicsAnchorsPrivate *anchor = d->geometryListeners.at(ii)->anchorPrivate(); + if (anchor) + anchor->updateVerticalAnchors(); } } diff --git a/src/declarative/graphicsitems/qmlgraphicsitem_p.h b/src/declarative/graphicsitems/qmlgraphicsitem_p.h index 304e36c..9496590 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem_p.h @@ -57,6 +57,7 @@ #include "qmlgraphicsanchors_p.h" #include "qmlgraphicsanchors_p_p.h" +#include "qmlgraphicsitemgeometrylistener_p.h" #include "../util/qmlstate_p.h" #include "../util/qmlnullablevalue_p_p.h" @@ -182,7 +183,6 @@ public: } return _anchors; } - QList<QmlGraphicsAnchors *> dependantAnchors; QmlGraphicsAnchors *_anchors; QmlGraphicsContents *_contents; @@ -206,6 +206,10 @@ public: return _anchorLines; } + void addGeometryListener(QmlGraphicsItemGeometryListener *); + void removeGeometryListener(QmlGraphicsItemGeometryListener *); + QList<QmlGraphicsItemGeometryListener *> geometryListeners; + QmlStateGroup *states(); QmlStateGroup *_stateGroup; diff --git a/src/declarative/graphicsitems/qmlgraphicsitemgeometrylistener_p.h b/src/declarative/graphicsitems/qmlgraphicsitemgeometrylistener_p.h new file mode 100644 index 0000000..6230e93 --- /dev/null +++ b/src/declarative/graphicsitems/qmlgraphicsitemgeometrylistener_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLGRAPHICSITEMGEOMETRYLISTENER +#define QMLGRAPHICSITEMGEOMETRYLISTENER + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class QRectF; +class QmlGraphicsItem; +class QmlGraphicsAnchorsPrivate; +class QmlGraphicsItemGeometryListener +{ +public: + virtual void itemGeometryChanged(QmlGraphicsItem *, const QRectF &newGeometry, const QRectF &oldGeometry) = 0; + virtual QmlGraphicsAnchorsPrivate *anchorPrivate() { return 0; } +}; + +QT_END_NAMESPACE + +#endif // QMLGRAPHICSITEMGEOMETRYLISTENER diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 16e9d6e..989970e 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -166,7 +166,7 @@ public: //---------------------------------------------------------------------------- -class QmlGraphicsListViewPrivate : public QmlGraphicsFlickablePrivate +class QmlGraphicsListViewPrivate : public QmlGraphicsFlickablePrivate, private QmlGraphicsItemGeometryListener { Q_DECLARE_PUBLIC(QmlGraphicsListView) @@ -410,6 +410,13 @@ public: q->setViewportWidth(q->minXExtent() - q->maxXExtent()); } + void itemGeometryChanged(QmlGraphicsItem *, const QRectF &newGeometry, const QRectF &oldGeometry) { + if (orient == QmlGraphicsListView::Vertical && newGeometry.height() != oldGeometry.height() + || newGeometry.width() != oldGeometry.width()) { + layout(); + fixupPosition(); + } + } // for debugging only void checkVisible() const { @@ -486,12 +493,8 @@ public: bool correctFlick : 1; bool inFlickCorrection : 1; bool lazyRelease : 1; - - static int itemResizedIdx; }; -int QmlGraphicsListViewPrivate::itemResizedIdx = -1; - void QmlGraphicsListViewPrivate::init() { Q_Q(QmlGraphicsListView); @@ -500,8 +503,6 @@ void QmlGraphicsListViewPrivate::init() QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(refill())); QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped())); q->setFlickDirection(QmlGraphicsFlickable::VerticalFlick); - if (itemResizedIdx == -1) - itemResizedIdx = QmlGraphicsListView::staticMetaObject.indexOfSlot("itemResized()"); } void QmlGraphicsListViewPrivate::clear() @@ -543,10 +544,7 @@ FxListItem *QmlGraphicsListViewPrivate::createItem(int modelIndex) listItem->item->setZValue(1); listItem->item->setParent(q->viewport()); QmlGraphicsItemPrivate *itemPrivate = static_cast<QmlGraphicsItemPrivate*>(QGraphicsItemPrivate::get(item)); - if (orient == QmlGraphicsListView::Vertical) - itemPrivate->connectToHeightChanged(q, itemResizedIdx); - else - itemPrivate->connectToWidthChanged(q, itemResizedIdx); + itemPrivate->addGeometryListener(this); } requestedIndex = -1; @@ -565,14 +563,11 @@ void QmlGraphicsListViewPrivate::releaseItem(FxListItem *item) QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); trackedItem = 0; } + QmlGraphicsItemPrivate *itemPrivate = static_cast<QmlGraphicsItemPrivate*>(QGraphicsItemPrivate::get(item->item)); + itemPrivate->removeGeometryListener(this); if (model->release(item->item) == 0) { // item was not destroyed, and we no longer reference it. unrequestedItems.insert(item->item, model->indexOf(item->item, q)); - QmlGraphicsItemPrivate *itemPrivate = static_cast<QmlGraphicsItemPrivate*>(QGraphicsItemPrivate::get(item->item)); - if (orient == QmlGraphicsListView::Vertical) - itemPrivate->disconnectFromHeightChanged(q, itemResizedIdx); - else - itemPrivate->disconnectFromWidthChanged(q, itemResizedIdx); } delete item; } @@ -2207,16 +2202,6 @@ void QmlGraphicsListView::trackedPositionChanged() } } -void QmlGraphicsListView::itemResized() -{ - Q_D(QmlGraphicsListView); - QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(sender()); - if (item) { - d->layout(); - d->fixupPosition(); - } -} - void QmlGraphicsListView::itemsInserted(int modelIndex, int count) { Q_D(QmlGraphicsListView); diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h index 6dc131c..cb9f5c4 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h @@ -188,7 +188,6 @@ protected: private Q_SLOTS: void refill(); void trackedPositionChanged(); - void itemResized(); void itemsInserted(int index, int count); void itemsRemoved(int index, int count); void itemsMoved(int from, int to, int count); diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index b96b8b8..ecaab80 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -67,8 +67,7 @@ void QmlGraphicsBasePositionerPrivate::watchChanges(QmlGraphicsItem *other) QmlGraphicsItemPrivate *otherPrivate = static_cast<QmlGraphicsItemPrivate*>(QGraphicsItemPrivate::get(other)); - otherPrivate->connectToHeightChanged(q, prePosIdx); - otherPrivate->connectToWidthChanged(q, prePosIdx); + otherPrivate->addGeometryListener(this); otherPrivate->registerSiblingOrderNotification(this); watched << other; @@ -81,8 +80,8 @@ void QmlGraphicsBasePositionerPrivate::unwatchChanges(QmlGraphicsItem* other) bool stillAlive = false; //Use the returns from disconnect to see if it was deleted or just reparented stillAlive |= QMetaObject::disconnect(other, visibleIdx, q, prePosIdx); stillAlive |= QMetaObject::disconnect(other, opacityIdx, q, prePosIdx); - stillAlive |= otherPrivate->disconnectFromHeightChanged(q, prePosIdx); - stillAlive |= otherPrivate->disconnectFromWidthChanged(q, prePosIdx); + + otherPrivate->removeGeometryListener(this); if(stillAlive) otherPrivate->unregisterSiblingOrderNotification(this); diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h b/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h index db795ec..63c1c83 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h @@ -66,7 +66,7 @@ #include <QtCore/QTimer> QT_BEGIN_NAMESPACE -class QmlGraphicsBasePositionerPrivate : public QmlGraphicsItemPrivate +class QmlGraphicsBasePositionerPrivate : public QmlGraphicsItemPrivate, public QmlGraphicsItemGeometryListener { Q_DECLARE_PUBLIC(QmlGraphicsBasePositioner) @@ -125,6 +125,13 @@ public: queuedPositioning = true; } } + + void itemGeometryChanged(QmlGraphicsItem *, const QRectF &newGeometry, const QRectF &oldGeometry) + { + Q_Q(QmlGraphicsBasePositioner); + if (newGeometry.size() != oldGeometry.size()) + q->prePositioning(); + } }; QT_END_NAMESPACE |