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'), SettingValue(typ.LastClose(), 'ignore'),
"Behavior when the last tab is closed."), "Behavior when the last tab is closed."),
('hide-auto', ('show',
SettingValue(typ.Bool(), 'false'), SettingValue(typ.TabBarShow(), 'always'),
"Hide the tab bar if only one tab is open."), "The tab bar showing strategy."),
('hide-always', ('show-switching-delay',
SettingValue(typ.Bool(), 'false'), SettingValue(typ.Int(), '800'),
"Always hide the tab bar."), "Time to show tab bar before hide it when tabs->show is switching."),
('wrap', ('wrap',
SettingValue(typ.Bool(), 'true'), SettingValue(typ.Bool(), 'true'),

View File

@ -1566,3 +1566,14 @@ class UserAgent(BaseType):
"curl 7.40.0") "curl 7.40.0")
] ]
return out 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) @pyqtSlot(int)
def emit_tab_index_changed(self, index): def emit_tab_index_changed(self, index):
"""Emit the tab_index_changed signal if the current tab changed.""" """Emit the tab_index_changed signal if the current tab changed."""
self.tabBar().on_change()
self.tab_index_changed.emit(index, self.count()) self.tab_index_changed.emit(index, self.count())
@ -220,32 +221,48 @@ class TabBar(QTabBar):
config_obj = objreg.get('config') config_obj = objreg.get('config')
config_obj.changed.connect(self.set_font) config_obj.changed.connect(self.set_font)
self.vertical = False self.vertical = False
self.autoHideTimer = None
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.set_colors() self.set_colors()
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.autohide)
config_obj.changed.connect(self.alwayshide)
config_obj.changed.connect(self.on_tab_colors_changed) 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): def __repr__(self):
return utils.get_repr(self, count=self.count()) return utils.get_repr(self, count=self.count())
@config.change_filter('tabs', 'hide-auto') @config.change_filter('tabs', 'show')
def autohide(self): def tabs_show(self):
"""Hide tab bar if needed when tabs->hide-auto got changed.""" """Hide or show tab bar if needed when tabs->show got changed."""
self._tabhide() self._tabhide()
@config.change_filter('tabs', 'hide-always') @config.change_filter('tabs', 'show-switching-delay')
def alwayshide(self): def showswitchingdelay(self):
"""Hide tab bar if needed when tabs->hide-always got changed.""" """Reset auto hide timer when tabs->show-switching-delay got changed."""
self._tabhide() 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): def _tabhide(self):
"""Hide the tab bar if needed.""" """Hide the tab bar if needed."""
hide_auto = config.get('tabs', 'hide-auto') show = config.get('tabs', 'show')
hide_always = config.get('tabs', 'hide-always') showNever = show == 'never'
if hide_always or (hide_auto and self.count() == 1): showSwitching = show == 'switching'
showMultiple = show == 'multiple'
if showNever or (showMultiple and self.count() == 1) or showSwitching:
self.hide() self.hide()
else: else:
self.show() self.show()