forked from trav/lintunes
v0.47.1: the no-art panel sits on the window, shaded like the visualizer
With no art, the sidebar's art widget moves out of the playlist list's frame onto the window below it, so the panel is set into the gray like the visualizer rather than into a white box. A tall debossed panel is now shaded along its top and bottom exactly as the 62 px visualizer is, flat in the visualizer's color between, instead of one gradient stretched over its whole height, which read as gray. The scrollbar thumb is shaded the same way, like a button.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||
|
||||
__version__ = "0.47.0"
|
||||
__version__ = "0.47.1"
|
||||
|
||||
+40
-17
@@ -94,8 +94,10 @@ class SidebarPanel(QWidget):
|
||||
inner.setSpacing(0)
|
||||
inner.addWidget(self._lists, stretch=1)
|
||||
self.art = SidebarArt(player)
|
||||
inner.addWidget(self.art)
|
||||
layout.addWidget(group, stretch=1)
|
||||
self._inner, self._outer = inner, layout
|
||||
self.art.has_art_changed.connect(self._place_art)
|
||||
self._place_art(False)
|
||||
# What the header row lines the Library button up with.
|
||||
self.list_area = group
|
||||
|
||||
@@ -107,6 +109,14 @@ class SidebarPanel(QWidget):
|
||||
self.friend_list.playlist_selected.connect(self._on_friend_playlist)
|
||||
self.friend_list.follow_toggled.connect(self.follow_toggled)
|
||||
|
||||
def _place_art(self, has_art: bool):
|
||||
"""Art goes inside the list's frame; the empty panel below it, on
|
||||
the window, where it reads as set into the window like the
|
||||
visualizer rather than as a box inside a white one."""
|
||||
for lay in (self._inner, self._outer):
|
||||
lay.removeWidget(self.art)
|
||||
(self._inner if has_art else self._outer).addWidget(self.art)
|
||||
|
||||
def _on_library_clicked(self):
|
||||
self.library_button.setChecked(True)
|
||||
if self.friend_mode:
|
||||
@@ -253,17 +263,21 @@ class FriendPlaylistList(QListWidget):
|
||||
self.playlist_selected.emit(current.data(Qt.ItemDataRole.UserRole))
|
||||
|
||||
|
||||
# The no-art panel: inset from the list's edges, corners like the visualizer's.
|
||||
NO_ART_MARGIN = 6
|
||||
# The no-art panel: on the window under the list's frame, this far below
|
||||
# it, with the visualizer's corners.
|
||||
NO_ART_GAP = 6
|
||||
NO_ART_RADIUS = 8
|
||||
|
||||
|
||||
class SidebarArt(QWidget):
|
||||
"""Square album art pinned to the sidebar bottom; an empty debossed panel
|
||||
when the current track has no embedded art. A click opens the big art window, or,
|
||||
on the gray square, asks for the track's art to be downloaded."""
|
||||
"""Square album art pinned to the sidebar bottom, inside the playlist
|
||||
list's frame. With no embedded art it is an empty panel instead, set
|
||||
into the window below the frame like the visualizer (SidebarPanel moves
|
||||
it on ``has_art_changed``). A click opens the big art window, or, on the
|
||||
empty panel, asks for the track's art to be downloaded."""
|
||||
|
||||
download_art_requested = pyqtSignal(int) # track id
|
||||
has_art_changed = pyqtSignal(bool)
|
||||
|
||||
def __init__(self, player, parent=None):
|
||||
super().__init__(parent)
|
||||
@@ -290,7 +304,14 @@ class SidebarArt(QWidget):
|
||||
self.setToolTip("")
|
||||
if self._art_window.isVisible():
|
||||
self._art_window.set_artwork(self._pixmap, self._title())
|
||||
self._fit_height()
|
||||
self.update()
|
||||
if self.has_art() != getattr(self, "_had_art", None):
|
||||
self._had_art = self.has_art()
|
||||
self.has_art_changed.emit(self._had_art)
|
||||
|
||||
def has_art(self) -> bool:
|
||||
return self._pixmap is not None and not self._pixmap.isNull()
|
||||
|
||||
def refresh(self):
|
||||
"""Re-read art for the current track (after tag edits)."""
|
||||
@@ -302,10 +323,15 @@ class SidebarArt(QWidget):
|
||||
return (" — ".join(p for p in (self._track.artist, self._track.album) if p)
|
||||
or self._track.name)
|
||||
|
||||
def _fit_height(self):
|
||||
# Keep it square: height follows the sidebar's width (plus the gap
|
||||
# above the empty panel)
|
||||
height = self.width() + (0 if self.has_art() else NO_ART_GAP)
|
||||
if self.height() != height:
|
||||
self.setFixedHeight(height)
|
||||
|
||||
def resizeEvent(self, event):
|
||||
# Keep it square: height follows the sidebar's width
|
||||
if self.height() != self.width():
|
||||
self.setFixedHeight(self.width())
|
||||
self._fit_height()
|
||||
super().resizeEvent(event)
|
||||
|
||||
def mouseReleaseEvent(self, event):
|
||||
@@ -323,17 +349,14 @@ class SidebarArt(QWidget):
|
||||
def paintEvent(self, event):
|
||||
painter = QPainter(self)
|
||||
if self._pixmap is None or self._pixmap.isNull():
|
||||
# No art: the list's own background, and in it a rounded panel
|
||||
# debossed like the visualizer and the now-playing panel.
|
||||
painter.fillRect(self.rect(), self.palette().base())
|
||||
# No art: straight onto the window, a panel debossed in the
|
||||
# visualizer's color and shaded at its edges as the visualizer is.
|
||||
from lintunes.gui.transport import CONTROL_HEIGHT
|
||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
rect = QRectF(self.rect()).adjusted(
|
||||
NO_ART_MARGIN + 0.5, NO_ART_MARGIN + 0.5,
|
||||
-NO_ART_MARGIN - 0.5, -NO_ART_MARGIN - 0.5)
|
||||
rect = QRectF(self.rect()).adjusted(0.5, NO_ART_GAP + 0.5, -0.5, -0.5)
|
||||
theme.paint_deboss(painter, rect,
|
||||
self.palette().alternateBase().color(),
|
||||
NO_ART_RADIUS,
|
||||
rim=theme.button_rim_px(self.fontMetrics()))
|
||||
NO_ART_RADIUS, like=CONTROL_HEIGHT)
|
||||
return
|
||||
scaled = self._pixmap.scaled(
|
||||
self.size(), Qt.AspectRatioMode.KeepAspectRatioByExpanding,
|
||||
|
||||
@@ -111,7 +111,7 @@ class ClickToJumpScrollStyle(QProxyStyle):
|
||||
if hot:
|
||||
color = color.darker(theme.HOVER_DARKER)
|
||||
theme.paint_emboss(painter, thumb, color, theme.BUTTON_RADIUS,
|
||||
rim=theme.button_rim_px(option.fontMetrics))
|
||||
like=theme.button_height_px(option.fontMetrics))
|
||||
painter.restore()
|
||||
|
||||
|
||||
|
||||
+26
-22
@@ -236,13 +236,15 @@ def deboss_qss(selector: str, color: QColor, *, radius: int = 8,
|
||||
|
||||
|
||||
def paint_deboss(painter, rect, color: QColor, radius: float,
|
||||
rim: float | None = None):
|
||||
like: float | None = None):
|
||||
"""``deboss_qss`` for a widget that paints itself: fills ``rect`` (a
|
||||
QRectF) as a debossed rounded panel and returns its path, for clipping.
|
||||
``rim`` (pixels) fixes the rims' height for a panel much taller than a
|
||||
button; without it they're ``EMBOSS_RIM_WIDTH`` of the height."""
|
||||
``like`` (pixels) shades a panel taller than that exactly as a panel
|
||||
``like`` tall is shaded along its top and bottom, flat in between, so a
|
||||
tall panel is recessed as much as a short one rather than gray at the
|
||||
top."""
|
||||
from PyQt6.QtGui import QPen
|
||||
path = _fill_embossed(painter, rect, color, radius, rim, pressed=True)
|
||||
path = _fill_embossed(painter, rect, color, radius, like, pressed=True)
|
||||
painter.setPen(QPen(color.darker(135), 1))
|
||||
painter.drawPath(path)
|
||||
# the darker top edge
|
||||
@@ -255,38 +257,40 @@ def paint_deboss(painter, rect, color: QColor, radius: float,
|
||||
|
||||
|
||||
def _fill_embossed(painter, rect, color: QColor, radius: float,
|
||||
rim: float | None, pressed: bool):
|
||||
"""Fill a rounded ``rect`` with ``emboss_stops``; ``rim`` in pixels, or
|
||||
None for the stops' own fractions. Returns the path."""
|
||||
like: float | None, pressed: bool):
|
||||
"""Fill a rounded ``rect`` with ``emboss_stops``, shaded as a shape
|
||||
``like`` pixels tall would be at its top and bottom (None: as itself).
|
||||
Returns the path."""
|
||||
from PyQt6.QtCore import QPointF
|
||||
from PyQt6.QtGui import QLinearGradient, QPainterPath
|
||||
path = QPainterPath()
|
||||
path.addRoundedRect(rect, radius, radius)
|
||||
height = max(rect.height(), 1.0)
|
||||
scale = min(like, height) / height if like else 1.0
|
||||
stops = emboss_stops(color, pressed)
|
||||
if rim is not None:
|
||||
edge = min(rim / max(rect.height(), 1.0), 0.49)
|
||||
stops = [(pos, c) for pos, (_, c) in zip([0, edge, 0.5, 1 - edge, 1], stops)]
|
||||
middle = stops[2][1]
|
||||
top = [(pos * scale, c) for pos, c in stops[:3]]
|
||||
bottom = [(1 - (1 - pos) * scale, c) for pos, c in stops[2:]]
|
||||
gradient = QLinearGradient(QPointF(0, rect.top()), QPointF(0, rect.bottom()))
|
||||
for pos, stop in stops:
|
||||
for pos, stop in top + [(top[-1][0], middle)] + bottom:
|
||||
gradient.setColorAt(pos, stop)
|
||||
painter.fillPath(path, gradient)
|
||||
return path
|
||||
|
||||
|
||||
def button_rim_px(metrics) -> float:
|
||||
"""How tall a button's rims are, in pixels, for a font with these
|
||||
QFontMetrics: ``EMBOSS_RIM_WIDTH`` of a button's height, which is the
|
||||
text line plus padding, outline and Fusion's margin (14 px). For things
|
||||
shaped otherwise (a scrollbar thumb) that still want a button's emboss."""
|
||||
return EMBOSS_RIM_WIDTH * (metrics.height() + 14)
|
||||
def button_height_px(metrics) -> int:
|
||||
"""How tall a button is for a font with these QFontMetrics: the text
|
||||
line plus padding, outline and Fusion's margin (14 px). For things shaped
|
||||
otherwise (a scrollbar thumb) that still want a button's emboss."""
|
||||
return metrics.height() + 14
|
||||
|
||||
|
||||
def paint_emboss(painter, rect, color: QColor, radius: float, rim: float):
|
||||
"""A button's face for a widget that paints itself: ``emboss_stops`` lit
|
||||
from above, but with rims ``rim`` pixels tall whatever ``rect``'s height,
|
||||
so a long scrollbar thumb is embossed exactly as much as a button."""
|
||||
def paint_emboss(painter, rect, color: QColor, radius: float, like: float):
|
||||
"""A button's face for a widget that paints itself: shaded at its top
|
||||
and bottom exactly as a button ``like`` pixels tall, flat in between, so
|
||||
a long scrollbar thumb is embossed exactly as much as a button."""
|
||||
from PyQt6.QtGui import QPen
|
||||
path = _fill_embossed(painter, rect, color, radius, rim, pressed=False)
|
||||
path = _fill_embossed(painter, rect, color, radius, like, pressed=False)
|
||||
painter.setPen(QPen(color.darker(135), 1))
|
||||
painter.drawPath(path)
|
||||
# the darker bottom edge (emboss_edges)
|
||||
|
||||
Reference in New Issue
Block a user