From 9af20c29d3e578025da6d37d7876b5c18a2a1b9f Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 6 Nov 2022 16:18:51 +0000 Subject: [PATCH] Fix scroll to current/next with hidden rows --- app/musicmuster.py | 4 ++-- app/playlists.py | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/musicmuster.py b/app/musicmuster.py index f6a5ef3..51d78b3 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1027,7 +1027,7 @@ class Window(QMainWindow, Ui_MainWindow): """Scroll to show current track""" log.debug(f"KAE: musicmuster.show_current()") - if self.current_track_playlist_tab != self.visible_playlist_tab: + if self.current_track_playlist_tab != self.visible_playlist_tab(): self.tabPlaylist.setCurrentWidget(self.current_track_playlist_tab) self.tabPlaylist.currentWidget().scroll_current_to_top() @@ -1035,7 +1035,7 @@ class Window(QMainWindow, Ui_MainWindow): """Scroll to show next track""" log.debug(f"KAE: musicmuster.show_next()") - if self.next_track_playlist_tab != self.visible_playlist_tab: + if self.next_track_playlist_tab != self.visible_playlist_tab(): self.tabPlaylist.setCurrentWidget(self.next_track_playlist_tab) self.tabPlaylist.currentWidget().scroll_next_to_top() diff --git a/app/playlists.py b/app/playlists.py index aba4521..43995ff 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -1727,10 +1727,25 @@ class PlaylistTab(QTableWidget): top. """ - if row is not None: - top_row = max(0, row - Config.SCROLL_TOP_MARGIN + 1) - scroll_item = self.item(top_row, 0) - self.scrollToItem(scroll_item, QAbstractItemView.PositionAtTop) + padding_required = Config.SCROLL_TOP_MARGIN + top_row = row + + if row > Config.SCROLL_TOP_MARGIN: + # We can't scroll to a hidden row. Calculate target_row as the + # one that is ideal to be at the top. Then count upwards from + # passed row until we either reach the target, pass it or reach + # row 0. + # target_row = max(0, row - Config.SCROLL_TOP_MARGIN + 1) + for i in range(row - 1, -1, -1): + if padding_required == 0: + break + if self.isRowHidden(i): + continue + top_row = i + padding_required -= 1 + + scroll_item = self.item(top_row, 0) + self.scrollToItem(scroll_item, QAbstractItemView.PositionAtTop) def _select_event(self) -> None: """