forked from Wobbl/Wobuzz
Moved playlist tabs related widgets to its own files.
This commit is contained in:
parent
9d844ae2dd
commit
649ad1d647
5 changed files with 97 additions and 78 deletions
|
@ -1,78 +0,0 @@
|
||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
from PyQt6.QtCore import Qt
|
|
||||||
from PyQt6.QtGui import QDragEnterEvent, QMouseEvent
|
|
||||||
from PyQt6.QtWidgets import QTabWidget, QTabBar, QLineEdit
|
|
||||||
|
|
||||||
|
|
||||||
class PlaylistTabs(QTabWidget):
|
|
||||||
def __init__(self, library, parent=None):
|
|
||||||
self.library = library
|
|
||||||
|
|
||||||
super().__init__(parent)
|
|
||||||
|
|
||||||
self.tab_bar = PlaylistTabBar(self)
|
|
||||||
self.setTabBar(self.tab_bar)
|
|
||||||
self.setDocumentMode(True)
|
|
||||||
|
|
||||||
self.setMovable(True)
|
|
||||||
self.setAcceptDrops(True)
|
|
||||||
|
|
||||||
def addTab(self, widget, label):
|
|
||||||
super().addTab(widget, None)
|
|
||||||
|
|
||||||
index = self.tab_bar.count() - 1
|
|
||||||
|
|
||||||
title = TabTitle(label, self.tab_bar, index)
|
|
||||||
|
|
||||||
self.tab_bar.setTabButton(index, QTabBar.ButtonPosition.RightSide, title)
|
|
||||||
|
|
||||||
|
|
||||||
class PlaylistTabBar(QTabBar):
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
super().__init__(parent)
|
|
||||||
|
|
||||||
self.tab_widget = parent
|
|
||||||
self.app = parent.library.app
|
|
||||||
|
|
||||||
self.setAcceptDrops(True)
|
|
||||||
|
|
||||||
self.tabBarClicked.connect(self.on_click)
|
|
||||||
self.tabBarDoubleClicked.connect(self.on_doubleclick)
|
|
||||||
|
|
||||||
def dragEnterEvent(self, event: QDragEnterEvent):
|
|
||||||
index = self.tabAt(event.position().toPoint())
|
|
||||||
|
|
||||||
self.tab_widget.setCurrentIndex(index)
|
|
||||||
|
|
||||||
def on_click(self, index):
|
|
||||||
playlist_view = self.tab_widget.widget(index)
|
|
||||||
playlist = playlist_view.playlist
|
|
||||||
|
|
||||||
self.app.gui.clicked_playlist = playlist
|
|
||||||
|
|
||||||
def on_doubleclick(self, index):
|
|
||||||
playlist_view = self.tab_widget.widget(index)
|
|
||||||
playlist = playlist_view.playlist
|
|
||||||
|
|
||||||
self.app.player.start_playlist(playlist)
|
|
||||||
|
|
||||||
|
|
||||||
class TabTitle(QLineEdit):
|
|
||||||
def __init__(self, label, parent, index: int):
|
|
||||||
super().__init__(label, parent)
|
|
||||||
|
|
||||||
self.tab_bar: PlaylistTabBar = parent
|
|
||||||
self.index = index
|
|
||||||
|
|
||||||
self.setStyleSheet("QLineEdit {background: transparent;}")
|
|
||||||
|
|
||||||
self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
|
||||||
|
|
||||||
def mouseDoubleClickEvent(self, event: QMouseEvent):
|
|
||||||
self.tab_bar.tabBarDoubleClicked.emit(self.index)
|
|
||||||
|
|
||||||
def mousePressEvent(self, event: QMouseEvent):
|
|
||||||
self.tab_bar.tabBarClicked.emit(self.index)
|
|
||||||
self.tab_bar.setCurrentIndex(self.index)
|
|
||||||
|
|
5
wobuzz/ui/playlist_tabs/__init__.py
Normal file
5
wobuzz/ui/playlist_tabs/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from .tab_widget import PlaylistTabs
|
||||||
|
from .tab_bar import PlaylistTabBar
|
||||||
|
from .tab_title import TabTitle
|
35
wobuzz/ui/playlist_tabs/tab_bar.py
Normal file
35
wobuzz/ui/playlist_tabs/tab_bar.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from PyQt6.QtGui import QDragEnterEvent
|
||||||
|
from PyQt6.QtWidgets import QTabBar
|
||||||
|
|
||||||
|
|
||||||
|
class PlaylistTabBar(QTabBar):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self.tab_widget = parent
|
||||||
|
self.app = parent.library.app
|
||||||
|
|
||||||
|
self.setAcceptDrops(True)
|
||||||
|
|
||||||
|
self.tabBarClicked.connect(self.on_click)
|
||||||
|
self.tabBarDoubleClicked.connect(self.on_doubleclick)
|
||||||
|
|
||||||
|
def dragEnterEvent(self, event: QDragEnterEvent):
|
||||||
|
index = self.tabAt(event.position().toPoint())
|
||||||
|
|
||||||
|
self.tab_widget.setCurrentIndex(index)
|
||||||
|
|
||||||
|
def on_click(self, index):
|
||||||
|
playlist_view = self.tab_widget.widget(index)
|
||||||
|
playlist = playlist_view.playlist
|
||||||
|
|
||||||
|
self.app.gui.clicked_playlist = playlist
|
||||||
|
|
||||||
|
def on_doubleclick(self, index):
|
||||||
|
playlist_view = self.tab_widget.widget(index)
|
||||||
|
playlist = playlist_view.playlist
|
||||||
|
|
||||||
|
self.app.player.start_playlist(playlist)
|
||||||
|
|
27
wobuzz/ui/playlist_tabs/tab_title.py
Normal file
27
wobuzz/ui/playlist_tabs/tab_title.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from PyQt6.QtCore import Qt
|
||||||
|
from PyQt6.QtGui import QMouseEvent
|
||||||
|
from PyQt6.QtWidgets import QLineEdit
|
||||||
|
|
||||||
|
from .tab_bar import PlaylistTabBar
|
||||||
|
|
||||||
|
|
||||||
|
class TabTitle(QLineEdit):
|
||||||
|
def __init__(self, label, parent, index: int):
|
||||||
|
super().__init__(label, parent)
|
||||||
|
|
||||||
|
self.tab_bar: PlaylistTabBar = parent
|
||||||
|
self.index = index
|
||||||
|
|
||||||
|
self.setStyleSheet("QLineEdit {background: transparent;}")
|
||||||
|
|
||||||
|
self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||||
|
|
||||||
|
def mouseDoubleClickEvent(self, event: QMouseEvent):
|
||||||
|
self.tab_bar.tabBarDoubleClicked.emit(self.index)
|
||||||
|
|
||||||
|
def mousePressEvent(self, event: QMouseEvent):
|
||||||
|
self.tab_bar.tabBarClicked.emit(self.index)
|
||||||
|
self.tab_bar.setCurrentIndex(self.index)
|
||||||
|
|
30
wobuzz/ui/playlist_tabs/tab_widget.py
Normal file
30
wobuzz/ui/playlist_tabs/tab_widget.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from PyQt6.QtWidgets import QTabWidget, QTabBar
|
||||||
|
|
||||||
|
from .tab_bar import PlaylistTabBar
|
||||||
|
from .tab_title import TabTitle
|
||||||
|
|
||||||
|
|
||||||
|
class PlaylistTabs(QTabWidget):
|
||||||
|
def __init__(self, library, parent=None):
|
||||||
|
self.library = library
|
||||||
|
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self.tab_bar = PlaylistTabBar(self)
|
||||||
|
self.setTabBar(self.tab_bar)
|
||||||
|
self.setDocumentMode(True)
|
||||||
|
|
||||||
|
self.setMovable(True)
|
||||||
|
self.setAcceptDrops(True)
|
||||||
|
|
||||||
|
def addTab(self, widget, label):
|
||||||
|
super().addTab(widget, None)
|
||||||
|
|
||||||
|
index = self.tab_bar.count() - 1
|
||||||
|
|
||||||
|
title = TabTitle(label, self.tab_bar, index)
|
||||||
|
|
||||||
|
self.tab_bar.setTabButton(index, QTabBar.ButtonPosition.RightSide, title)
|
||||||
|
|
Loading…
Add table
Reference in a new issue