v0.67.3: the rating column is never narrower than five stars

This commit is contained in:
2026-10-19 22:10:47 -07:00
parent 2e5ebf0b0b
commit 1d215fd045
3 changed files with 56 additions and 4 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.67.2"
__version__ = "0.67.3"
+20 -3
View File
@@ -245,6 +245,13 @@ def rating_slot_width(fm: QFontMetrics) -> int:
return max(fm.horizontalAdvance("★"), fm.horizontalAdvance("•")) + 4
def rating_min_width(fm: QFontMetrics) -> int:
"""Narrowest the rating column may be: all five slots plus the left pad
and as much again on the right, so five stars never spill into the next
column."""
return 5 * rating_slot_width(fm) + 2 * RATING_LEFT_PAD
def rating_slot_at(x: int, slot_w: int) -> int:
"""Which slot (1..5) an x offset within the rating cell lands on."""
if slot_w <= 0:
@@ -970,11 +977,21 @@ class TrackTableView(QTableView):
self.sort_changed.emit(field, order == Qt.SortOrder.AscendingOrder)
def _on_section_resized(self, section, _old, new_width):
if self._suppress_signals or section >= len(self.model_.fields):
if section >= len(self.model_.fields):
return
header = self.horizontalHeader()
if (header.stretchLastSection()
and section == header.logicalIndex(header.count() - 1)):
stretched = (header.stretchLastSection()
and section == header.logicalIndex(header.count() - 1))
if self.model_.fields[section] == "rating" and not stretched:
# Never narrower than five stars (a saved width or a drag alike);
# the resize re-enters here with the clamped width.
least = rating_min_width(QFontMetrics(self.font()))
if new_width < least:
header.resizeSection(section, least)
return
if self._suppress_signals:
return
if stretched:
# The last column is stretch-sized, so Qt re-fires this every time
# the viewport changes width — resizing the window or dragging the
# splitter would otherwise rewrite the whole playlist JSON (and hand
+35
View File
@@ -0,0 +1,35 @@
"""Round 100: the rating column is never narrower than five stars."""
from PyQt6.QtGui import QFontMetrics
from lintunes.gui.track_table import TrackTableView, rating_min_width
from lintunes.models.playlist import PlaylistSettings
def _view(widths):
view = TrackTableView(playlist_mode=False)
view.apply_settings(PlaylistSettings(
visible_columns=["name", "rating", "date_added"], sort_column="name",
column_widths=widths))
return view
def test_saved_narrow_width_is_widened(qapp):
view = _view({"rating": 20})
least = rating_min_width(QFontMetrics(view.font()))
assert view.columnWidth(view.model_.fields.index("rating")) == least
def test_dragging_narrower_snaps_back_and_saves_the_minimum(qapp):
view = _view({})
col = view.model_.fields.index("rating")
saved = []
view.column_width_changed.connect(lambda f, w: saved.append((f, w)))
view.horizontalHeader().resizeSection(col, 10)
least = rating_min_width(QFontMetrics(view.font()))
assert view.columnWidth(col) == least
assert saved == [("rating", least)]
def test_wider_widths_are_left_alone(qapp):
view = _view({"rating": 200})
assert view.columnWidth(view.model_.fields.index("rating")) == 200