From b042b5cbc43eddc782c725570d504b0f63b061be Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 15 Jul 2014 07:45:53 +0200 Subject: [PATCH] Try drawing our own tab button --- qutebrowser/widgets/tabwidget.py | 37 ++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/qutebrowser/widgets/tabwidget.py b/qutebrowser/widgets/tabwidget.py index f6f21c90f..9193b3de7 100644 --- a/qutebrowser/widgets/tabwidget.py +++ b/qutebrowser/widgets/tabwidget.py @@ -22,7 +22,7 @@ from math import ceil import functools -from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QSize, QRect +from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QSize, QRect, QRectF from PyQt5.QtWidgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle, QStyle, QStylePainter, QStyleOptionTab) from PyQt5.QtGui import QIcon, QPalette, QColor @@ -183,6 +183,16 @@ class TabBar(QTabBar): continue p.drawControl(QStyle.CE_TabBarTab, tab) + def tabInserted(self, index): + """Extend tabInserted to set close button size policy. + + FIXME is this needed? + """ + super().tabInserted(index) + button = self.tabButton(index, QTabBar.RightSide) + if button is not None: + button.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) + class TabBarStyle(QCommonStyle): @@ -218,7 +228,7 @@ class TabBarStyle(QCommonStyle): 'generatedIconPixmap', 'hitTestComplexControl', 'pixelMetric', 'itemPixmapRect', 'itemTextRect', 'polish', 'styleHint', 'subControlRect', 'unpolish', - 'drawPrimitive', 'drawItemText', 'sizeFromContents'): + 'drawItemText', 'sizeFromContents'): target = getattr(self._style, method) setattr(self, method, functools.partial(target)) super().__init__() @@ -264,6 +274,29 @@ class TabBarStyle(QCommonStyle): # style. self._style.drawControl(element, opt, p, widget) + def drawPrimitive(self, element, opt, painter, widget=None): + """Draws the given primitive element. + + Args: + element: PrimitiveElement + opt: const QStyleOption * + painter: QPainter * + widget: const QWidget * + """ + if element != QStyle.PE_IndicatorTabClose: + self._style.drawPrimitive(element, opt, painter, widget) + return + painter.save() + painter.setPen(QColor(config.get('colors', 'tab.fg'))) + rect = QRectF(opt.rect) + center = rect.center() + new_size = rect.size() * 0.4 + rect.setSize(new_size) + rect.moveCenter(center) + painter.drawLine(rect.topLeft(), rect.bottomRight()) + painter.drawLine(rect.topRight(), rect.bottomLeft()) + painter.restore() + def pixelMetric(self, metric, option=None, widget=None): """Override pixelMetric to not shift the selected tab.