From b4d5f9e7a6129bccf07feb50c193a448e4dda234 Mon Sep 17 00:00:00 2001 From: Artur Shaik Date: Fri, 19 Jun 2015 12:06:48 +0600 Subject: [PATCH] Tabs->show option. Issue #771 Implemted common option for tab bar show strategy. Options: always, never, multiple, switching. --- qutebrowser/config/configdata.py | 12 ++++----- qutebrowser/config/configtypes.py | 11 ++++++++ qutebrowser/mainwindow/tabwidget.py | 41 ++++++++++++++++++++--------- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 5968731f3..87ff31995 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -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'), diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index da2efda06..c054d1779 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -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.")) + + diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 5ba9bb66d..14e428fe9 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -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()