Implemented counter for total number of tabs
With this counter we can better control the space on the tabbar.
This commit is contained in:
parent
6f8aaccc2b
commit
d7f5f61f03
@ -227,6 +227,10 @@ class CommandDispatcher:
|
|||||||
tabbar = self._tabbed_browser.tabBar()
|
tabbar = self._tabbed_browser.tabBar()
|
||||||
selection_override = self._get_selection_override(left, right,
|
selection_override = self._get_selection_override(left, right,
|
||||||
opposite)
|
opposite)
|
||||||
|
|
||||||
|
if tab.data.pinned:
|
||||||
|
tabbar.pinned -= 1
|
||||||
|
|
||||||
if selection_override is None:
|
if selection_override is None:
|
||||||
self._tabbed_browser.close_tab(tab)
|
self._tabbed_browser.close_tab(tab)
|
||||||
else:
|
else:
|
||||||
|
@ -99,9 +99,16 @@ class TabWidget(QTabWidget):
|
|||||||
pinned: Pinned tab state.
|
pinned: Pinned tab state.
|
||||||
"""
|
"""
|
||||||
bar = self.tabBar()
|
bar = self.tabBar()
|
||||||
bar.set_tab_data(idx, 'pinned',pinned)
|
bar.set_tab_data(idx, 'pinned', pinned)
|
||||||
bar.update(bar.tabRect(idx))
|
bar.update(bar.tabRect(idx))
|
||||||
|
|
||||||
|
if pinned:
|
||||||
|
bar.pinned += 1
|
||||||
|
else:
|
||||||
|
bar.pinned -= 1
|
||||||
|
|
||||||
|
bar.refresh()
|
||||||
|
|
||||||
def set_page_title(self, idx, title):
|
def set_page_title(self, idx, title):
|
||||||
"""Set the tab title user data."""
|
"""Set the tab title user data."""
|
||||||
self.tabBar().set_tab_data(idx, 'page-title', title)
|
self.tabBar().set_tab_data(idx, 'page-title', title)
|
||||||
@ -139,10 +146,6 @@ class TabWidget(QTabWidget):
|
|||||||
fields['title_sep'] = ' - ' if page_title else ''
|
fields['title_sep'] = ' - ' if page_title else ''
|
||||||
fields['perc_raw'] = tab.progress()
|
fields['perc_raw'] = tab.progress()
|
||||||
|
|
||||||
#TODO: Move this to a proper place
|
|
||||||
if tab.data.pinned:
|
|
||||||
self.set_tab_pinned(idx, tab.data.pinned)
|
|
||||||
|
|
||||||
if tab.load_status() == usertypes.LoadStatus.loading:
|
if tab.load_status() == usertypes.LoadStatus.loading:
|
||||||
fields['perc'] = '[{}%] '.format(tab.progress())
|
fields['perc'] = '[{}%] '.format(tab.progress())
|
||||||
else:
|
else:
|
||||||
@ -298,6 +301,7 @@ class TabBar(QTabBar):
|
|||||||
self._auto_hide_timer.timeout.connect(self._tabhide)
|
self._auto_hide_timer.timeout.connect(self._tabhide)
|
||||||
self.setAutoFillBackground(True)
|
self.setAutoFillBackground(True)
|
||||||
self.set_colors()
|
self.set_colors()
|
||||||
|
self.pinned = 0
|
||||||
config_obj.changed.connect(self.set_colors)
|
config_obj.changed.connect(self.set_colors)
|
||||||
QTimer.singleShot(0, self._tabhide)
|
QTimer.singleShot(0, self._tabhide)
|
||||||
config_obj.changed.connect(self.on_tab_colors_changed)
|
config_obj.changed.connect(self.on_tab_colors_changed)
|
||||||
@ -479,14 +483,16 @@ class TabBar(QTabBar):
|
|||||||
return size
|
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.
|
# width. Also taken in consideration the reduced space necessary for
|
||||||
#looks like this generates high cpu usage
|
# the pinned tabs.
|
||||||
#need to register the number of pin tabs in advance
|
#TODO: During shutdown the self.count goes down, but the self.pinned not
|
||||||
#nb_of_pins = len([None for item in range(self.count())
|
#this generates some odd bahavior.
|
||||||
# if objreg.get('tab', scope='tab',
|
#To avoid this we compare self.count against self.pinned.
|
||||||
# window=self._win_id, tab=item).pin is True])
|
if self.pinned > 0 and self.count() > self.pinned:
|
||||||
#width = (self.width() + 40*nb_of_pins) / self.count()
|
width = (self.width() - 40*self.pinned) / (self.count() - self.pinned)
|
||||||
width = self.width() / self.count()
|
else:
|
||||||
|
width = self.width() / self.count()
|
||||||
|
|
||||||
## If width is not divisible by count, add a pixel to some tabs so
|
## If width is not divisible by 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 index < self.width() % self.count():
|
||||||
|
@ -381,6 +381,8 @@ class SessionManager(QObject):
|
|||||||
self._load_tab(new_tab, tab)
|
self._load_tab(new_tab, tab)
|
||||||
if tab.get('active', False):
|
if tab.get('active', False):
|
||||||
tab_to_focus = i
|
tab_to_focus = i
|
||||||
|
if new_tab.data.pinned:
|
||||||
|
tabbed_browser.set_tab_pinned(i, new_tab.data.pinned)
|
||||||
if tab_to_focus is not None:
|
if tab_to_focus is not None:
|
||||||
tabbed_browser.setCurrentIndex(tab_to_focus)
|
tabbed_browser.setCurrentIndex(tab_to_focus)
|
||||||
if win.get('active', False):
|
if win.get('active', False):
|
||||||
|
Loading…
Reference in New Issue
Block a user