forked from trav/lintunes
v0.67.3: the rating column is never narrower than five stars
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||
|
||||
__version__ = "0.67.2"
|
||||
__version__ = "0.67.3"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user