Merge remote-tracking branch 'origin/pr/6619'

This commit is contained in:
Florian Bruhin 2022-01-05 16:22:44 +01:00
commit 0903d9879a
3 changed files with 22 additions and 4 deletions

View File

@ -4388,6 +4388,7 @@ The following placeholders are defined:
* `{index}`: Index of this tab.
* `{aligned_index}`: Index of this tab padded with spaces to have the same
width.
* `{relative_index}`: Index of this tab relative to the current tab.
* `{id}`: Internal tab ID of this tab.
* `{scroll_pos}`: Page scroll position.
* `{host}`: Host of the current web page.

View File

@ -2171,6 +2171,7 @@ tabs.title.format:
- title_sep
- index
- aligned_index
- relative_index
- id
- scroll_pos
- host
@ -2190,6 +2191,7 @@ tabs.title.format:
* `{index}`: Index of this tab.
* `{aligned_index}`: Index of this tab padded with spaces to have the same
width.
* `{relative_index}`: Index of this tab relative to the current tab.
* `{id}`: Internal tab ID of this tab.
* `{scroll_pos}`: Page scroll position.
* `{host}`: Host of the current web page.
@ -2210,6 +2212,7 @@ tabs.title.format_pinned:
- title_sep
- index
- aligned_index
- relative_index
- id
- scroll_pos
- host

View File

@ -136,18 +136,31 @@ class TabWidget(QTabWidget):
(fmt is None or ('{' + field + '}') not in fmt)):
return
def right_align(text):
return str(text).rjust(len(str(self.count())))
def left_align(text):
return str(text).ljust(len(str(self.count())))
bar = self.tabBar()
cur_idx = bar.currentIndex()
if idx == cur_idx:
rel_idx = left_align(idx + 1) + " "
else:
rel_idx = " " + right_align(abs(idx - cur_idx))
fields = self.get_tab_fields(idx)
fields['current_title'] = fields['current_title'].replace('&', '&&')
fields['index'] = idx + 1
fields['aligned_index'] = str(idx + 1).rjust(len(str(self.count())))
fields['aligned_index'] = right_align(idx + 1)
fields['relative_index'] = rel_idx
title = '' if fmt is None else fmt.format(**fields)
tabbar = self.tabBar()
# Only change the tab title if it changes, setting the tab title causes
# a size recalculation which is slow.
if tabbar.tabText(idx) != title:
tabbar.setTabText(idx, title)
if bar.tabText(idx) != title:
bar.setTabText(idx, title)
def get_tab_fields(self, idx):
"""Get the tab field data."""
@ -305,6 +318,7 @@ class TabWidget(QTabWidget):
def _on_current_changed(self, index):
"""Emit the tab_index_changed signal if the current tab changed."""
self.tabBar().on_current_changed()
self.update_tab_titles()
self.tab_index_changed.emit(index, self.count())
@pyqtSlot()