Tabs->show option.

Issue #771
Implemted common option for tab bar show strategy.
Options: always, never, multiple, switching.
This commit is contained in:
Artur Shaik 2015-06-19 12:06:48 +06:00 committed by Florian Bruhin
parent edf431f541
commit b4d5f9e7a6
3 changed files with 46 additions and 18 deletions

View File

@ -479,13 +479,13 @@ def data(readonly=False):
SettingValue(typ.LastClose(), 'ignore'),
"Behavior when the last tab is closed."),
('hide-auto',
SettingValue(typ.Bool(), 'false'),
"Hide the tab bar if only one tab is open."),
('show',
SettingValue(typ.TabBarShow(), 'always'),
"The tab bar showing strategy."),
('hide-always',
SettingValue(typ.Bool(), 'false'),
"Always hide the tab bar."),
('show-switching-delay',
SettingValue(typ.Int(), '800'),
"Time to show tab bar before hide it when tabs->show is switching."),
('wrap',
SettingValue(typ.Bool(), 'true'),

View File

@ -1566,3 +1566,14 @@ class UserAgent(BaseType):
"curl 7.40.0")
]
return out
class TabBarShow(BaseType):
"""How to format the question when downloading."""
valid_values = ValidValues(('always', "Always show the tab bar."),
('never', "Always hide the tab bar."),
('multiple', "Hide the tab bar if only one tab is open."),
('switching', "Show the tab bar only when current tab changed."))

View File

@ -194,6 +194,7 @@ class TabWidget(QTabWidget):
@pyqtSlot(int)
def emit_tab_index_changed(self, index):
"""Emit the tab_index_changed signal if the current tab changed."""
self.tabBar().on_change()
self.tab_index_changed.emit(index, self.count())
@ -220,32 +221,48 @@ class TabBar(QTabBar):
config_obj = objreg.get('config')
config_obj.changed.connect(self.set_font)
self.vertical = False
self.autoHideTimer = None
self.setAutoFillBackground(True)
self.set_colors()
config_obj.changed.connect(self.set_colors)
QTimer.singleShot(0, self._tabhide)
config_obj.changed.connect(self.autohide)
config_obj.changed.connect(self.alwayshide)
config_obj.changed.connect(self.on_tab_colors_changed)
config_obj.changed.connect(self.showswitchingdelay)
config_obj.changed.connect(self.tabs_show)
def __repr__(self):
return utils.get_repr(self, count=self.count())
@config.change_filter('tabs', 'hide-auto')
def autohide(self):
"""Hide tab bar if needed when tabs->hide-auto got changed."""
@config.change_filter('tabs', 'show')
def tabs_show(self):
"""Hide or show tab bar if needed when tabs->show got changed."""
self._tabhide()
@config.change_filter('tabs', 'hide-always')
def alwayshide(self):
"""Hide tab bar if needed when tabs->hide-always got changed."""
self._tabhide()
@config.change_filter('tabs', 'show-switching-delay')
def showswitchingdelay(self):
"""Reset auto hide timer when tabs->show-switching-delay got changed."""
self.autoHideTimer = None
def on_change(self):
"""Show tab bar when current tab got changed."""
show = config.get('tabs', 'show')
show_switching_delay = config.get('tabs', 'show-switching-delay')
if show == 'switching':
self.show()
if not self.autoHideTimer:
self.autoHideTimer = QTimer()
self.autoHideTimer.setInterval(show_switching_delay)
self.autoHideTimer.setSingleShot(True)
self.autoHideTimer.timeout.connect(self._tabhide)
self.autoHideTimer.start()
def _tabhide(self):
"""Hide the tab bar if needed."""
hide_auto = config.get('tabs', 'hide-auto')
hide_always = config.get('tabs', 'hide-always')
if hide_always or (hide_auto and self.count() == 1):
show = config.get('tabs', 'show')
showNever = show == 'never'
showSwitching = show == 'switching'
showMultiple = show == 'multiple'
if showNever or (showMultiple and self.count() == 1) or showSwitching:
self.hide()
else:
self.show()