v0.79.0: the now-playing panel embosses on hover and a click goes to the current song

This commit is contained in:
2026-10-25 14:02:33 -07:00
parent 4a32baac3a
commit 1ad6956abe
5 changed files with 173 additions and 5 deletions
+82 -4
View File
@@ -77,8 +77,83 @@ TILE_STYLE = "".join(
def _nowplaying_style(bg: QColor) -> str:
"""Debossed: pushed in as far as the buttons stand out."""
return theme.deboss_qss("QFrame#nowPlayingBox", bg, radius=8)
"""Debossed: pushed in as far as the buttons stand out. While a song is
on it is also a button (Go to Current Song): under the cursor it stands
out in the buttons' hover face, and held it sinks, darker."""
sel = "QFrame#nowPlayingBox"
hover = bg.darker(theme.HOVER_DARKER)
down = bg.darker(theme.PRESSED_DARKER)
return (theme.deboss_qss(sel, bg, radius=8)
+ f'{sel}[face="hover"] {{ {theme.emboss_edges(hover)}'
f" background: {theme.emboss_gradient(hover)}; }}"
+ f'{sel}[face="down"] {{ {theme.deboss_edges(down)}'
f" background: {theme.emboss_gradient(down, pressed=True)}; }}")
class NowPlayingPanel(QFrame):
"""The now-playing panel. A QFrame has no :pressed in a style sheet, and
its :hover can't be switched off, so the face is a property."""
clicked = pyqtSignal()
def __init__(self, parent=None):
super().__init__(parent)
self.setObjectName("nowPlayingBox")
self._clickable = False
self._inside = False
self._held = False
def set_clickable(self, on: bool):
self._clickable = on
self._held = self._held and on
self.setCursor(Qt.CursorShape.PointingHandCursor if on
else Qt.CursorShape.ArrowCursor)
self.setToolTip("Go to Current Song" if on else "")
self._refresh()
def _refresh(self):
face = ""
if self._clickable and self._inside:
face = "down" if self._held else "hover"
if (self.property("face") or "") != face:
self.setProperty("face", face)
self.style().unpolish(self)
self.style().polish(self)
self.update()
def enterEvent(self, event):
super().enterEvent(event)
self._inside = True
self._refresh()
def leaveEvent(self, event):
super().leaveEvent(event)
self._inside = False
self._refresh()
def mousePressEvent(self, event):
if self._clickable and event.button() == Qt.MouseButton.LeftButton:
self._held = True
self._refresh()
return
super().mousePressEvent(event)
def mouseMoveEvent(self, event):
if self._held: # the press grabs the mouse: no enter/leave
self._inside = self.rect().contains(event.position().toPoint())
self._refresh()
super().mouseMoveEvent(event)
def mouseReleaseEvent(self, event):
if self._held and event.button() == Qt.MouseButton.LeftButton:
self._held = False
self._inside = self.rect().contains(event.position().toPoint())
self._refresh()
if self._inside and self._clickable:
self.clicked.emit()
return
super().mouseReleaseEvent(event)
# Title sits this many points above the artist/album line, both following the
# UI-scale app font (see theme.UI_SCALES).
@@ -385,6 +460,7 @@ class TransportBar(QWidget):
play_clicked = pyqtSignal() # MainWindow decides what "play" means
dj_toggled = pyqtSignal(bool)
volume_level_changed = pyqtSignal(float) # the slider, 0..1 perceptual
now_playing_clicked = pyqtSignal() # Go to Current Song
def __init__(self, player, manager, prefs, cast=None, airplay=None,
parent=None):
@@ -475,8 +551,8 @@ class TransportBar(QWidget):
# White rounded now-playing panel: holds only the song title and the
# artist/album line, centered, filling the zone above the seek row.
self._now_playing = QFrame()
self._now_playing.setObjectName("nowPlayingBox")
self._now_playing = NowPlayingPanel()
self._now_playing.clicked.connect(self.now_playing_clicked)
self._apply_now_playing_bg()
np = QVBoxLayout(self._now_playing)
np.setContentsMargins(12, 6, 12, 6)
@@ -658,6 +734,7 @@ class TransportBar(QWidget):
self._on_dj_button_icon(on)
self._dj_on = on
if on:
self._now_playing.set_clickable(False)
self.set_dj_titles(titles)
else:
self._on_track_changed(self._current_track)
@@ -1030,6 +1107,7 @@ class TransportBar(QWidget):
def _on_track_changed(self, track):
self._current_track = track
self._now_playing.set_clickable(track is not None and not self._dj_on)
if self._dj_on:
return # the panel names the decks' songs meanwhile
if track is None: