From 144fa523efe86841e969318df3ebd5e626573d61 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 Nov 2013 22:07:28 +0530 Subject: [PATCH] Booklist: Fix using Page Up/Down keys moving book list by one row too many. Fixes #1248109 [Page up and page down keys scroll one book too much](https://bugs.launchpad.net/calibre/+bug/1248109) --- src/calibre/gui2/library/views.py | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 2718b0335e..10d0ba55fc 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -859,6 +859,38 @@ class BooksView(QTableView): # {{{ self.horizontalScrollBar().setValue(val) return ret + def row_at_top(self): + pos = 0 + while pos < 100: + ans = self.rowAt(pos) + if ans > -1: + return ans + pos += 5 + + def row_at_bottom(self): + pos = self.viewport().height() + limit = pos - 100 + while pos > limit: + ans = self.rowAt(pos) + if ans > -1: + return ans + pos -= 5 + + def moveCursor(self, action, modifiers): + orig = self.currentIndex() + index = QTableView.moveCursor(self, action, modifiers) + if action == QTableView.MovePageDown: + rows = self.row_at_bottom() - self.row_at_top() + moved = index.row() - orig.row() + if moved > rows: + index = self.model().index(orig.row() + rows, index.column()) + elif action == QTableView.MovePageUp: + rows = self.row_at_bottom() - self.row_at_top() + moved = orig.row() - index.row() + if moved > rows: + index = self.model().index(orig.row() - rows, index.column()) + return index + def ids_to_rows(self, ids): row_map = OrderedDict() ids = frozenset(ids)