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."""
|
|
|
|
|
2014-04-10 23:30:45 +02:00
|
|
|
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
|
2014-04-10 23:30:45 +02:00
|
|
|
from qutebrowser.config.style import set_register_stylesheet
|
2014-02-11 07:01:59 +01:00
|
|
|
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:
|
2014-04-10 23:30:45 +02:00
|
|
|
STYLESHEET: The stylesheet template to be used.
|
2014-02-18 16:38:13 +01:00
|
|
|
"""
|
2013-12-15 20:29:39 +01:00
|
|
|
|
2014-04-10 23:30:45 +02:00
|
|
|
STYLESHEET = """
|
2014-01-28 12:21:00 +01:00
|
|
|
QTabWidget::pane {{
|
2014-01-21 10:47:22 +01:00
|
|
|
position: absolute;
|
|
|
|
top: 0px;
|
2014-01-28 12:21:00 +01:00
|
|
|
}}
|
2014-01-21 10:47:22 +01:00
|
|
|
|
2014-01-28 12:21:00 +01:00
|
|
|
QTabBar {{
|
2014-02-10 07:03:51 +01:00
|
|
|
{font[tabbar]}
|
2014-04-22 20:49:16 +02:00
|
|
|
{color[tab.bg.bar]}
|
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]}
|
2014-04-22 23:02:51 +02:00
|
|
|
padding: 0px 5px 0px 5px;
|
2014-05-01 21:30:29 +02:00
|
|
|
border-right: 2px solid {color[tab.seperator]};
|
2014-05-12 16:04:43 +02:00
|
|
|
min-width: {config[tabbar][min-tab-width]}px;
|
|
|
|
max-width: {config[tabbar][max-tab-width]}px;
|
2014-01-28 12:21:00 +01:00
|
|
|
}}
|
2014-01-27 23:12:43 +01:00
|
|
|
|
2014-01-28 12:21:00 +01:00
|
|
|
QTabBar::tab:selected {{
|
|
|
|
{color[tab.bg.selected]}
|
|
|
|
}}
|
2014-01-21 10:47:22 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, parent):
|
|
|
|
super().__init__(parent)
|
2014-01-30 22:29:01 +01:00
|
|
|
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
2014-02-11 07:01:59 +01:00
|
|
|
self.setStyle(Style(self.style()))
|
2014-04-10 23:30:45 +02:00
|
|
|
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-04-22 20:49:16 +02:00
|
|
|
self.tabBar().setDrawBase(False)
|
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,
|
|
|
|
}
|
2014-04-17 15:26:27 +02:00
|
|
|
self.setMovable(config.get('tabbar', 'movable'))
|
2014-04-27 21:21:14 +02:00
|
|
|
self.setTabsClosable(config.get('tabbar', 'close-buttons'))
|
|
|
|
self.setUsesScrollButtons(config.get('tabbar', 'scroll-buttons'))
|
2014-04-17 15:26:27 +02:00
|
|
|
posstr = config.get('tabbar', 'position')
|
2014-04-27 21:21:14 +02:00
|
|
|
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
|
2014-04-10 23:30:45 +02:00
|
|
|
|
2014-04-17 11:39:25 +02:00
|
|
|
@pyqtSlot(str, str)
|
2014-04-22 17:53:27 +02:00
|
|
|
def on_config_changed(self, section, _option):
|
2014-04-10 23:30:45 +02:00
|
|
|
"""Update attributes when config changed."""
|
|
|
|
if section == 'tabbar':
|
|
|
|
self._init_config()
|