summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-07-16 14:24:09 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-07-16 14:29:42 (GMT)
commit5fe6a7457033b183d8cc3861fe8593338ad3385b (patch)
treed6425fdbe3048efa04537d4747f6d8cc1c5def96 /src
parent6d0290b2202d4fc084595ba678c2a2d984392e72 (diff)
downloadQt-5fe6a7457033b183d8cc3861fe8593338ad3385b.zip
Qt-5fe6a7457033b183d8cc3861fe8593338ad3385b.tar.gz
Qt-5fe6a7457033b183d8cc3861fe8593338ad3385b.tar.bz2
QTreeView: fix the scrollTo with position center and bottom
This still needs to be autotested Task-number: 258225
Diffstat (limited to 'src')
-rw-r--r--src/gui/itemviews/qtreeview.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp
index 7084e6d..f7fa3ad 100644
--- a/src/gui/itemviews/qtreeview.cpp
+++ b/src/gui/itemviews/qtreeview.cpp
@@ -1095,18 +1095,22 @@ void QTreeView::scrollTo(const QModelIndex &index, ScrollHint hint)
} else if (hint == PositionAtTop || (hint == EnsureVisible && item < top)) {
verticalScrollBar()->setValue(item);
} else { // PositionAtBottom or PositionAtCenter
- int itemLocation = item;
+ const int currentItemHeight = d->itemHeight(item);
int y = (hint == PositionAtCenter
- ? area.height() / 2
+ //we center on the current item with a preference to the top item (ie. -1)
+ ? area.height() / 2 + currentItemHeight - 1
+ //otherwise we simply take the whole space
: area.height());
- while (y > 0 && item > 0)
- y -= d->itemHeight(item--);
- // end up half over the top of the area
- if (y < 0 && item < itemLocation)
- ++item;
- // end up half over the bottom of the area
- if (item >= 0 && item < itemLocation)
- ++item;
+ if (y > currentItemHeight) {
+ while (item >= 0) {
+ y -= d->itemHeight(item);
+ if (y < 0) { //there is no more space left
+ item++;
+ break;
+ }
+ item--;
+ }
+ }
verticalScrollBar()->setValue(item);
}
} else { // ScrollPerPixel