v0.79.0: the now-playing panel embosses on hover and a click goes to the current song
This commit is contained in:
@@ -229,6 +229,10 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
|
|||||||
panel draws the cover to the outline's centre and the 1 px line over it
|
panel draws the cover to the outline's centre and the 1 px line over it
|
||||||
in the lists' grey (`frame_color`); inset by half a pixel, the clip
|
in the lists' grey (`frame_color`); inset by half a pixel, the clip
|
||||||
left a pale blend that read as a 2 px border on vivid covers.
|
left a pale blend that read as a 2 px border on vivid covers.
|
||||||
|
The now-playing panel (`transport.NowPlayingPanel`, Round 110) is a
|
||||||
|
Go to Current Song button while a song is on (not in DJ mode): raised
|
||||||
|
in the hover face under the cursor, sunk and darker while held. Its
|
||||||
|
face is a `face` property, since a QFrame has no `:pressed`.
|
||||||
The playlist list's frame is a `sidebar.RoundedFrame` (Round 91): the
|
The playlist list's frame is a `sidebar.RoundedFrame` (Round 91): the
|
||||||
panels' 8 px corners, painted *over* the list by a mouse-transparent
|
panels' 8 px corners, painted *over* the list by a mouse-transparent
|
||||||
overlay (window color outside the curve, then Fusion's own frame line,
|
overlay (window color outside the curve, then Fusion's own frame line,
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||||
|
|
||||||
__version__ = "0.78.0"
|
__version__ = "0.79.0"
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
# Wiring
|
# Wiring
|
||||||
self._transport.play_clicked.connect(self.play_pause)
|
self._transport.play_clicked.connect(self.play_pause)
|
||||||
|
self._transport.now_playing_clicked.connect(self._go_to_current_song)
|
||||||
self._sidebar.library_selected.connect(self._show_library)
|
self._sidebar.library_selected.connect(self._show_library)
|
||||||
self._sidebar.friend_selector_clicked.connect(
|
self._sidebar.friend_selector_clicked.connect(
|
||||||
self._cassette.show_friend_menu)
|
self._cassette.show_friend_menu)
|
||||||
|
|||||||
@@ -77,8 +77,83 @@ TILE_STYLE = "".join(
|
|||||||
|
|
||||||
|
|
||||||
def _nowplaying_style(bg: QColor) -> str:
|
def _nowplaying_style(bg: QColor) -> str:
|
||||||
"""Debossed: pushed in as far as the buttons stand out."""
|
"""Debossed: pushed in as far as the buttons stand out. While a song is
|
||||||
return theme.deboss_qss("QFrame#nowPlayingBox", bg, radius=8)
|
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
|
# Title sits this many points above the artist/album line, both following the
|
||||||
# UI-scale app font (see theme.UI_SCALES).
|
# UI-scale app font (see theme.UI_SCALES).
|
||||||
@@ -385,6 +460,7 @@ class TransportBar(QWidget):
|
|||||||
play_clicked = pyqtSignal() # MainWindow decides what "play" means
|
play_clicked = pyqtSignal() # MainWindow decides what "play" means
|
||||||
dj_toggled = pyqtSignal(bool)
|
dj_toggled = pyqtSignal(bool)
|
||||||
volume_level_changed = pyqtSignal(float) # the slider, 0..1 perceptual
|
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,
|
def __init__(self, player, manager, prefs, cast=None, airplay=None,
|
||||||
parent=None):
|
parent=None):
|
||||||
@@ -475,8 +551,8 @@ class TransportBar(QWidget):
|
|||||||
|
|
||||||
# White rounded now-playing panel: holds only the song title and the
|
# White rounded now-playing panel: holds only the song title and the
|
||||||
# artist/album line, centered, filling the zone above the seek row.
|
# artist/album line, centered, filling the zone above the seek row.
|
||||||
self._now_playing = QFrame()
|
self._now_playing = NowPlayingPanel()
|
||||||
self._now_playing.setObjectName("nowPlayingBox")
|
self._now_playing.clicked.connect(self.now_playing_clicked)
|
||||||
self._apply_now_playing_bg()
|
self._apply_now_playing_bg()
|
||||||
np = QVBoxLayout(self._now_playing)
|
np = QVBoxLayout(self._now_playing)
|
||||||
np.setContentsMargins(12, 6, 12, 6)
|
np.setContentsMargins(12, 6, 12, 6)
|
||||||
@@ -658,6 +734,7 @@ class TransportBar(QWidget):
|
|||||||
self._on_dj_button_icon(on)
|
self._on_dj_button_icon(on)
|
||||||
self._dj_on = on
|
self._dj_on = on
|
||||||
if on:
|
if on:
|
||||||
|
self._now_playing.set_clickable(False)
|
||||||
self.set_dj_titles(titles)
|
self.set_dj_titles(titles)
|
||||||
else:
|
else:
|
||||||
self._on_track_changed(self._current_track)
|
self._on_track_changed(self._current_track)
|
||||||
@@ -1030,6 +1107,7 @@ class TransportBar(QWidget):
|
|||||||
|
|
||||||
def _on_track_changed(self, track):
|
def _on_track_changed(self, track):
|
||||||
self._current_track = track
|
self._current_track = track
|
||||||
|
self._now_playing.set_clickable(track is not None and not self._dj_on)
|
||||||
if self._dj_on:
|
if self._dj_on:
|
||||||
return # the panel names the decks' songs meanwhile
|
return # the panel names the decks' songs meanwhile
|
||||||
if track is None:
|
if track is None:
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
"""Round 110: the now-playing panel is a Go to Current Song button."""
|
||||||
|
from PyQt6.QtCore import QEvent, QPointF, Qt
|
||||||
|
from PyQt6.QtGui import QEnterEvent, QMouseEvent
|
||||||
|
|
||||||
|
from lintunes.gui.transport import NowPlayingPanel
|
||||||
|
|
||||||
|
|
||||||
|
def _mouse(kind, x=5, y=5):
|
||||||
|
return QMouseEvent(kind, QPointF(x, y), QPointF(x, y),
|
||||||
|
Qt.MouseButton.LeftButton,
|
||||||
|
Qt.MouseButton.LeftButton if kind != QEvent.Type.MouseButtonRelease
|
||||||
|
else Qt.MouseButton.NoButton,
|
||||||
|
Qt.KeyboardModifier.NoModifier)
|
||||||
|
|
||||||
|
|
||||||
|
def _enter(panel):
|
||||||
|
panel.enterEvent(QEnterEvent(QPointF(5, 5), QPointF(5, 5), QPointF(5, 5)))
|
||||||
|
|
||||||
|
|
||||||
|
def test_hover_embosses_and_a_click_goes_to_the_song(qapp):
|
||||||
|
panel = NowPlayingPanel()
|
||||||
|
panel.resize(200, 60)
|
||||||
|
clicks = []
|
||||||
|
panel.clicked.connect(lambda: clicks.append(1))
|
||||||
|
panel.set_clickable(True)
|
||||||
|
assert not panel.property("face")
|
||||||
|
_enter(panel)
|
||||||
|
assert panel.property("face") == "hover"
|
||||||
|
panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress))
|
||||||
|
assert panel.property("face") == "down"
|
||||||
|
panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease))
|
||||||
|
assert clicks == [1] and panel.property("face") == "hover"
|
||||||
|
panel.leaveEvent(QEvent(QEvent.Type.Leave))
|
||||||
|
assert not panel.property("face")
|
||||||
|
|
||||||
|
|
||||||
|
def test_released_outside_is_no_click(qapp):
|
||||||
|
panel = NowPlayingPanel()
|
||||||
|
panel.resize(200, 60)
|
||||||
|
clicks = []
|
||||||
|
panel.clicked.connect(lambda: clicks.append(1))
|
||||||
|
panel.set_clickable(True)
|
||||||
|
_enter(panel)
|
||||||
|
panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress))
|
||||||
|
panel.mouseMoveEvent(_mouse(QEvent.Type.MouseMove, 400, 5))
|
||||||
|
assert not panel.property("face")
|
||||||
|
panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease, 400, 5))
|
||||||
|
assert clicks == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_nothing_playing_is_just_a_panel(qapp):
|
||||||
|
panel = NowPlayingPanel()
|
||||||
|
clicks = []
|
||||||
|
panel.clicked.connect(lambda: clicks.append(1))
|
||||||
|
_enter(panel)
|
||||||
|
panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress))
|
||||||
|
panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease))
|
||||||
|
assert clicks == [] and not panel.property("face")
|
||||||
|
|
||||||
|
|
||||||
|
def test_window_wires_it_to_go_to_current_song(qapp, tmp_path, monkeypatch):
|
||||||
|
from lintunes.gui.main_window import MainWindow
|
||||||
|
from lintunes.library_manager import LibraryManager
|
||||||
|
from lintunes.models.library import Library
|
||||||
|
from lintunes.models.track import Track
|
||||||
|
from lintunes.preferences import Preferences
|
||||||
|
library = Library()
|
||||||
|
library.tracks[1] = Track(track_id=1, name="Song", artist="A")
|
||||||
|
manager = LibraryManager(library, tmp_path / "data")
|
||||||
|
went = []
|
||||||
|
monkeypatch.setattr(MainWindow, "_go_to_current_song",
|
||||||
|
lambda self: went.append(1))
|
||||||
|
window = MainWindow(manager, Preferences(tmp_path / "data"))
|
||||||
|
try:
|
||||||
|
window._transport.now_playing_clicked.emit()
|
||||||
|
assert went == [1]
|
||||||
|
panel = window._transport._now_playing
|
||||||
|
window._transport._on_track_changed(library.tracks[1])
|
||||||
|
assert panel._clickable
|
||||||
|
window._transport.set_dj_mode(True)
|
||||||
|
assert not panel._clickable
|
||||||
|
window._transport.set_dj_mode(False)
|
||||||
|
assert panel._clickable
|
||||||
|
finally:
|
||||||
|
window.close()
|
||||||
Reference in New Issue
Block a user