Fix padding of remaining tabbar space with pinned tabs

This commit is contained in:
Marius 2017-06-18 21:49:04 +02:00
parent a5db21abe9
commit 4b2bf12efa

View File

@ -514,10 +514,13 @@ class TabBar(QTabBar):
except KeyError: except KeyError:
pinned = False pinned = False
no_pinned_count = self.count() - self.pinned_count
pinned_width = tab_width_pinned_conf * self.pinned_count
no_pinned_width = self.width() - pinned_width
if pinned: if pinned:
size = QSize(tab_width_pinned_conf, height) width = tab_width_pinned_conf
qtutils.ensure_valid(size) else:
return size
# If we *do* have enough space, tabs should occupy the whole window # If we *do* have enough space, tabs should occupy the whole window
# width. If there are pinned tabs their size will be subtracted # width. If there are pinned tabs their size will be subtracted
@ -525,17 +528,16 @@ class TabBar(QTabBar):
# During shutdown the self.count goes down, # During shutdown the self.count goes down,
# but the self.pinned_count not - this generates some odd behavior. # but the self.pinned_count not - this generates some odd behavior.
# To avoid this we compare self.count against self.pinned_count. # To avoid this we compare self.count against self.pinned_count.
if self.pinned_count > 0 and self.count() > self.pinned_count: if self.pinned_count > 0 and no_pinned_count > 0:
pinned_width = tab_width_pinned_conf * self.pinned_count width = no_pinned_width / no_pinned_count
no_pinned_width = self.width() - pinned_width
width = no_pinned_width / (self.count() - self.pinned_count)
else: else:
width = self.width() / self.count() width = self.width() / self.count()
# If width is not divisible by count, add a pixel to some tabs so # If no_pinned_width is not divisible by no_pinned_count, add a pixel to some tabs so
# that there is no ugly leftover space. # that there is no ugly leftover space.
if index < self.width() % self.count(): if no_pinned_count > 0 and index < no_pinned_width % no_pinned_count:
width += 1 width += 1
size = QSize(width, height) size = QSize(width, height)
qtutils.ensure_valid(size) qtutils.ensure_valid(size)
return size return size