v0.61.0: buttons darken clearly while held; the play box is three touching buttons; taller scrubber; crisp art border
Held is now PRESSED_DARKER 125 (between Material 3 and GNOME), sunk, on every button. Transport boxes no longer carry the face themselves (a QFrame has no pressed state): each button does, so shuffle, repeat and bpm sink while held and the play box's tiles act as separate buttons with no grey hover patch. Scrollbar thumbs darken further while dragged. The seek bar's groove and knob are twice as tall. The album art meets a 1 px line in the lists' grey, without the pale blend that doubled it.
This commit is contained in:
@@ -198,6 +198,18 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
|
||||
(right: previous/next style, wrapping) — hit-tested on release. No
|
||||
double-click. Both big windows (visualizer, album art) close on a click
|
||||
or Esc.
|
||||
**Buttons** (Round 92): every one darkens on hover (`HOVER_DARKER`)
|
||||
and clearly more while held (`PRESSED_DARKER` 125, sunk) — between
|
||||
Material 3's 8 %→10 % and GNOME's 15 %→30 %; a checked toggle uses
|
||||
`CHECKED_DARKER`. A transport box draws nothing itself: its buttons
|
||||
carry the face (QFrame has no `:pressed`, so a face on the box could
|
||||
never sink), and the play box's three are separate touching buttons
|
||||
(`tile` property: square where they meet, one shared line). The seek
|
||||
slider has the `tall` property, which `ClickToJumpScrollStyle` reads to
|
||||
draw its groove and knob twice Fusion's height. With art, the sidebar
|
||||
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
|
||||
left a pale blend that read as a 2 px border on vivid covers.
|
||||
The playlist list's frame is a `sidebar.RoundedFrame` (Round 91): the
|
||||
panels' 8 px corners, painted *over* the list by a mouse-transparent
|
||||
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."""
|
||||
|
||||
__version__ = "0.60.0"
|
||||
__version__ = "0.61.0"
|
||||
|
||||
+13
-6
@@ -441,24 +441,31 @@ class SidebarArt(QWidget):
|
||||
face.darker(theme.HOVER_DARKER),
|
||||
NO_ART_RADIUS, like=CONTROL_HEIGHT)
|
||||
return
|
||||
if self._pixmap is None or self._pixmap.isNull():
|
||||
theme.paint_deboss(painter, rect,
|
||||
self.palette().alternateBase().color(),
|
||||
NO_ART_RADIUS, like=CONTROL_HEIGHT)
|
||||
if self._pixmap is None or self._pixmap.isNull():
|
||||
return
|
||||
# The cover fills the panel inside its border, so the border and its
|
||||
# darker top edge stay where they are with or without art.
|
||||
inside = rect.adjusted(1, 1, -1, -1)
|
||||
# The cover reaches the outline's centre and the line is drawn over
|
||||
# it, so the art meets a crisp 1 px line — inset half a pixel, the
|
||||
# antialiased clip left a pale blend of panel and art inside the
|
||||
# line that read as a second pixel of border. The line is the lists'
|
||||
# uniform frame grey (Round 92).
|
||||
clip = QPainterPath()
|
||||
clip.addRoundedRect(inside, NO_ART_RADIUS - 1, NO_ART_RADIUS - 1)
|
||||
clip.addRoundedRect(rect, NO_ART_RADIUS, NO_ART_RADIUS)
|
||||
painter.save()
|
||||
painter.setClipPath(clip)
|
||||
area = inside.toAlignedRect()
|
||||
area = self.rect().adjusted(0, NO_ART_GAP, 0, 0)
|
||||
scaled = self._pixmap.scaled(
|
||||
area.size(), Qt.AspectRatioMode.KeepAspectRatioByExpanding,
|
||||
Qt.TransformationMode.SmoothTransformation)
|
||||
x = area.left() + (area.width() - scaled.width()) // 2
|
||||
y = area.top() + (area.height() - scaled.height()) // 2
|
||||
painter.drawPixmap(x, y, scaled)
|
||||
painter.restore()
|
||||
from PyQt6.QtGui import QPen
|
||||
painter.setPen(QPen(frame_color(self.palette()), 1))
|
||||
painter.drawPath(clip)
|
||||
|
||||
|
||||
class PlaylistTree(QTreeWidget):
|
||||
|
||||
@@ -44,6 +44,14 @@ class ClickToJumpScrollStyle(QProxyStyle):
|
||||
|
||||
extent = 14
|
||||
|
||||
# A slider whose `tall` property is set (the seek bar) has its groove
|
||||
# and handle this many times Fusion's height; the handle keeps its width.
|
||||
TALL = 2
|
||||
|
||||
@staticmethod
|
||||
def _tall(widget) -> bool:
|
||||
return widget is not None and bool(widget.property("tall"))
|
||||
|
||||
def styleHint(self, hint, option=None, widget=None, returnData=None):
|
||||
if hint == QStyle.StyleHint.SH_ScrollBar_LeftClickAbsolutePosition:
|
||||
return 1
|
||||
@@ -54,9 +62,31 @@ class ClickToJumpScrollStyle(QProxyStyle):
|
||||
return self.extent
|
||||
if metric == QStyle.PixelMetric.PM_ScrollBarSliderMin:
|
||||
return self.extent * 2
|
||||
if metric in (QStyle.PixelMetric.PM_SliderThickness,
|
||||
QStyle.PixelMetric.PM_SliderControlThickness) \
|
||||
and self._tall(widget):
|
||||
return super().pixelMetric(metric, option, widget) * self.TALL
|
||||
return super().pixelMetric(metric, option, widget)
|
||||
|
||||
def subControlRect(self, control, option, sub, widget=None):
|
||||
if control == QStyle.ComplexControl.CC_Slider and self._tall(widget) \
|
||||
and sub == QStyle.SubControl.SC_SliderGroove:
|
||||
groove = super().subControlRect(control, option, sub, widget)
|
||||
center = groove.center()
|
||||
if option.orientation == Qt.Orientation.Horizontal:
|
||||
groove.setHeight(groove.height() * self.TALL)
|
||||
else:
|
||||
groove.setWidth(groove.width() * self.TALL)
|
||||
groove.moveCenter(center)
|
||||
return groove
|
||||
if control == QStyle.ComplexControl.CC_Slider and self._tall(widget) \
|
||||
and sub == QStyle.SubControl.SC_SliderHandle:
|
||||
handle = super().subControlRect(control, option, sub, widget)
|
||||
if option.orientation == Qt.Orientation.Horizontal:
|
||||
handle.moveTop(max(option.rect.top(), handle.top()))
|
||||
else:
|
||||
handle.moveLeft(max(option.rect.left(), handle.left()))
|
||||
return handle
|
||||
if control != QStyle.ComplexControl.CC_ScrollBar:
|
||||
return super().subControlRect(control, option, sub, widget)
|
||||
SC = QStyle.SubControl
|
||||
@@ -109,7 +139,11 @@ class ClickToJumpScrollStyle(QProxyStyle):
|
||||
and option.state & (QStyle.StateFlag.State_MouseOver
|
||||
| QStyle.StateFlag.State_Sunken))
|
||||
if hot:
|
||||
color = color.darker(theme.HOVER_DARKER)
|
||||
# A thumb is a button: darker under the cursor, darker
|
||||
# still while it's held and dragged.
|
||||
held = option.state & QStyle.StateFlag.State_Sunken
|
||||
color = color.darker(theme.PRESSED_DARKER if held
|
||||
else theme.HOVER_DARKER)
|
||||
theme.paint_emboss(painter, thumb, color, theme.BUTTON_RADIUS,
|
||||
like=theme.button_height_px(option.fontMetrics))
|
||||
painter.restore()
|
||||
|
||||
+28
-28
@@ -41,35 +41,31 @@ TOP = Qt.AlignmentFlag.AlignTop
|
||||
# (Library button · search or playlist name · seek) at the medium UI scale.
|
||||
BAR_HEIGHT = TOP_MARGIN + CONTROL_HEIGHT + ROW_GAP + 34
|
||||
|
||||
def _box_style(bg: QColor, button: bool = False) -> str:
|
||||
"""A transport box. A box that *is* one button (shuffle, bpm) gets the
|
||||
shared button face — emboss, outline, whole-box darkening on hover; the
|
||||
three-tile play box gets the same face, and each tile darkens on its own
|
||||
(see TILE_STYLE)."""
|
||||
face = theme.button_face_qss("QFrame#transportBox", bg, radius=8)
|
||||
if not button:
|
||||
# Hover belongs to the tiles here, not the whole box.
|
||||
face += (f"QFrame#transportBox:hover {{ background:"
|
||||
f" {theme.emboss_gradient(bg)}; }}")
|
||||
def _box_style(bg: QColor) -> str:
|
||||
"""A transport box is its buttons: each one carries the shared button
|
||||
face (emboss, outline, darker on hover, sunk and darker while held), and
|
||||
the box itself draws nothing. The play box's three are separate buttons
|
||||
that touch — square where they meet, sharing one line (TILE_STYLE)."""
|
||||
face = "QFrame#transportBox { border: none; background: transparent; }"
|
||||
for kind in ("QToolButton", "QPushButton"):
|
||||
face += theme.button_face_qss(f"QFrame#transportBox > {kind}", bg,
|
||||
radius=8)
|
||||
return face + TILE_STYLE
|
||||
|
||||
|
||||
# Tool buttons inside a box: no light panel of their own. A tile in the play
|
||||
# box darkens slightly under the cursor — the same "whole button, a little
|
||||
# darker" as every other button — and a lone button leaves that to its box.
|
||||
TILE_STYLE = """
|
||||
QFrame#transportBox QToolButton, QFrame#transportBox QPushButton {
|
||||
border: none; background: transparent; border-radius: 6px;
|
||||
}
|
||||
# Where tiles meet: square corners, and one shared line (the later tile
|
||||
# drops its left border), as the Library button and its ▾ do.
|
||||
TILE_STYLE = "".join(
|
||||
f"QFrame#transportBox > {kind}[tile=\"{tile}\"] {{ {rule} }}"
|
||||
for kind in ("QToolButton", "QPushButton")
|
||||
for tile, rule in (
|
||||
("first", "border-top-right-radius: 0; border-bottom-right-radius: 0;"),
|
||||
("middle", "border-radius: 0; border-left: none;"),
|
||||
("last", "border-top-left-radius: 0; border-bottom-left-radius: 0;"
|
||||
" border-left: none;"))) + """
|
||||
QFrame#transportBox QPushButton, QFrame#transportBox QPushButton:disabled {
|
||||
color: black;
|
||||
}
|
||||
QFrame#transportBox[tiles="true"] QToolButton:hover {
|
||||
background: rgba(0, 0, 0, 22);
|
||||
}
|
||||
QFrame#transportBox[tiles="true"] QToolButton:pressed {
|
||||
background: rgba(0, 0, 0, 38);
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
@@ -133,12 +129,15 @@ def _box(*widgets, bg: QColor, margins=(10, 3, 10, 3), hug=False,
|
||||
a full-bleed tap target with its content centered in its share."""
|
||||
frame = QFrame()
|
||||
frame.setObjectName("transportBox")
|
||||
# A box holding one control is that control: it darkens as a whole.
|
||||
frame.setProperty("tiles", len(widgets) > 1)
|
||||
frame.setAttribute(Qt.WidgetAttribute.WA_Hover)
|
||||
frame.setStyleSheet(_box_style(bg, button=len(widgets) == 1))
|
||||
if len(widgets) > 1:
|
||||
for i, widget in enumerate(widgets):
|
||||
widget.setProperty("tile", "first" if i == 0 else
|
||||
"last" if i == len(widgets) - 1 else "middle")
|
||||
frame.setStyleSheet(_box_style(bg))
|
||||
inner = QHBoxLayout(frame)
|
||||
inner.setContentsMargins(*margins)
|
||||
# A split box is all button, edge to edge: the face is the buttons'.
|
||||
inner.setContentsMargins(*((0, 0, 0, 0) if split else margins))
|
||||
if split:
|
||||
inner.setSpacing(0)
|
||||
for widget in widgets:
|
||||
@@ -492,6 +491,7 @@ class TransportBar(QWidget):
|
||||
self._remaining_label.setAlignment(Qt.AlignmentFlag.AlignRight
|
||||
| Qt.AlignmentFlag.AlignBottom)
|
||||
self._slider = SeekSlider()
|
||||
self._slider.setProperty("tall", True) # twice Fusion's height
|
||||
self._slider.setRange(0, 0)
|
||||
self._slider.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||
# The row reaches below the floor by the text's descent (so the
|
||||
@@ -670,7 +670,7 @@ class TransportBar(QWidget):
|
||||
button.refresh_icons()
|
||||
box_bg = theme.gray(theme.gray_value(self._prefs, "color_button"))
|
||||
for box in self._boxes:
|
||||
box.setStyleSheet(_box_style(box_bg, button=not box.property("tiles")))
|
||||
box.setStyleSheet(_box_style(box_bg))
|
||||
self._apply_now_playing_bg()
|
||||
self._apply_now_playing_font()
|
||||
self._visualizer.update() # dim-mode bar color may have changed
|
||||
|
||||
+5
-2
@@ -208,7 +208,10 @@ EMBOSS_RIM = 116
|
||||
EMBOSS_RIM_WIDTH = 0.08 # fraction of the height each rim takes
|
||||
BUTTON_RADIUS = 4 # every button's corners, and the scrollbar thumb's
|
||||
HOVER_DARKER = 107 # hover: the whole button, slightly darker
|
||||
PRESSED_DARKER = 112
|
||||
# Held down: clearly darker again (Round 92) — between Material 3's state
|
||||
# layers (hover 8 %, pressed 10 %) and GNOME's buttons (15 % → 30 %).
|
||||
PRESSED_DARKER = 125
|
||||
CHECKED_DARKER = 112 # a toggle that is on (checked), not held
|
||||
|
||||
|
||||
def emboss_edges(color: QColor) -> str:
|
||||
@@ -332,7 +335,7 @@ def button_emboss_qss(button: QColor) -> str:
|
||||
return button_face_qss(
|
||||
"QPushButton:!flat", button,
|
||||
extra="padding: 3px 12px; min-height: 1.3em;",
|
||||
checked_color=button.darker(PRESSED_DARKER)) + \
|
||||
checked_color=button.darker(CHECKED_DARKER)) + \
|
||||
"QPushButton:!flat:default { border-color: palette(highlight); }" \
|
||||
"QPushButton:!flat:disabled { color: palette(mid); }"
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ class TestEmboss:
|
||||
sidebar = SidebarPanel(manager, MagicMock())
|
||||
for qss in (sidebar.library_button.styleSheet(),
|
||||
sidebar.friend_button.styleSheet(),
|
||||
_box_style(QColor("#dddddd"), button=True),
|
||||
_box_style(QColor("#dddddd")),
|
||||
cassette_art.friend_button_qss()):
|
||||
assert ":hover" in qss
|
||||
assert "border-bottom-color" in qss
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
"""Round 92: a twice-as-tall scrubber, buttons that darken clearly while
|
||||
held (the transport's included — the play box is three touching buttons),
|
||||
and the album art's border a crisp 1 px of the lists' grey."""
|
||||
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QColor, QPixmap
|
||||
from PyQt6.QtWidgets import QSlider, QStyle, QStyleOptionSlider
|
||||
|
||||
from lintunes import theme
|
||||
from tests.test_round49 import _FakePlayer
|
||||
|
||||
|
||||
def _rects(qapp, tall):
|
||||
from lintunes.gui.track_table import ClickToJumpScrollStyle
|
||||
style = ClickToJumpScrollStyle()
|
||||
slider = QSlider(Qt.Orientation.Horizontal)
|
||||
slider.setStyle(style)
|
||||
slider.setProperty("tall", tall)
|
||||
slider.resize(200, slider.sizeHint().height())
|
||||
option = QStyleOptionSlider()
|
||||
slider.initStyleOption(option)
|
||||
cc, sc = QStyle.ComplexControl.CC_Slider, QStyle.SubControl
|
||||
return (slider.sizeHint().height(),
|
||||
style.subControlRect(cc, option, sc.SC_SliderGroove, slider),
|
||||
style.subControlRect(cc, option, sc.SC_SliderHandle, slider))
|
||||
|
||||
|
||||
def test_the_scrubber_is_twice_as_tall(qapp):
|
||||
hint, groove, handle = _rects(qapp, False)
|
||||
tall_hint, tall_groove, tall_handle = _rects(qapp, True)
|
||||
assert tall_hint == 2 * hint
|
||||
assert tall_groove.height() == 2 * groove.height()
|
||||
assert tall_handle.height() == 2 * handle.height()
|
||||
assert tall_handle.width() == handle.width()
|
||||
assert tall_handle.top() >= 0
|
||||
|
||||
|
||||
def test_held_is_clearly_darker_than_hover():
|
||||
assert theme.PRESSED_DARKER - 100 >= 2 * (theme.HOVER_DARKER - 100)
|
||||
qss = theme.button_face_qss("QPushButton", QColor("#c0c0c0"))
|
||||
pressed = qss.split("QPushButton:pressed {", 1)[1].split("}", 1)[0]
|
||||
assert QColor("#c0c0c0").darker(theme.PRESSED_DARKER).name() in pressed
|
||||
|
||||
|
||||
def test_transport_buttons_carry_their_own_face(qapp):
|
||||
from lintunes.gui.transport import TransportBar
|
||||
from lintunes.preferences import Preferences
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
player = MagicMock()
|
||||
player.repeat_mode.return_value = "off"
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
bar = TransportBar(player, MagicMock(), Preferences(Path(d)))
|
||||
assert [b.property("tile") for b in
|
||||
(bar._prev_btn, bar._play_btn, bar._next_btn)] == [
|
||||
"first", "middle", "last"]
|
||||
assert bar._shuffle_btn.property("tile") is None
|
||||
qss = bar._shuffle_btn.parentWidget().styleSheet()
|
||||
assert "QFrame#transportBox > QToolButton:pressed" in qss
|
||||
assert "QFrame#transportBox > QToolButton:hover" in qss
|
||||
assert "rgba(" not in qss # no grey patch on hover
|
||||
|
||||
|
||||
def test_the_art_meets_one_pixel_of_frame_grey(qapp):
|
||||
from lintunes.gui.sidebar import NO_ART_GAP, SidebarArt, frame_color
|
||||
art = SidebarArt(_FakePlayer())
|
||||
art.resize(100, 100 + NO_ART_GAP)
|
||||
pink = QPixmap(50, 50)
|
||||
pink.fill(QColor("#e8457a"))
|
||||
art._track = SimpleNamespace(track_id=1)
|
||||
art._pixmap = pink
|
||||
image = art.grab().toImage()
|
||||
middle = NO_ART_GAP + 50
|
||||
line = frame_color(art.palette()).name()
|
||||
assert image.pixelColor(0, middle).name() == line
|
||||
assert image.pixelColor(1, middle).name() == "#e8457a"
|
||||
assert image.pixelColor(50, NO_ART_GAP).name() == line
|
||||
assert image.pixelColor(50, NO_ART_GAP + 1).name() == "#e8457a"
|
||||
Reference in New Issue
Block a user