diff options
author | Tang Haixiang <tanghaixiang@uniontech.com> | 2021-04-27 17:39:48 +0800 |
---|---|---|
committer | Tang Haixiang <tanghaixiang@uniontech.com> | 2021-05-31 03:27:12 +0000 |
commit | c77840d734883c91079c942e052cbdc0994c2f01 (patch) | |
tree | a8d0771493c859dbf35693aa8a058fe2373c57e9 /src/widgets/itemviews | |
parent | 80cf470534c3ce2a4f9c3cb8c6795e5342f2d932 (diff) |
Fix PageDown behavior and PageUP
When the PageDown is pressed, the current's rect cannot be
used to match the item, because we don't know the size of
the rect. Move the rect by the height of the viewport, and
then move the rect upwards until it matches the
button <= viewport's bottom of the item
Fixes: QTBUG-92583
Pick-to: 6.1
Change-Id: I210edc0e8b942984f3fc20e7752c6e1315152ea1
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qlistview.cpp | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index f04aec71bb..7e05e8e977 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -1234,13 +1234,25 @@ QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie d->removeCurrentAndDisabled(&intersectVector, current); } return d->closestIndex(initialRect, intersectVector); - case MovePageUp: - // move current by (visibileRowCount - 1) items. - // rect.translate(0, -rect.height()); will happen in the switch fallthrough for MoveUp. - rect.moveTop(rect.top() - d->viewport->height() + 2 * rect.height()); - if (rect.top() < rect.height()) - rect.moveTop(rect.height()); - Q_FALLTHROUGH(); + case MovePageUp: { + rect.moveTop(rect.top() - d->viewport->height() + 1 ); + if (rect.top() < rect.height()) { + rect.setTop(0); + rect.setBottom(1); + } + QModelIndex findindex = current; + while (intersectVector.isEmpty() + || rectForIndex(findindex).top() <= (rectForIndex(current).bottom() - d->viewport->rect().height()) + || rect.top() <= 0) { + rect.translate(0, 1); + if (rect.bottom() <= 0) { + return current; + } + intersectVector = d->intersectingSet(rect); + findindex = d->closestIndex(initialRect, intersectVector); + } + return findindex; + } case MovePrevious: case MoveUp: while (intersectVector.isEmpty()) { @@ -1263,13 +1275,26 @@ QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie d->removeCurrentAndDisabled(&intersectVector, current); } return d->closestIndex(initialRect, intersectVector); - case MovePageDown: - // move current by (visibileRowCount - 1) items. - // rect.translate(0, rect.height()); will happen in the switch fallthrough for MoveDown. - rect.moveTop(rect.top() + d->viewport->height() - 2 * rect.height()); - if (rect.bottom() > contents.height() - rect.height()) - rect.moveBottom(contents.height() - rect.height()); - Q_FALLTHROUGH(); + case MovePageDown: { + rect.moveTop(rect.top() + d->viewport->height() - 1 ); + if (rect.bottom() > contents.height() - rect.height()){ + rect.setTop(contents.height() - 1); + rect.setBottom(contents.height()); + } + QModelIndex index = current; + // index's bottom() - current's top() always <= (d->viewport->rect().height() + while (intersectVector.isEmpty() + || rectForIndex(index).bottom() >= (d->viewport->rect().height() + rectForIndex(current).top()) + || rect.bottom() > contents.height()) { + rect.translate(0, -1); + if (rect.top() >= contents.height()) { + return current; + } + intersectVector = d->intersectingSet(rect); + index = d->closestIndex(initialRect, intersectVector); + } + return index; + } case MoveNext: case MoveDown: while (intersectVector.isEmpty()) { |