Added playlist tab title index synchronisation to fix some bugs.
This commit is contained in:
parent
5f20c6e5b0
commit
9ee4184c84
2 changed files with 22 additions and 4 deletions
|
@ -19,6 +19,7 @@ class PlaylistTabBar(QTabBar):
|
||||||
|
|
||||||
self.tabBarClicked.connect(self.on_click)
|
self.tabBarClicked.connect(self.on_click)
|
||||||
self.tabBarDoubleClicked.connect(self.on_doubleclick)
|
self.tabBarDoubleClicked.connect(self.on_doubleclick)
|
||||||
|
self.tabMoved.connect(self.on_tab_move)
|
||||||
|
|
||||||
def dragEnterEvent(self, event: QDragEnterEvent):
|
def dragEnterEvent(self, event: QDragEnterEvent):
|
||||||
index = self.tabAt(event.position().toPoint())
|
index = self.tabAt(event.position().toPoint())
|
||||||
|
@ -62,3 +63,13 @@ class PlaylistTabBar(QTabBar):
|
||||||
|
|
||||||
self.context_menu.exec(event.globalPos(), title)
|
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
|
||||||
|
|
|
@ -20,12 +20,19 @@ class PlaylistTabs(QTabWidget):
|
||||||
self.setMovable(True)
|
self.setMovable(True)
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
|
|
||||||
def addTab(self, playlist_view, label):
|
def addTab(self, playlist_view, label) -> int:
|
||||||
super().addTab(playlist_view, None)
|
index = super().addTab(playlist_view, None)
|
||||||
|
|
||||||
index = self.tab_bar.count() - 1
|
|
||||||
|
|
||||||
title = TabTitle(self.app, label, self.tab_bar, index, playlist_view)
|
title = TabTitle(self.app, label, self.tab_bar, index, playlist_view)
|
||||||
|
|
||||||
self.tab_bar.setTabButton(index, QTabBar.ButtonPosition.RightSide, title)
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue