From 9ee4184c84c40638a3b48ee43cd71e0aaf2d539c Mon Sep 17 00:00:00 2001 From: The Wobbler Date: Mon, 3 Mar 2025 16:13:37 +0100 Subject: [PATCH] Added playlist tab title index synchronisation to fix some bugs. --- wobuzz/ui/playlist_tabs/tab_bar.py | 11 +++++++++++ wobuzz/ui/playlist_tabs/tab_widget.py | 15 +++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/wobuzz/ui/playlist_tabs/tab_bar.py b/wobuzz/ui/playlist_tabs/tab_bar.py index 8519ffd..be7621e 100644 --- a/wobuzz/ui/playlist_tabs/tab_bar.py +++ b/wobuzz/ui/playlist_tabs/tab_bar.py @@ -19,6 +19,7 @@ class PlaylistTabBar(QTabBar): self.tabBarClicked.connect(self.on_click) self.tabBarDoubleClicked.connect(self.on_doubleclick) + self.tabMoved.connect(self.on_tab_move) def dragEnterEvent(self, event: QDragEnterEvent): index = self.tabAt(event.position().toPoint()) @@ -62,3 +63,13 @@ class PlaylistTabBar(QTabBar): self.context_menu.exec(event.globalPos(), title) + def on_tab_move(self, i_from, i_to): + title = self.tabButton(i_to, QTabBar.ButtonPosition.RightSide) + + # update the index + title.index = i_to + + def update_title_indexes(self, after: int): + for i in range(after, self.count()): + title = self.tabButton(i, QTabBar.ButtonPosition.RightSide) + title.index = i diff --git a/wobuzz/ui/playlist_tabs/tab_widget.py b/wobuzz/ui/playlist_tabs/tab_widget.py index afdb04b..d2ffce6 100644 --- a/wobuzz/ui/playlist_tabs/tab_widget.py +++ b/wobuzz/ui/playlist_tabs/tab_widget.py @@ -20,12 +20,19 @@ class PlaylistTabs(QTabWidget): self.setMovable(True) self.setAcceptDrops(True) - def addTab(self, playlist_view, label): - super().addTab(playlist_view, None) - - index = self.tab_bar.count() - 1 + def addTab(self, playlist_view, label) -> int: + index = super().addTab(playlist_view, None) title = TabTitle(self.app, label, self.tab_bar, index, playlist_view) self.tab_bar.setTabButton(index, QTabBar.ButtonPosition.RightSide, title) + return index + + def tabRemoved(self, index): + # Update indexes because when a playlist is replaced, (and the old playlist widget is deleted by deleteLater()) + # the old playlist_widget is actually deleted later than the new one is created. + # Because of this, the new playlist tab gets immediately moved one to the left and we have to update the + # indexes. + self.tab_bar.update_title_indexes(index) +