From 768209aebcbc66fec3a600be0a0f0e58d9f405d8 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 24 Jun 2010 15:56:05 +1000 Subject: Restore neutral movement state if a view is manually positioned. Make sure the previous movement state is cancelled if contentX or contentY are set directly. Task-number: QTBUG-11650 --- .../graphicsitems/qdeclarativeflickable_p.h | 4 ++-- .../graphicsitems/qdeclarativegridview.cpp | 21 +++++++++++++++++++-- .../graphicsitems/qdeclarativegridview_p.h | 3 +++ .../graphicsitems/qdeclarativelistview.cpp | 21 +++++++++++++++++++-- .../graphicsitems/qdeclarativelistview_p.h | 3 +++ 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h index be4846e..eb738d9 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h @@ -112,10 +112,10 @@ public: void setContentHeight(qreal); qreal contentX() const; - void setContentX(qreal pos); + virtual void setContentX(qreal pos); qreal contentY() const; - void setContentY(qreal pos); + virtual void setContentY(qreal pos); bool isMoving() const; bool isMovingHorizontally() const; diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index af9b04e..dda1efb 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -151,9 +151,9 @@ public: void setPosition(qreal pos) { Q_Q(QDeclarativeGridView); if (flow == QDeclarativeGridView::LeftToRight) - q->setContentY(pos); + q->QDeclarativeFlickable::setContentY(pos); else - q->setContentX(pos); + q->QDeclarativeFlickable::setContentX(pos); } int size() const { Q_Q(const QDeclarativeGridView); @@ -1742,6 +1742,22 @@ void QDeclarativeGridView::setHeader(QDeclarativeComponent *header) } } +void QDeclarativeGridView::setContentX(qreal pos) +{ + Q_D(QDeclarativeGridView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeGridViewPrivate::Other; + QDeclarativeFlickable::setContentX(pos); +} + +void QDeclarativeGridView::setContentY(qreal pos) +{ + Q_D(QDeclarativeGridView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeGridViewPrivate::Other; + QDeclarativeFlickable::setContentY(pos); +} + bool QDeclarativeGridView::event(QEvent *event) { Q_D(QDeclarativeGridView); @@ -2144,6 +2160,7 @@ void QDeclarativeGridView::componentComplete() d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); d->updateTrackedItem(); } + d->moveReason = QDeclarativeGridViewPrivate::Other; d->fixupPosition(); } } diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index 021aad9..64b91d8 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -151,6 +151,9 @@ public: QDeclarativeComponent *header() const; void setHeader(QDeclarativeComponent *); + virtual void setContentX(qreal pos); + virtual void setContentY(qreal pos); + enum PositionMode { Beginning, Center, End, Visible, Contain }; Q_INVOKABLE void positionViewAtIndex(int index, int mode); diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 59bb178..6fc066d 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -216,9 +216,9 @@ public: void setPosition(qreal pos) { Q_Q(QDeclarativeListView); if (orient == QDeclarativeListView::Vertical) - q->setContentY(pos); + q->QDeclarativeFlickable::setContentY(pos); else - q->setContentX(pos); + q->QDeclarativeFlickable::setContentX(pos); } qreal size() const { Q_Q(const QDeclarativeListView); @@ -2182,6 +2182,22 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header) } } +void QDeclarativeListView::setContentX(qreal pos) +{ + Q_D(QDeclarativeListView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeListViewPrivate::Other; + QDeclarativeFlickable::setContentX(pos); +} + +void QDeclarativeListView::setContentY(qreal pos) +{ + Q_D(QDeclarativeListView); + // Positioning the view manually should override any current movement state + d->moveReason = QDeclarativeListViewPrivate::Other; + QDeclarativeFlickable::setContentY(pos); +} + bool QDeclarativeListView::event(QEvent *event) { Q_D(QDeclarativeListView); @@ -2551,6 +2567,7 @@ void QDeclarativeListView::componentComplete() d->highlight->setPosition(d->currentItem->position()); d->updateTrackedItem(); } + d->moveReason = QDeclarativeListViewPrivate::Other; d->fixupPosition(); } } diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h index d6e8023..505f659 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview_p.h +++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h @@ -198,6 +198,9 @@ public: QDeclarativeComponent *header() const; void setHeader(QDeclarativeComponent *); + virtual void setContentX(qreal pos); + virtual void setContentY(qreal pos); + static QDeclarativeListViewAttached *qmlAttachedProperties(QObject *); enum PositionMode { Beginning, Center, End, Visible, Contain }; -- cgit v0.12