forked from trav/lintunes
v0.31.7: fixed 16px gaps in the top row, panel fills the rest; right inset
The row of boxes keeps one 16px gap before, between and after its controls at every width; the now-playing panel and the seek row under it take all the remaining width. The track lists get the same 8px of bare window on the right that the playlists have on the left. README updates.
This commit is contained in:
+17
-45
@@ -20,15 +20,11 @@ ICON_GRAY = QColor("#4A4A4A")
|
||||
TOP_MARGIN = 9
|
||||
# Between the row of boxes and the header row under it.
|
||||
ROW_GAP = 4
|
||||
# The now-playing panel is this share of the bar's width (700px on a 1920px
|
||||
# screen), within these bounds. The row floats: the space before the first
|
||||
# control, between each pair and after the last is one equal gap, so the
|
||||
# whole row scales with the window instead of bunching up anywhere.
|
||||
NOW_PLAYING_SHARE = 700 / 1920
|
||||
NOW_PLAYING_MIN = 220
|
||||
NOW_PLAYING_MAX = 1100
|
||||
# Floor for each of those gaps.
|
||||
MIN_GAP = 12
|
||||
# The row of boxes is knolled: one GAP before the first control, between
|
||||
# each pair and after the last, always. The now-playing panel (and the seek
|
||||
# row under it) takes all the width that's left.
|
||||
GAP = 16
|
||||
NOW_PLAYING_MIN = 180
|
||||
|
||||
# Shared height for the boxed side controls (transport, shuffle, bpm) and the
|
||||
# visualizer, so they line up. ~midway between their old heights: the stretchy
|
||||
@@ -381,20 +377,12 @@ class TransportBar(QWidget):
|
||||
# window could never shrink past the width it last had.
|
||||
outer.setSizeConstraint(QLayout.SizeConstraint.SetNoConstraint)
|
||||
layout = QHBoxLayout()
|
||||
layout.setContentsMargins(MIN_GAP, 0, MIN_GAP, 0)
|
||||
layout.setContentsMargins(GAP, 0, GAP, 0)
|
||||
layout.setSpacing(0)
|
||||
outer.addLayout(layout)
|
||||
|
||||
# Knolled: every control keeps its size and the gaps between them
|
||||
# are equal; _size_now_playing sizes them (and the two ends).
|
||||
self._row = layout
|
||||
self._gaps: list[QSpacerItem] = []
|
||||
|
||||
def gap():
|
||||
spacer = QSpacerItem(MIN_GAP, 0, QSizePolicy.Policy.Fixed,
|
||||
QSizePolicy.Policy.Minimum)
|
||||
self._gaps.append(spacer)
|
||||
layout.addSpacerItem(spacer)
|
||||
layout.addSpacing(GAP)
|
||||
|
||||
# Rounded button boxes carry a user-tunable grayscale fill, decoupled
|
||||
# from the stripe color they used to share via palette(alternate-base).
|
||||
@@ -513,7 +501,7 @@ class TransportBar(QWidget):
|
||||
# the seek row hangs underneath the panel, in the header row.
|
||||
self._now_playing.setFixedHeight(CONTROL_HEIGHT)
|
||||
# Its width is set by _size_now_playing: all the room the controls
|
||||
# and minimal gaps leave, up to NOW_PLAYING_MAX.
|
||||
# and gaps leave.
|
||||
self._now_playing.setFixedWidth(NOW_PLAYING_MIN)
|
||||
layout.addWidget(self._now_playing, alignment=TOP)
|
||||
self._now_playing.installEventFilter(self)
|
||||
@@ -602,33 +590,17 @@ class TransportBar(QWidget):
|
||||
self._place_header()
|
||||
|
||||
def _controls_width(self) -> int:
|
||||
"""Everything in the row of boxes but the now-playing panel, with
|
||||
each gap at its floor."""
|
||||
return (2 * MIN_GAP
|
||||
# A fixed width shows in the minimum, not the size hint.
|
||||
+ sum(max(w.sizeHint().width(), w.minimumWidth())
|
||||
for w in self._fixed_controls)
|
||||
+ len(self._fixed_controls) * MIN_GAP)
|
||||
"""Everything in the row of boxes but the now-playing panel: the
|
||||
controls and a GAP before, between and after them."""
|
||||
# A fixed width shows in the minimum, not the size hint.
|
||||
return (sum(max(w.sizeHint().width(), w.minimumWidth())
|
||||
for w in self._fixed_controls)
|
||||
+ (len(self._fixed_controls) + 2) * GAP)
|
||||
|
||||
def _size_now_playing(self):
|
||||
"""The panel takes its share of the width; the rest is split into
|
||||
equal gaps before, between and after the controls."""
|
||||
spaces = len(self._gaps) + 2
|
||||
fixed = sum(max(w.sizeHint().width(), w.minimumWidth())
|
||||
for w in self._fixed_controls)
|
||||
panel = round(self.width() * NOW_PLAYING_SHARE)
|
||||
panel = min(panel, self.width() - fixed - spaces * MIN_GAP)
|
||||
panel = max(NOW_PLAYING_MIN, min(NOW_PLAYING_MAX, panel))
|
||||
self._now_playing.setFixedWidth(panel)
|
||||
free = max(0, self.width() - fixed - panel)
|
||||
gap = max(MIN_GAP, free // spaces)
|
||||
for spacer in self._gaps:
|
||||
spacer.changeSize(gap, 0, QSizePolicy.Policy.Fixed,
|
||||
QSizePolicy.Policy.Minimum)
|
||||
# Integer rounding's leftover pixels go to the right end.
|
||||
end = max(MIN_GAP, free - gap * len(self._gaps))
|
||||
self._row.setContentsMargins(gap, 0, max(MIN_GAP, end - gap), 0)
|
||||
self._row.invalidate()
|
||||
"""The panel fills whatever the controls and gaps leave."""
|
||||
self._now_playing.setFixedWidth(
|
||||
max(NOW_PLAYING_MIN, self.width() - self._controls_width()))
|
||||
|
||||
def minimumSizeHint(self):
|
||||
hint = super().minimumSizeHint()
|
||||
|
||||
Reference in New Issue
Block a user