WIP: V3 header rows span columns
This commit is contained in:
parent
9a01bf2c2c
commit
978b83ba67
@ -245,6 +245,7 @@ class MusicMusterSignals(QObject):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
set_next_track_signal = pyqtSignal(int, int)
|
set_next_track_signal = pyqtSignal(int, int)
|
||||||
|
span_cells_signal = pyqtSignal(int, int, int, int)
|
||||||
|
|
||||||
|
|
||||||
class PlaylistTrack:
|
class PlaylistTrack:
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import auto, Enum
|
from enum import auto, Enum
|
||||||
from typing import Optional
|
from typing import Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt6.QtCore import (
|
from PyQt6.QtCore import (
|
||||||
QAbstractTableModel,
|
QAbstractTableModel,
|
||||||
@ -12,7 +12,6 @@ from PyQt6.QtCore import (
|
|||||||
from PyQt6.QtGui import (
|
from PyQt6.QtGui import (
|
||||||
QBrush,
|
QBrush,
|
||||||
QColor,
|
QColor,
|
||||||
QFont,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
@ -27,6 +26,9 @@ from models import (
|
|||||||
PlaylistRows,
|
PlaylistRows,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from musicmuster import MusicMusterSignals
|
||||||
|
|
||||||
|
|
||||||
class Col(Enum):
|
class Col(Enum):
|
||||||
START_GAP = 0
|
START_GAP = 0
|
||||||
@ -40,6 +42,9 @@ class Col(Enum):
|
|||||||
NOTE = auto()
|
NOTE = auto()
|
||||||
|
|
||||||
|
|
||||||
|
HEADER_NOTES_COLUMN = 1
|
||||||
|
|
||||||
|
|
||||||
class PlaylistRowData:
|
class PlaylistRowData:
|
||||||
def __init__(self, plr: PlaylistRows) -> None:
|
def __init__(self, plr: PlaylistRows) -> None:
|
||||||
"""
|
"""
|
||||||
@ -77,8 +82,11 @@ class PlaylistRowData:
|
|||||||
|
|
||||||
|
|
||||||
class PlaylistModel(QAbstractTableModel):
|
class PlaylistModel(QAbstractTableModel):
|
||||||
def __init__(self, playlist_id: int, *args, **kwargs):
|
def __init__(
|
||||||
|
self, playlist_id: int, signals: "MusicMusterSignals", *args, **kwargs
|
||||||
|
):
|
||||||
self.playlist_id = playlist_id
|
self.playlist_id = playlist_id
|
||||||
|
self.signals = signals
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.playlist_rows: dict[int, PlaylistRowData] = {}
|
self.playlist_rows: dict[int, PlaylistRowData] = {}
|
||||||
@ -146,6 +154,21 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
Return text for display
|
Return text for display
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Detect whether this is a header row
|
||||||
|
if not prd.path:
|
||||||
|
header = prd.note
|
||||||
|
else:
|
||||||
|
header = ""
|
||||||
|
|
||||||
|
if header:
|
||||||
|
if column == HEADER_NOTES_COLUMN:
|
||||||
|
self.signals.span_cells_signal.emit(
|
||||||
|
row, HEADER_NOTES_COLUMN, 1, self.columnCount() - 1
|
||||||
|
)
|
||||||
|
return QVariant(prd.note)
|
||||||
|
else:
|
||||||
|
return QVariant()
|
||||||
|
|
||||||
if column == Col.START_GAP.value:
|
if column == Col.START_GAP.value:
|
||||||
return QVariant(prd.start_gap)
|
return QVariant(prd.start_gap)
|
||||||
if column == Col.TITLE.value:
|
if column == Col.TITLE.value:
|
||||||
@ -168,7 +191,11 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
def background_role(self, row: int, column: int, prd: PlaylistRowData) -> QBrush:
|
def background_role(self, row: int, column: int, prd: PlaylistRowData) -> QBrush:
|
||||||
""" Return background setting """
|
"""Return background setting"""
|
||||||
|
|
||||||
|
# Handle entire row colouring
|
||||||
|
if file_is_unreadable(prd.path):
|
||||||
|
return QBrush(QColor(Config.COLOUR_UNREADABLE))
|
||||||
|
|
||||||
if column == Col.START_GAP.value:
|
if column == Col.START_GAP.value:
|
||||||
if prd.start_gap and prd.start_gap >= Config.START_GAP_WARNING_THRESHOLD:
|
if prd.start_gap and prd.start_gap >= Config.START_GAP_WARNING_THRESHOLD:
|
||||||
@ -199,7 +226,6 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
# cell_colour = Config.COLOUR_BITRATE_OK
|
# cell_colour = Config.COLOUR_BITRATE_OK
|
||||||
# return QVariant(QColor(cell_colour))
|
# return QVariant(QColor(cell_colour))
|
||||||
|
|
||||||
|
|
||||||
# if not rowdata.played:
|
# if not rowdata.played:
|
||||||
# font = QFont()
|
# font = QFont()
|
||||||
# font.setBold(True)
|
# font.setBold(True)
|
||||||
|
|||||||
@ -146,7 +146,7 @@ class PlaylistTab(QTableView):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.musicmuster = musicmuster
|
self.musicmuster = musicmuster
|
||||||
self.playlist_id = playlist_id
|
self.playlist_id = playlist_id
|
||||||
self.setModel(PlaylistModel(playlist_id))
|
self.setModel(PlaylistModel(playlist_id, signals))
|
||||||
self.signals = signals
|
self.signals = signals
|
||||||
|
|
||||||
# Set up widget
|
# Set up widget
|
||||||
@ -202,6 +202,7 @@ class PlaylistTab(QTableView):
|
|||||||
self.horizontalHeader().sectionResized.connect(self._column_resize)
|
self.horizontalHeader().sectionResized.connect(self._column_resize)
|
||||||
# self.itemSelectionChanged.connect(self._select_event)
|
# self.itemSelectionChanged.connect(self._select_event)
|
||||||
# self.signals.set_next_track_signal.connect(self._reset_next)
|
# self.signals.set_next_track_signal.connect(self._reset_next)
|
||||||
|
self.signals.span_cells_signal.connect(self._span_cells)
|
||||||
|
|
||||||
# Load playlist rows
|
# Load playlist rows
|
||||||
# self.populate_display(session, self.playlist_id)
|
# self.populate_display(session, self.playlist_id)
|
||||||
@ -2379,6 +2380,13 @@ class PlaylistTab(QTableView):
|
|||||||
self.save_playlist(session)
|
self.save_playlist(session)
|
||||||
self._update_start_end_times(session)
|
self._update_start_end_times(session)
|
||||||
|
|
||||||
|
def _span_cells(self, row: int, column: int, rowSpan: int, columnSpan: int) -> None:
|
||||||
|
"""
|
||||||
|
Implement spanning of cells, initiated by signal
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.setSpan(row, column, rowSpan, columnSpan)
|
||||||
|
|
||||||
def _track_time_between_rows(
|
def _track_time_between_rows(
|
||||||
self, session: scoped_session, from_plr: PlaylistRows, to_plr: PlaylistRows
|
self, session: scoped_session, from_plr: PlaylistRows, to_plr: PlaylistRows
|
||||||
) -> Tuple[int, int]:
|
) -> Tuple[int, int]:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user