Use qt to equally size tabs
This commit is contained in:
parent
0147ff192a
commit
84a8845905
@ -568,15 +568,6 @@ class TabBar(QTabBar):
|
|||||||
width = max(min_width, width)
|
width = max(min_width, width)
|
||||||
return QSize(width, height)
|
return QSize(width, height)
|
||||||
|
|
||||||
def _pinned_statistics(self) -> (int, int):
|
|
||||||
"""Get the number of pinned tabs and the total width of pinned tabs."""
|
|
||||||
pinned_list = [idx for idx in range(self.count())
|
|
||||||
if self._tab_pinned(idx)]
|
|
||||||
pinned_count = len(pinned_list)
|
|
||||||
pinned_width = sum(self.minimumTabSizeHint(idx, ellipsis=False).width()
|
|
||||||
for idx in pinned_list)
|
|
||||||
return (pinned_count, pinned_width)
|
|
||||||
|
|
||||||
def _tab_pinned(self, index: int) -> bool:
|
def _tab_pinned(self, index: int) -> bool:
|
||||||
"""Return True if tab is pinned."""
|
"""Return True if tab is pinned."""
|
||||||
try:
|
try:
|
||||||
@ -614,32 +605,17 @@ class TabBar(QTabBar):
|
|||||||
width = int(confwidth)
|
width = int(confwidth)
|
||||||
size = QSize(max(minimum_size.width(), width), height)
|
size = QSize(max(minimum_size.width(), width), height)
|
||||||
else:
|
else:
|
||||||
if config.cache['tabs.pinned.shrink']:
|
if config.cache['tabs.pinned.shrink'] and self._tab_pinned(index):
|
||||||
pinned = self._tab_pinned(index)
|
|
||||||
pinned_count, pinned_width = self._pinned_statistics()
|
|
||||||
else:
|
|
||||||
pinned = False
|
|
||||||
pinned_count, pinned_width = 0, 0
|
|
||||||
no_pinned_count = self.count() - pinned_count
|
|
||||||
no_pinned_width = self.width() - pinned_width
|
|
||||||
|
|
||||||
if pinned:
|
|
||||||
# Give pinned tabs the minimum size they need to display their
|
# Give pinned tabs the minimum size they need to display their
|
||||||
# titles, let Qt handle scaling it down if we get too small.
|
# titles, let Qt handle scaling it down if we get too small.
|
||||||
width = self.minimumTabSizeHint(index, ellipsis=False).width()
|
width = self.minimumTabSizeHint(index, ellipsis=False).width()
|
||||||
else:
|
else:
|
||||||
width = no_pinned_width / no_pinned_count
|
# Request as much space as possible so we fill the tabbar, let
|
||||||
|
# Qt shrink us down
|
||||||
|
width = self.width()
|
||||||
|
|
||||||
# If no_pinned_width is not divisible by no_pinned_count, add a
|
# If we don't have enough space, we return the minimum size
|
||||||
# pixel to some tabs so that there is no ugly leftover space.
|
|
||||||
if (no_pinned_count > 0 and
|
|
||||||
index < no_pinned_width % no_pinned_count):
|
|
||||||
width += 1
|
|
||||||
|
|
||||||
# If we don't have enough space, we return the minimum size so we
|
|
||||||
# get scroll buttons as soon as needed.
|
|
||||||
width = max(width, minimum_size.width())
|
width = max(width, minimum_size.width())
|
||||||
|
|
||||||
size = QSize(width, height)
|
size = QSize(width, height)
|
||||||
qtutils.ensure_valid(size)
|
qtutils.ensure_valid(size)
|
||||||
return size
|
return size
|
||||||
|
Loading…
Reference in New Issue
Block a user