summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativegridview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativegridview.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp65
1 files changed, 46 insertions, 19 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 23140fa..f6666f2 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -347,6 +347,7 @@ public:
void QDeclarativeGridViewPrivate::init()
{
Q_Q(QDeclarativeGridView);
+ QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped()));
q->setFlag(QGraphicsItem::ItemIsFocusScope);
q->setFlickDirection(QDeclarativeFlickable::VerticalFlick);
addItemChangeListener(this, Geometry);
@@ -747,18 +748,31 @@ void QDeclarativeGridViewPrivate::fixupPosition()
void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent)
{
Q_Q(QDeclarativeGridView);
+ if ((flow == QDeclarativeGridView::TopToBottom && &data == &vData)
+ || (flow == QDeclarativeGridView::LeftToRight && &data == &hData))
+ return;
+
int oldDuration = fixupDuration;
fixupDuration = moveReason == Mouse ? fixupDuration : 0;
if (haveHighlightRange && highlightRange == QDeclarativeGridView::StrictlyEnforceRange) {
- if (currentItem && currentItem->rowPos() - position() != highlightRangeStart) {
- qreal pos = currentItem->rowPos() - highlightRangeStart;
+ if (currentItem) {
+ updateHighlight();
+ qreal pos = currentItem->rowPos();
+ qreal viewPos = position();
+ if (viewPos < pos + rowSize() - highlightRangeEnd)
+ viewPos = pos + rowSize() - highlightRangeEnd;
+ if (viewPos > pos - highlightRangeStart)
+ viewPos = pos - highlightRangeStart;
+
timeline.reset(data.move);
- if (fixupDuration) {
- timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
- } else {
- data.move.setValue(-pos);
- q->viewportMoved();
+ if (viewPos != position()) {
+ if (fixupDuration) {
+ timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
+ } else {
+ data.move.setValue(-viewPos);
+ q->viewportMoved();
+ }
}
vTime = timeline.time();
}
@@ -803,7 +817,7 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
maxDistance = qAbs(minExtent - data.move.value());
}
}
- if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
+ if (snapMode == QDeclarativeGridView::NoSnap && highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
data.flickTarget = minExtent;
} else {
if (data.move.value() > maxExtent) {
@@ -814,7 +828,7 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
maxDistance = qAbs(maxExtent - data.move.value());
}
}
- if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
+ if (snapMode == QDeclarativeGridView::NoSnap && highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
data.flickTarget = maxExtent;
}
if (maxDistance > 0 || overShoot) {
@@ -1510,12 +1524,12 @@ void QDeclarativeGridView::viewportMoved()
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) {
// reposition highlight
qreal pos = d->highlight->rowPos();
- qreal viewPos = qRound(d->position());
- if (pos > viewPos + d->highlightRangeEnd - 1 - d->rowSize())
- pos = viewPos + d->highlightRangeEnd - 1 - d->rowSize();
+ qreal viewPos = d->position();
+ if (pos > viewPos + d->highlightRangeEnd - d->rowSize())
+ pos = viewPos + d->highlightRangeEnd - d->rowSize();
if (pos < viewPos + d->highlightRangeStart)
pos = viewPos + d->highlightRangeStart;
- d->highlight->setPosition(d->highlight->colPos(), pos);
+ d->highlight->setPosition(d->highlight->colPos(), qRound(pos));
// update current index
int idx = d->snapIndex();
@@ -1538,8 +1552,10 @@ qreal QDeclarativeGridView::minYExtent() const
if (d->flow == QDeclarativeGridView::TopToBottom)
return QDeclarativeFlickable::minYExtent();
qreal extent = -d->startPosition();
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
extent += d->highlightRangeStart;
+ extent = qMax(extent, -(d->rowPosAt(0) + d->rowSize() - d->highlightRangeEnd));
+ }
return extent;
}
@@ -1550,8 +1566,9 @@ qreal QDeclarativeGridView::maxYExtent() const
return QDeclarativeFlickable::maxYExtent();
qreal extent;
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
- extent = -(d->endPosition() - d->highlightRangeEnd);
- extent = qMax(extent, -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart));
+ extent = -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart);
+ if (d->highlightRangeEnd != d->highlightRangeStart)
+ extent = qMin(extent, -(d->endPosition() - d->highlightRangeEnd + 1));
} else {
extent = -(d->endPosition() - height());
}
@@ -1567,8 +1584,10 @@ qreal QDeclarativeGridView::minXExtent() const
if (d->flow == QDeclarativeGridView::LeftToRight)
return QDeclarativeFlickable::minXExtent();
qreal extent = -d->startPosition();
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange)
+ if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
extent += d->highlightRangeStart;
+ extent = qMax(extent, -(d->rowPosAt(0) + d->rowSize() - d->highlightRangeEnd));
+ }
return extent;
}
@@ -1579,8 +1598,9 @@ qreal QDeclarativeGridView::maxXExtent() const
return QDeclarativeFlickable::maxXExtent();
qreal extent;
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
- extent = -(d->endPosition() - d->highlightRangeEnd);
- extent = qMax(extent, -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart));
+ extent = -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart);
+ if (d->highlightRangeEnd != d->highlightRangeStart)
+ extent = qMin(extent, -(d->endPosition() - d->highlightRangeEnd + 1));
} else {
extent = -(d->endPosition() - height());
}
@@ -2250,6 +2270,13 @@ void QDeclarativeGridView::destroyingItem(QDeclarativeItem *item)
d->unrequestedItems.remove(item);
}
+void QDeclarativeGridView::animStopped()
+{
+ Q_D(QDeclarativeGridView);
+ d->bufferMode = QDeclarativeGridViewPrivate::NoBuffer;
+ if (d->haveHighlightRange && d->highlightRange == QDeclarativeGridView::StrictlyEnforceRange)
+ d->updateHighlight();
+}
void QDeclarativeGridView::refill()
{