Wobuzz/wobuzz/ui/playlist_tabs.py

79 lines
2.1 KiB
Python
Raw Normal View History

#!/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)
2025-01-27 14:47:08 +01:00
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
2025-01-26 12:33:23 +01:00
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)