Avoid calls to minTabSizeHint in tabSizeHint
This commit is contained in:
parent
e9ca4c4295
commit
773fe47687
@ -388,13 +388,14 @@ class TabBar(QTabBar):
|
|||||||
if option.startswith('colors.tabs.'):
|
if option.startswith('colors.tabs.'):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
# Clear _minimum_tab_size_hint_helper cache when appropriate
|
# Clear tab size caches when appropriate
|
||||||
if option in ["tabs.indicator.padding",
|
if option in ["tabs.indicator.padding",
|
||||||
"tabs.padding",
|
"tabs.padding",
|
||||||
"tabs.indicator.width",
|
"tabs.indicator.width",
|
||||||
"tabs.min_width",
|
"tabs.min_width",
|
||||||
"tabs.pinned.shrink"]:
|
"tabs.pinned.shrink"]:
|
||||||
self._minimum_tab_size_hint_helper.cache_clear()
|
self._minimum_tab_size_hint_helper.cache_clear()
|
||||||
|
self._minimum_tab_height.cache_clear()
|
||||||
|
|
||||||
def _on_show_switching_delay_changed(self):
|
def _on_show_switching_delay_changed(self):
|
||||||
"""Set timer interval when tabs.show_switching_delay got changed."""
|
"""Set timer interval when tabs.show_switching_delay got changed."""
|
||||||
@ -471,6 +472,7 @@ class TabBar(QTabBar):
|
|||||||
self._set_icon_size()
|
self._set_icon_size()
|
||||||
# clear tab size cache
|
# clear tab size cache
|
||||||
self._minimum_tab_size_hint_helper.cache_clear()
|
self._minimum_tab_size_hint_helper.cache_clear()
|
||||||
|
self._minimum_tab_height.cache_clear()
|
||||||
|
|
||||||
def _set_icon_size(self):
|
def _set_icon_size(self):
|
||||||
"""Set the tab bar favicon size."""
|
"""Set the tab bar favicon size."""
|
||||||
@ -558,8 +560,7 @@ class TabBar(QTabBar):
|
|||||||
# Only add padding if indicator exists
|
# Only add padding if indicator exists
|
||||||
if indicator_width != 0:
|
if indicator_width != 0:
|
||||||
padding_h += indicator_padding.left + indicator_padding.right
|
padding_h += indicator_padding.left + indicator_padding.right
|
||||||
padding_v = padding.top + padding.bottom
|
height = self._minimum_tab_height()
|
||||||
height = self.fontMetrics().height() + padding_v
|
|
||||||
width = (text_width + icon_width +
|
width = (text_width + icon_width +
|
||||||
padding_h + indicator_width)
|
padding_h + indicator_width)
|
||||||
min_width = config.val.tabs.min_width
|
min_width = config.val.tabs.min_width
|
||||||
@ -568,6 +569,11 @@ class TabBar(QTabBar):
|
|||||||
width = max(min_width, width)
|
width = max(min_width, width)
|
||||||
return QSize(width, height)
|
return QSize(width, height)
|
||||||
|
|
||||||
|
@functools.lru_cache(maxsize=1)
|
||||||
|
def _minimum_tab_height(self):
|
||||||
|
padding = config.cache['tabs.padding']
|
||||||
|
return self.fontMetrics().height() + padding.top + padding.bottom
|
||||||
|
|
||||||
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:
|
||||||
@ -592,8 +598,7 @@ class TabBar(QTabBar):
|
|||||||
# want to ensure it's valid in this special case.
|
# want to ensure it's valid in this special case.
|
||||||
return QSize()
|
return QSize()
|
||||||
|
|
||||||
minimum_size = self.minimumTabSizeHint(index)
|
height = self._minimum_tab_height()
|
||||||
height = minimum_size.height()
|
|
||||||
if self.vertical:
|
if self.vertical:
|
||||||
confwidth = str(config.cache['tabs.width'])
|
confwidth = str(config.cache['tabs.width'])
|
||||||
if confwidth.endswith('%'):
|
if confwidth.endswith('%'):
|
||||||
@ -603,7 +608,7 @@ class TabBar(QTabBar):
|
|||||||
width = main_window.width() * perc / 100
|
width = main_window.width() * perc / 100
|
||||||
else:
|
else:
|
||||||
width = int(confwidth)
|
width = int(confwidth)
|
||||||
size = QSize(max(minimum_size.width(), width), height)
|
size = QSize(width, height)
|
||||||
else:
|
else:
|
||||||
if config.cache['tabs.pinned.shrink'] and self._tab_pinned(index):
|
if config.cache['tabs.pinned.shrink'] and self._tab_pinned(index):
|
||||||
# Give pinned tabs the minimum size they need to display their
|
# Give pinned tabs the minimum size they need to display their
|
||||||
@ -611,11 +616,9 @@ class TabBar(QTabBar):
|
|||||||
width = self.minimumTabSizeHint(index, ellipsis=False).width()
|
width = self.minimumTabSizeHint(index, ellipsis=False).width()
|
||||||
else:
|
else:
|
||||||
# Request as much space as possible so we fill the tabbar, let
|
# Request as much space as possible so we fill the tabbar, let
|
||||||
# Qt shrink us down
|
# Qt shrink us down. If for some reason (tests, bugs)
|
||||||
width = self.width()
|
# self.width() gives 0, use a sane min of 10 px
|
||||||
|
width = max(self.width(), 10)
|
||||||
# If we don't have enough space, we return the minimum size
|
|
||||||
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