Add auto-hide option for tabs.

This commit is contained in:
Florian Bruhin 2014-09-18 18:15:37 +02:00
parent 906a049382
commit 076ed43ec0
2 changed files with 22 additions and 0 deletions

View File

@ -389,6 +389,10 @@ DATA = collections.OrderedDict([
SettingValue(typ.LastClose(), 'ignore'),
"Behaviour when the last tab is closed."),
('auto-hide',
SettingValue(typ.Bool(), 'false'),
"Hide the tabbar if only one tab is open."),
('wrap',
SettingValue(typ.Bool(), 'true'),
"Whether to wrap when changing tabs."),

View File

@ -138,6 +138,12 @@ class TabBar(QTabBar):
p = self.palette()
p.setColor(QPalette.Window, config.get('colors', 'tab.bg.bar'))
self.setPalette(p)
elif section == 'tabs' and option == 'auto-hide':
hide = config.get('tabs', 'auto-hide')
if hide and self.count() == 1:
self.hide()
elif not hide:
self.show()
def mousePressEvent(self, e):
"""Override mousePressEvent to close tabs if configured."""
@ -240,6 +246,18 @@ class TabBar(QTabBar):
continue
p.drawControl(QStyle.CE_TabBarTab, tab)
def tabInserted(self, idx):
"""Show the tabbar if configured to hide and >1 tab is open."""
if self.count() > 1 and config.get('tabs', 'auto-hide'):
self.show()
super().tabInserted(idx)
def tabRemoved(self, idx):
"""Hide the tabbar if configured when only one tab is open."""
if self.count() <= 1 and config.get('tabs', 'auto-hide'):
self.hide()
super().tabRemoved(idx)
class TabBarStyle(QCommonStyle):