summaryrefslogtreecommitdiff
path: root/qutebrowser/mainwindow/tabwidget.py
diff options
context:
space:
mode:
Diffstat (limited to 'qutebrowser/mainwindow/tabwidget.py')
-rw-r--r--qutebrowser/mainwindow/tabwidget.py51
1 files changed, 27 insertions, 24 deletions
diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py
index 2ac7cb6d4..be1c696cf 100644
--- a/qutebrowser/mainwindow/tabwidget.py
+++ b/qutebrowser/mainwindow/tabwidget.py
@@ -1,19 +1,6 @@
-# Copyright 2014-2021 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
+# SPDX-FileCopyrightText: 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 <https://www.gnu.org/licenses/>.
+# SPDX-License-Identifier: GPL-3.0-or-later
"""The tab widget used for TabbedBrowser from browser.py."""
@@ -374,7 +361,9 @@ class TabWidget(QTabWidget):
self.setTabIcon(idx, icon)
if config.val.tabs.tabs_are_windows:
- self.window().setWindowIcon(tab.icon())
+ window = self.window()
+ assert window is not None
+ window.setWindowIcon(tab.icon())
def setTabIcon(self, idx: int, icon: QIcon) -> None:
"""Always show tab icons for pinned tabs in some circumstances."""
@@ -384,7 +373,9 @@ class TabWidget(QTabWidget):
config.cache['tabs.pinned.shrink'] and
not self.tab_bar().vertical and
tab is not None and tab.data.pinned):
- icon = self.style().standardIcon(QStyle.StandardPixmap.SP_FileIcon)
+ style = self.style()
+ assert style is not None
+ icon = style.standardIcon(QStyle.StandardPixmap.SP_FileIcon)
super().setTabIcon(idx, icon)
@@ -424,6 +415,7 @@ class TabBar(QTabBar):
self._win_id = win_id
self._our_style = TabBarStyle()
self.setStyle(self._our_style)
+ self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
self.vertical = False
self._auto_hide_timer = QTimer()
self._auto_hide_timer.setSingleShot(True)
@@ -828,6 +820,17 @@ class TabBarStyle(QProxyStyle):
ICON_PADDING = 4
+ def __init__(self, style=None):
+ # "useless" override as WORKAROUND for
+ # https://www.riverbankcomputing.com/pipermail/pyqt/2023-September/045510.html
+ super().__init__(style)
+
+ def _base_style(self) -> QStyle:
+ """Get the base style."""
+ style = self.baseStyle()
+ assert style is not None
+ return style
+
def _draw_indicator(self, layouts, opt, p):
"""Draw the tab indicator.
@@ -855,7 +858,7 @@ class TabBarStyle(QProxyStyle):
icon_state = (QIcon.State.On if opt.state & QStyle.StateFlag.State_Selected
else QIcon.State.Off)
icon = opt.icon.pixmap(opt.iconSize, icon_mode, icon_state)
- self.baseStyle().drawItemPixmap(p, layouts.icon, Qt.AlignmentFlag.AlignCenter, icon)
+ self._base_style().drawItemPixmap(p, layouts.icon, Qt.AlignmentFlag.AlignCenter, icon)
def drawControl(self, element, opt, p, widget=None):
"""Override drawControl to draw odd tabs in a different color.
@@ -872,7 +875,7 @@ class TabBarStyle(QProxyStyle):
if element not in [QStyle.ControlElement.CE_TabBarTab, QStyle.ControlElement.CE_TabBarTabShape,
QStyle.ControlElement.CE_TabBarTabLabel]:
# Let the real style draw it.
- self.baseStyle().drawControl(element, opt, p, widget)
+ self._base_style().drawControl(element, opt, p, widget)
return
layouts = self._tab_layout(opt)
@@ -895,7 +898,7 @@ class TabBarStyle(QProxyStyle):
self._draw_icon(layouts, opt, p)
alignment = (config.cache['tabs.title.alignment'] |
Qt.AlignmentFlag.AlignVCenter | Qt.TextFlag.TextHideMnemonic)
- self.baseStyle().drawItemText(
+ self._base_style().drawItemText(
p,
layouts.text,
int(alignment),
@@ -925,7 +928,7 @@ class TabBarStyle(QProxyStyle):
QStyle.PixelMetric.PM_TabBarScrollButtonWidth]:
return 0
else:
- return self.baseStyle().pixelMetric(metric, option, widget)
+ return self._base_style().pixelMetric(metric, option, widget)
def subElementRect(self, sr, opt, widget=None):
"""Override subElementRect to use our own _tab_layout implementation.
@@ -955,7 +958,7 @@ class TabBarStyle(QProxyStyle):
# style differences...
return QCommonStyle.subElementRect(self, sr, opt, widget)
else:
- return self.baseStyle().subElementRect(sr, opt, widget)
+ return self._base_style().subElementRect(sr, opt, widget)
def _tab_layout(self, opt):
"""Compute the text/icon rect from the opt rect.
@@ -1002,7 +1005,7 @@ class TabBarStyle(QProxyStyle):
text_rect.adjust(
icon_rect.width() + TabBarStyle.ICON_PADDING, 0, 0, 0)
- text_rect = self.baseStyle().visualRect(opt.direction, opt.rect, text_rect)
+ text_rect = self._base_style().visualRect(opt.direction, opt.rect, text_rect)
return Layouts(text=text_rect, icon=icon_rect,
indicator=indicator_rect)
@@ -1037,5 +1040,5 @@ class TabBarStyle(QProxyStyle):
icon_top = text_rect.center().y() + 1 - tab_icon_size.height() // 2
icon_rect = QRect(QPoint(text_rect.left(), icon_top), tab_icon_size)
- icon_rect = self.baseStyle().visualRect(opt.direction, opt.rect, icon_rect)
+ icon_rect = self._base_style().visualRect(opt.direction, opt.rect, icon_rect)
return icon_rect