Fix a regression in previous release that broke scrolling when using the scroll_per_row tweak. Fixes #2018660 [Opening the Edit Metadata dialog causes the book list to scroll down too much](https://bugs.launchpad.net/calibre/+bug/2018660)

This commit is contained in:
Kovid Goyal 2023-05-07 14:56:54 +05:30
parent 07c1abe04f
commit 1fd1d1cdef
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1319,19 +1319,38 @@ class BooksView(QTableView): # {{{
vertical_offset = vh.offset() vertical_offset = vh.offset()
vertical_position = vh.sectionPosition(row) vertical_position = vh.sectionPosition(row)
cell_height = vh.sectionSize(row) cell_height = vh.sectionSize(row)
pos = 'center' pos = 'center'
if vertical_position - vertical_offset < 0 or cell_height > viewport_height: if vertical_position - vertical_offset < 0 or cell_height > viewport_height:
pos = 'top' pos = 'top'
elif vertical_position - vertical_offset + cell_height > viewport_height: elif vertical_position - vertical_offset + cell_height > viewport_height:
pos = 'bottom' pos = 'bottom'
vsb = self.verticalScrollBar() vsb = self.verticalScrollBar()
if pos == 'top':
vsb.setValue(vertical_position) if self.verticalScrollMode() == QAbstractItemView.ScrollMode.ScrollPerPixel:
elif pos == 'bottom': if pos == 'top':
vsb.setValue(vertical_position - viewport_height + cell_height) vsb.setValue(vertical_position)
elif pos == 'bottom':
vsb.setValue(vertical_position - viewport_height + cell_height)
else:
vsb.setValue(vertical_position - ((viewport_height - cell_height) // 2))
else: else:
vsb.setValue(vertical_position - ((viewport_height - cell_height) // 2)) vertical_index = vh.visualIndex(row)
if pos in ('bottom', 'center'):
h = (viewport_height // 2) if pos == 'center' else viewport_height
y = cell_height
while vertical_index > 0:
r = vh.logicalIndex(vertical_index - 1)
y += vh.sectionSize(r)
if y > h:
break
vertical_index -= 1
hidden_sections = 0
if vh.sectionsHidden():
for s in range(vertical_index - 1, -1, -1):
r = vh.logicalIndex(s)
if vh.isSectionHidden(row):
hidden_sections += 1
vsb.setValue(vertical_index - hidden_sections)
@property @property
def current_book(self): def current_book(self):