diff options
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativegridview.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativegridview.cpp | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 3792595..cb99129 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); @@ -421,10 +421,10 @@ FxGridItem *QDeclarativeGridViewPrivate::createItem(int modelIndex) if (model->completePending()) { // complete listItem->item->setZValue(1); - listItem->item->setParentItem(q->viewport()); + listItem->item->setParentItem(q->contentItem()); model->completeItem(); } else { - listItem->item->setParentItem(q->viewport()); + listItem->item->setParentItem(q->contentItem()); } unrequestedItems.remove(listItem->item); } @@ -716,12 +716,12 @@ void QDeclarativeGridViewPrivate::createHighlight() } } else { item = new QDeclarativeItem; - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); highlight = new FxGridItem(item, q); highlightXAnimator = new QSmoothedAnimation(q); highlightXAnimator->target = QDeclarativeProperty(highlight->item, QLatin1String("x")); @@ -808,8 +808,8 @@ void QDeclarativeGridViewPrivate::updateFooter() delete context; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); item->setZValue(1); QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -854,8 +854,8 @@ void QDeclarativeGridViewPrivate::updateHeader() delete context; } if (item) { - QDeclarative_setParent_noEvent(item, q->viewport()); - item->setParentItem(q->viewport()); + QDeclarative_setParent_noEvent(item, q->contentItem()); + item->setParentItem(q->contentItem()); item->setZValue(1); QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item)); itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); @@ -1099,6 +1099,8 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m is not clipped by another item or the screen, it will be necessary to set \e {clip: true} in order to have the out of view items clipped nicely. + + \sa {declarative/modelviews/gridview}{GridView example} */ QDeclarativeGridView::QDeclarativeGridView(QDeclarativeItem *parent) : QDeclarativeFlickable(*(new QDeclarativeGridViewPrivate), parent) @@ -1742,6 +1744,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); @@ -1919,6 +1937,8 @@ void QDeclarativeGridView::keyPressEvent(QKeyEvent *event) Move the currentIndex up one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexUp() { @@ -1942,6 +1962,8 @@ void QDeclarativeGridView::moveCurrentIndexUp() Move the currentIndex down one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexDown() { @@ -1965,6 +1987,8 @@ void QDeclarativeGridView::moveCurrentIndexDown() Move the currentIndex left one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexLeft() { @@ -1988,6 +2012,8 @@ void QDeclarativeGridView::moveCurrentIndexLeft() Move the currentIndex right one item in the view. The current index will wrap if keyNavigationWraps is true and it is currently at the end. + + \bold Note: methods should only be called after the Component has completed. */ void QDeclarativeGridView::moveCurrentIndexRight() { @@ -2028,6 +2054,14 @@ void QDeclarativeGridView::moveCurrentIndexRight() at a particular index. This is unreliable since removing items from the start of the view does not cause all other items to be repositioned. The correct way to bring an item into view is with \c positionViewAtIndex. + + \bold Note: methods should only be called after the Component has completed. To position + the view at startup, this method should be called by Component.onCompleted. For + example, to position the view at the end: + + \code + Component.onCompleted: positionViewAtIndex(count - 1, GridView.Beginning) + \endcode */ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) { @@ -2037,6 +2071,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) if (mode < Beginning || mode > Contain) return; + if (d->layoutScheduled) + d->layout(); qreal pos = d->position(); FxGridItem *item = d->visibleItem(index); if (!item) { @@ -2079,6 +2115,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) pos = qMin(pos, maxExtent); qreal minExtent = d->flow == QDeclarativeGridView::LeftToRight ? -minYExtent() : -minXExtent(); pos = qMax(pos, minExtent); + d->moveReason = QDeclarativeGridViewPrivate::Other; + cancelFlick(); d->setPosition(pos); } d->fixupPosition(); @@ -2093,6 +2131,8 @@ void QDeclarativeGridView::positionViewAtIndex(int index, int mode) If the item is outside the visible area, -1 is returned, regardless of whether an item will exist at that point when scrolled into view. + + \bold Note: methods should only be called after the Component has completed. */ int QDeclarativeGridView::indexAt(int x, int y) const { @@ -2113,10 +2153,16 @@ void QDeclarativeGridView::componentComplete() d->updateGrid(); if (d->isValid()) { refill(); + d->moveReason = QDeclarativeGridViewPrivate::SetIndex; if (d->currentIndex < 0) d->updateCurrent(0); else d->updateCurrent(d->currentIndex); + if (d->highlight) { + d->highlight->setPosition(d->currentItem->colPos(), d->currentItem->rowPos()); + d->updateTrackedItem(); + } + d->moveReason = QDeclarativeGridViewPrivate::Other; d->fixupPosition(); } } |