qutebrowser/qutebrowser/widgets/tabwidget.py

105 lines
3.3 KiB
Python
Raw Normal View History

2014-02-06 14:01:23 +01:00
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
2014-02-17 12:23:52 +01:00
"""The tab widget used for TabbedBrowser from browser.py."""
from PyQt5.QtCore import pyqtSlot, Qt
2014-02-17 12:23:52 +01:00
from PyQt5.QtWidgets import QTabWidget, QTabBar, QSizePolicy
2013-12-15 20:29:39 +01:00
2014-02-23 18:07:17 +01:00
import qutebrowser.config.config as config
from qutebrowser.config.style import set_register_stylesheet
from qutebrowser.utils.style import Style
2014-01-28 12:21:00 +01:00
2014-01-28 23:04:02 +01:00
2013-12-15 20:29:39 +01:00
class TabWidget(QTabWidget):
2014-02-07 20:21:50 +01:00
2014-02-18 16:38:13 +01:00
"""The tabwidget used for TabbedBrowser.
2014-04-17 17:44:27 +02:00
Class attributes:
STYLESHEET: The stylesheet template to be used.
2014-02-18 16:38:13 +01:00
"""
2013-12-15 20:29:39 +01:00
2014-01-27 23:12:43 +01:00
# FIXME there is still some ugly 1px white stripe from somewhere if we do
# background-color: grey for QTabBar...
STYLESHEET = """
2014-01-28 12:21:00 +01:00
QTabWidget::pane {{
position: absolute;
top: 0px;
2014-01-28 12:21:00 +01:00
}}
2014-01-28 12:21:00 +01:00
QTabBar {{
2014-02-10 07:03:51 +01:00
{font[tabbar]}
2014-01-28 12:21:00 +01:00
}}
2013-12-15 20:29:39 +01:00
2014-01-28 12:21:00 +01:00
QTabBar::tab {{
{color[tab.bg]}
{color[tab.fg]}
padding-left: 5px;
padding-right: 5px;
padding-top: 0px;
padding-bottom: 0px;
2014-01-28 12:21:00 +01:00
}}
2013-12-15 20:29:39 +01:00
2014-01-28 12:21:00 +01:00
QTabBar::tab:first, QTabBar::tab:middle {{
border-right: 1px solid {color[tab.seperator]};
}}
2014-01-27 23:12:43 +01:00
2014-01-28 12:21:00 +01:00
QTabBar::tab:selected {{
{color[tab.bg.selected]}
}}
"""
def __init__(self, parent):
super().__init__(parent)
2014-01-30 22:29:01 +01:00
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.setStyle(Style(self.style()))
set_register_stylesheet(self)
2013-12-15 20:29:39 +01:00
self.setDocumentMode(True)
2014-01-19 16:56:33 +01:00
self.setElideMode(Qt.ElideRight)
2014-02-13 08:56:01 +01:00
self._init_config()
def _init_config(self):
"""Initialize attributes based on the config."""
position_conv = {
'north': QTabWidget.North,
'south': QTabWidget.South,
'west': QTabWidget.West,
'east': QTabWidget.East,
}
select_conv = {
'left': QTabBar.SelectLeftTab,
'right': QTabBar.SelectRightTab,
'previous': QTabBar.SelectPreviousTab,
}
self.setMovable(config.get('tabbar', 'movable'))
self.setTabsClosable(config.get('tabbar', 'closebuttons'))
self.setUsesScrollButtons(config.get('tabbar', 'scrollbuttons'))
posstr = config.get('tabbar', 'position')
selstr = config.get('tabbar', 'select_on_remove')
2014-02-13 08:56:01 +01:00
try:
self.setTabPosition(position_conv[posstr])
self.tabBar().setSelectionBehaviorOnRemove(select_conv[selstr])
except KeyError:
pass
@pyqtSlot(str, str)
2014-04-22 17:53:27 +02:00
def on_config_changed(self, section, _option):
"""Update attributes when config changed."""
if section == 'tabbar':
self._init_config()