forked from trav/lintunes
v0.85.0: every slider tall and click-to-jump, Light | Dark as folder tabs, album art shows it's clickable (finger, tooltip, keyboard focus)
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||
|
||||
__version__ = "0.84.1"
|
||||
__version__ = "0.85.0"
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
"""Folder tabs after classic Mac OS (the Platinum look of OS 8 and 9), in
|
||||
the house style (shared-resources' design page, #tabs): slanted sides with
|
||||
8 px top corners, the tabs behind are buttons (embossed in the button
|
||||
gray, darker on hover, sunk while held), and the open tab in front is the
|
||||
page's own color with only the top rim, open at the foot so it runs into
|
||||
the page. All stand on one baseline, overlapping a little.
|
||||
|
||||
Each tab is a checkable QToolButton that paints itself, so the window's
|
||||
QButtonGroup logic is unchanged; `TabStrip` holds them, overlapping a little
|
||||
the way the real ones did, and draws the baseline they stand on. The tab
|
||||
in front is raised above its neighbours, so its feet cover theirs."""
|
||||
from __future__ import annotations
|
||||
|
||||
from PyQt6.QtCore import QPointF, QSize, Qt
|
||||
from PyQt6.QtGui import QLinearGradient, QPainter, QPainterPath, QPalette, QPen
|
||||
from PyQt6.QtWidgets import QToolButton, QWidget
|
||||
|
||||
from lintunes import theme
|
||||
|
||||
OVERLAP = 9 # px adjacent tabs overlap at their slanted feet
|
||||
RADIUS = 8 # the top corners: the big buttons' radius
|
||||
SLANT = 0.28 # each side's run, as a share of the height
|
||||
OUTLINE = 135 # the buttons' outline, darker(135)
|
||||
|
||||
|
||||
def _slant(h: int) -> float:
|
||||
return h * SLANT
|
||||
|
||||
|
||||
def baseline_color(palette):
|
||||
return palette.color(QPalette.ColorRole.Window).darker(OUTLINE)
|
||||
|
||||
|
||||
class MacTab(QToolButton):
|
||||
def __init__(self, text: str, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setText(text)
|
||||
self.setCheckable(True)
|
||||
self.toggled.connect(lambda on: on and self.raise_())
|
||||
|
||||
def sizeHint(self) -> QSize:
|
||||
fm = self.fontMetrics()
|
||||
h = fm.height() + 12
|
||||
return QSize(int(fm.horizontalAdvance(self.text()) + 2 * _slant(h) + 18), h)
|
||||
|
||||
def minimumSizeHint(self) -> QSize:
|
||||
return self.sizeHint()
|
||||
|
||||
def _outline(self) -> QPainterPath:
|
||||
"""Up the left slope, round the top corners, down the right slope;
|
||||
open along the foot."""
|
||||
w, h, s = self.width(), self.height(), _slant(self.height())
|
||||
top, foot = 0.5, float(h)
|
||||
side = ((s - 0.5) ** 2 + (foot - top) ** 2) ** 0.5
|
||||
r = min(RADIUS, side / 2)
|
||||
# where the curve starts, back down each slope
|
||||
dx, dy = (s - 0.5) * r / side, (foot - top) * r / side
|
||||
p = QPainterPath()
|
||||
p.moveTo(0.5, foot)
|
||||
p.lineTo(s - dx, top + dy)
|
||||
p.quadTo(s, top, s + r, top)
|
||||
p.lineTo(w - s - r, top)
|
||||
p.quadTo(w - s, top, w - s + dx, top + dy)
|
||||
p.lineTo(w - 0.5, foot)
|
||||
return p
|
||||
|
||||
def _fill(self, color, front: bool) -> QLinearGradient:
|
||||
"""A button's emboss, or (front) only its top rim, then the page."""
|
||||
g = QLinearGradient(QPointF(0, 0), QPointF(0, self.height()))
|
||||
stops = theme.emboss_stops(color, pressed=self.isDown() and not front)
|
||||
for pos, c in (stops[:3] if front else stops):
|
||||
g.setColorAt(pos, c)
|
||||
if front:
|
||||
g.setColorAt(1, color)
|
||||
return g
|
||||
|
||||
def paintEvent(self, _) -> None:
|
||||
front = self.isChecked()
|
||||
pal = self.palette()
|
||||
if front:
|
||||
color = pal.color(QPalette.ColorRole.Window)
|
||||
else:
|
||||
color = pal.color(QPalette.ColorRole.Button)
|
||||
if self.isDown():
|
||||
color = color.darker(theme.PRESSED_DARKER)
|
||||
elif self.underMouse():
|
||||
color = color.darker(theme.HOVER_DARKER)
|
||||
w, h = self.width(), self.height()
|
||||
p = QPainter(self)
|
||||
p.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
shape = self._outline()
|
||||
p.fillPath(shape, self._fill(color, front))
|
||||
p.setPen(QPen(color.darker(OUTLINE), 1))
|
||||
p.drawPath(shape)
|
||||
if not front: # behind: the baseline runs across its foot
|
||||
p.setPen(QPen(baseline_color(pal), 1))
|
||||
p.drawLine(QPointF(0, h - 0.5), QPointF(w, h - 0.5))
|
||||
p.setPen(pal.color(QPalette.ColorRole.WindowText if front
|
||||
else QPalette.ColorRole.ButtonText))
|
||||
f = self.font()
|
||||
f.setBold(front)
|
||||
p.setFont(f)
|
||||
p.drawText(self.rect().adjusted(0, 2, 0, 0), Qt.AlignmentFlag.AlignCenter, self.text())
|
||||
p.end()
|
||||
|
||||
def enterEvent(self, e) -> None:
|
||||
self.update()
|
||||
super().enterEvent(e)
|
||||
|
||||
def leaveEvent(self, e) -> None:
|
||||
self.update()
|
||||
super().leaveEvent(e)
|
||||
|
||||
|
||||
class TabStrip(QWidget):
|
||||
"""A row of MacTabs (None in `add` = a gap) on a baseline across the
|
||||
width. Placed by hand: a layout can't overlap its widgets."""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self._items: list[MacTab | int] = [] # a tab, or a gap's width
|
||||
|
||||
def add(self, tab: MacTab | None, gap: int = 24) -> None:
|
||||
if tab is None:
|
||||
self._items.append(gap)
|
||||
else:
|
||||
tab.setParent(self)
|
||||
self._items.append(tab)
|
||||
|
||||
def finish(self) -> None:
|
||||
for t in self._tabs():
|
||||
if t.isChecked():
|
||||
t.raise_()
|
||||
self._place()
|
||||
|
||||
def _tabs(self) -> list[MacTab]:
|
||||
return [t for t in self._items if isinstance(t, MacTab)]
|
||||
|
||||
def sizeHint(self) -> QSize:
|
||||
tabs = self._tabs()
|
||||
h = max((t.sizeHint().height() for t in tabs), default=24)
|
||||
w = 4 + sum(t.sizeHint().width() - OVERLAP if isinstance(t, MacTab) else t
|
||||
for t in self._items) + OVERLAP
|
||||
return QSize(w, h)
|
||||
|
||||
def minimumSizeHint(self) -> QSize:
|
||||
return self.sizeHint()
|
||||
|
||||
def _place(self) -> None:
|
||||
x, h = 4, self.height()
|
||||
for item in self._items:
|
||||
if isinstance(item, MacTab):
|
||||
hint = item.sizeHint()
|
||||
item.setGeometry(x, h - hint.height(), hint.width(), hint.height())
|
||||
x += hint.width() - OVERLAP
|
||||
else:
|
||||
x += item
|
||||
|
||||
def resizeEvent(self, e) -> None:
|
||||
self._place()
|
||||
super().resizeEvent(e)
|
||||
|
||||
def paintEvent(self, _) -> None:
|
||||
p = QPainter(self)
|
||||
p.setPen(QPen(baseline_color(self.palette()), 1))
|
||||
p.drawLine(0, self.height() - 1, self.width(), self.height() - 1)
|
||||
p.end()
|
||||
@@ -19,6 +19,7 @@ from lintunes.gui import visualizer_styles
|
||||
from lintunes.gui.range_slider import RangeSlider
|
||||
from lintunes.gui.scope_drawing import ScopeDrawing
|
||||
from lintunes.gui.transport import ClickJumpSlider
|
||||
from lintunes.gui.mac_tabs import MacTab, TabStrip
|
||||
from lintunes.gui import visualizer_presets as presets
|
||||
from lintunes.gui import sounds
|
||||
from lintunes.theme import HIGHLIGHT_COLORS
|
||||
@@ -1137,7 +1138,7 @@ class PreferencesDialog(QDialog):
|
||||
|
||||
def _build_colors_group(self) -> QGroupBox:
|
||||
"""Light and dark each have a tint and a full set of grays; the
|
||||
Light | Dark switch picks which set the controls show and edit, and
|
||||
Light | Dark tabs pick which set the controls show and edit, and
|
||||
every control moves to that set's saved values."""
|
||||
group = QGroupBox("Colors")
|
||||
form = QFormLayout(group)
|
||||
@@ -1146,21 +1147,19 @@ class PreferencesDialog(QDialog):
|
||||
note.setWordWrap(True)
|
||||
form.addRow(note)
|
||||
|
||||
switch = QHBoxLayout()
|
||||
switch.setSpacing(0)
|
||||
# Which set the controls below show: folder tabs, since picking one
|
||||
# changes the page under it (shared design #tabs).
|
||||
strip = TabStrip()
|
||||
self._color_mode_group = QButtonGroup(self)
|
||||
self._color_mode_buttons = {}
|
||||
for which in theme.MODES:
|
||||
button = QPushButton(which.capitalize())
|
||||
button.setCheckable(True)
|
||||
button.setProperty("tile", "first" if which == "light" else "last")
|
||||
self._color_mode_group.addButton(button)
|
||||
self._color_mode_buttons[which] = button
|
||||
switch.addWidget(button)
|
||||
button.toggled.connect(
|
||||
tab = MacTab(which.capitalize())
|
||||
self._color_mode_group.addButton(tab)
|
||||
self._color_mode_buttons[which] = tab
|
||||
strip.add(tab)
|
||||
tab.toggled.connect(
|
||||
lambda on, w=which: on and self._edit_colors_of(w))
|
||||
switch.addStretch()
|
||||
form.addRow("Editing:", switch)
|
||||
form.addRow(strip)
|
||||
|
||||
self._editing = theme.mode(self._prefs)
|
||||
tint_row = QHBoxLayout()
|
||||
@@ -1187,6 +1186,7 @@ class PreferencesDialog(QDialog):
|
||||
self._color_sliders[key] = slider
|
||||
form.addRow(label, slider)
|
||||
self._color_mode_buttons[self._editing].setChecked(True)
|
||||
strip.finish()
|
||||
self._show_color_values()
|
||||
return group
|
||||
|
||||
|
||||
+53
-8
@@ -329,6 +329,10 @@ class SidebarArt(QWidget):
|
||||
self._art_window = ArtWindow()
|
||||
self._hovered = False
|
||||
self._held = False
|
||||
# A clickable picture can't wear a button face without changing the
|
||||
# picture, so it says so the shared way (design #clickable-images):
|
||||
# the finger over it, a tooltip, and a place in the Tab order.
|
||||
self.setFocusPolicy(Qt.FocusPolicy.TabFocus)
|
||||
player.track_changed.connect(self.set_track)
|
||||
|
||||
def set_track(self, track):
|
||||
@@ -340,6 +344,7 @@ class SidebarArt(QWidget):
|
||||
pixmap = QPixmap()
|
||||
if pixmap.loadFromData(data):
|
||||
self._pixmap = pixmap
|
||||
self._update_cursor()
|
||||
if self._pixmap is not None:
|
||||
self.setToolTip("Click to view full size")
|
||||
elif track is not None:
|
||||
@@ -354,6 +359,14 @@ class SidebarArt(QWidget):
|
||||
self._had_art = self.has_art()
|
||||
self.has_art_changed.emit(self._had_art)
|
||||
|
||||
def _update_cursor(self):
|
||||
"""The finger only over a picture: an empty panel shows it's a
|
||||
button by its face instead."""
|
||||
if self.has_art():
|
||||
self.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||
else:
|
||||
self.unsetCursor()
|
||||
|
||||
def has_art(self) -> bool:
|
||||
return self._pixmap is not None and not self._pixmap.isNull()
|
||||
|
||||
@@ -415,21 +428,53 @@ class SidebarArt(QWidget):
|
||||
# also fire when a drag merely starts here.
|
||||
if (event.button() == Qt.MouseButton.LeftButton
|
||||
and self.rect().contains(event.position().toPoint())):
|
||||
if self._pixmap is not None:
|
||||
self._art_window.show_artwork(self._pixmap, self._title(),
|
||||
self.screen())
|
||||
elif self._track is not None:
|
||||
self.download_art_requested.emit(self._track.track_id)
|
||||
self._activate()
|
||||
super().mouseReleaseEvent(event)
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if event.key() in (Qt.Key.Key_Return, Qt.Key.Key_Enter, Qt.Key.Key_Space):
|
||||
self._activate()
|
||||
event.accept()
|
||||
return
|
||||
super().keyPressEvent(event)
|
||||
|
||||
def focusInEvent(self, event):
|
||||
self.update()
|
||||
super().focusInEvent(event)
|
||||
|
||||
def focusOutEvent(self, event):
|
||||
self.update()
|
||||
super().focusOutEvent(event)
|
||||
|
||||
def _activate(self):
|
||||
if self._pixmap is not None:
|
||||
self._art_window.show_artwork(self._pixmap, self._title(),
|
||||
self.screen())
|
||||
elif self._track is not None:
|
||||
self.download_art_requested.emit(self._track.track_id)
|
||||
|
||||
def _paint_focus(self, painter, rect):
|
||||
"""The keyboard focus ring: 2 px of the highlight over the edge."""
|
||||
if not self.hasFocus():
|
||||
return
|
||||
from PyQt6.QtGui import QPainterPath, QPen
|
||||
ring = QPainterPath()
|
||||
ring.addRoundedRect(rect, NO_ART_RADIUS, NO_ART_RADIUS)
|
||||
painter.setPen(QPen(self.palette().highlight().color(), 2))
|
||||
painter.drawPath(ring)
|
||||
|
||||
def paintEvent(self, event):
|
||||
painter = QPainter(self)
|
||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
rect = QRectF(self.rect()).adjusted(0.5, NO_ART_GAP + 0.5, -0.5, -0.5)
|
||||
self._paint_panel(painter, rect)
|
||||
self._paint_focus(painter, rect)
|
||||
|
||||
def _paint_panel(self, painter, rect):
|
||||
# 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
|
||||
from PyQt6.QtGui import QPainterPath
|
||||
painter = QPainter(self)
|
||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
rect = QRectF(self.rect()).adjusted(0.5, NO_ART_GAP + 0.5, -0.5, -0.5)
|
||||
if self._is_button() and self._hovered:
|
||||
# Pops up as a plain button under the cursor (no glyph): the
|
||||
# Library button's face, hover-darkened, and sunk while held.
|
||||
|
||||
@@ -3,7 +3,7 @@ import os
|
||||
|
||||
from PyQt6.QtWidgets import (
|
||||
QTableView, QAbstractItemView, QMenu, QApplication, QProxyStyle, QStyle,
|
||||
QStyledItemDelegate, QStyleOptionViewItem, QWidget,
|
||||
QStyledItemDelegate, QStyleOptionViewItem, QWidget, QSlider,
|
||||
)
|
||||
from PyQt6.QtCore import (
|
||||
Qt, QAbstractTableModel, QModelIndex, QPersistentModelIndex,
|
||||
@@ -50,17 +50,23 @@ 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.
|
||||
# Every slider is tall (shared design #sliders): groove and handle this
|
||||
# many times Fusion's height, the handle keeping its width. A slider
|
||||
# opts out with the `tall` property set False, or by having a style
|
||||
# sheet of its own (the DJ shelf's), which draws it instead.
|
||||
TALL = 2
|
||||
|
||||
@staticmethod
|
||||
def _tall(widget) -> bool:
|
||||
return widget is not None and bool(widget.property("tall"))
|
||||
return (isinstance(widget, QSlider) and widget.property("tall") is not False
|
||||
and not widget.styleSheet())
|
||||
|
||||
def styleHint(self, hint, option=None, widget=None, returnData=None):
|
||||
if hint == QStyle.StyleHint.SH_ScrollBar_LeftClickAbsolutePosition:
|
||||
return 1
|
||||
if hint == QStyle.StyleHint.SH_Slider_AbsoluteSetButtons:
|
||||
# a left click puts the handle's centre where it lands
|
||||
return Qt.MouseButton.LeftButton.value
|
||||
return super().styleHint(hint, option, widget, returnData)
|
||||
|
||||
def pixelMetric(self, metric, option=None, widget=None):
|
||||
|
||||
Reference in New Issue
Block a user