summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-11-30 05:54:25 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-11-30 05:54:25 (GMT)
commit840ffbd6187fe2573d8c00481120d4cf30aed351 (patch)
treeb65be7919d3eb5e0b6fd63c6127234a79bd9e262 /src
parentfe3cfced940f41d078380ef7bdebe40d85aa49a2 (diff)
downloadQt-840ffbd6187fe2573d8c00481120d4cf30aed351.zip
Qt-840ffbd6187fe2573d8c00481120d4cf30aed351.tar.gz
Qt-840ffbd6187fe2573d8c00481120d4cf30aed351.tar.bz2
Ensure header is considered when positioning content with snapping.
When snapping is enabled the header was ignored and content would be aligned with the first item rather than the header, when at the top of the view. Task-number: QTBUG-15710 Reviewed-by: Bea Lam
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp37
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp6
2 files changed, 26 insertions, 17 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 6f38f63..4454284 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -219,12 +219,8 @@ public:
}
} else {
qreal pos = (modelIndex / columns) * rowSize();
- if (header) {
- qreal headerSize = flow == QDeclarativeGridView::LeftToRight
- ? header->item->height()
- : header->item->width();
- pos += headerSize;
- }
+ if (header)
+ pos += headerSize();
return pos;
}
return 0;
@@ -291,11 +287,9 @@ public:
if (item->index == -1)
continue;
qreal itemTop = item->rowPos();
- if (item->index == model->count()-1 || (itemTop+rowSize()/2 >= pos))
+ if (itemTop+rowSize()/2 >= pos && itemTop - rowSize()/2 <= pos)
return item;
}
- if (visibleItems.count() && visibleItems.first()->rowPos() <= pos)
- return visibleItems.first();
return 0;
}
@@ -315,6 +309,16 @@ public:
return index;
}
+ qreal headerSize() const {
+ if (!header)
+ return 0.0;
+
+ return flow == QDeclarativeGridView::LeftToRight
+ ? header->item->height()
+ : header->item->width();
+ }
+
+
virtual void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
Q_Q(const QDeclarativeGridView);
QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry);
@@ -878,14 +882,11 @@ void QDeclarativeGridViewPrivate::updateHeader()
if (header) {
if (visibleItems.count()) {
qreal startPos = startPosition();
- qreal headerSize = flow == QDeclarativeGridView::LeftToRight
- ? header->item->height()
- : header->item->width();
if (visibleIndex == 0) {
- header->setPosition(0, startPos - headerSize);
+ header->setPosition(0, startPos - headerSize());
} else {
- if (position() <= startPos || header->rowPos() > startPos - headerSize)
- header->setPosition(0, startPos - headerSize);
+ if (position() <= startPos || header->rowPos() > startPos - headerSize())
+ header->setPosition(0, startPos - headerSize());
}
} else {
header->setPosition(0, 0);
@@ -920,10 +921,14 @@ void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
qreal bottomPos = qMax(bottomItem->rowPos() - highlightRangeEnd, -minExtent);
pos = qAbs(data.move + topPos) < qAbs(data.move + bottomPos) ? topPos : bottomPos;
} else if (topItem) {
- pos = qMax(qMin(topItem->rowPos() - highlightRangeStart, -maxExtent), -minExtent);
+ if (topItem->index == 0 && header && position()+highlightRangeStart < header->rowPos()+headerSize()/2)
+ pos = header->rowPos() - highlightRangeStart;
+ else
+ pos = qMax(qMin(topItem->rowPos() - highlightRangeStart, -maxExtent), -minExtent);
} else if (bottomItem) {
pos = qMax(qMin(bottomItem->rowPos() - highlightRangeStart, -maxExtent), -minExtent);
} else {
+ QDeclarativeFlickablePrivate::fixup(data, minExtent, maxExtent);
fixupDuration = oldDuration;
return;
}
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index 450b6af..d1f52be 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -1185,10 +1185,14 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
FxListItem *bottomItem = snapItemAt(position()+highlightRangeEnd);
qreal pos;
if (topItem) {
- pos = qMax(qMin(topItem->position() - highlightRangeStart, -maxExtent), -minExtent);
+ if (topItem->index == 0 && header && position()+highlightRangeStart < header->position()+header->size()/2)
+ pos = header->position() - highlightRangeStart;
+ else
+ pos = qMax(qMin(topItem->position() - highlightRangeStart, -maxExtent), -minExtent);
} else if (bottomItem) {
pos = qMax(qMin(bottomItem->position() - highlightRangeStart, -maxExtent), -minExtent);
} else {
+ QDeclarativeFlickablePrivate::fixup(data, minExtent, maxExtent);
fixupDuration = oldDuration;
return;
}