From 6549fd84ce461d3098c13818219df4e4bfd6b444 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Wed, 26 Apr 2017 02:49:57 +0200 Subject: [PATCH] Add tabs->favicon-scale setting This allows users to change the size of the favicon independently from the size of the font/tab, in order to adjust the balance between favicons and text. The drawing code is also adjusted to place the icon relative to the text center, rather than the text top. Works as expected even for values of 0.0 (which is equivalent to hiding the favicon completely). Closes #2549. --- doc/help/settings.asciidoc | 7 +++++++ qutebrowser/config/configdata.py | 5 +++++ qutebrowser/mainwindow/tabwidget.py | 14 +++++++++++--- tests/unit/mainwindow/test_tabwidget.py | 1 + 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index c6a80754c..68ca0a118 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -126,6 +126,7 @@ |<>|On which mouse button to close tabs. |<>|The position of the tab bar. |<>|Whether to show favicons in the tab bar. +|<>|Scale for favicons in the tab bar. The tab size is unchanged, so big favicons also require extra `tabs->padding`. |<>|The width of the tab bar if it's vertical, in px or as percentage of the window. |<>|Width of the progress indicator (0 to disable). |<>|Whether to open windows instead of tabs. @@ -1206,6 +1207,12 @@ Valid values: Default: +pass:[true]+ +[[tabs-favicon-scale]] +=== favicon-scale +Scale for favicons in the tab bar. The tab size is unchanged, so big favicons also require extra `tabs->padding`. + +Default: +pass:[1.0]+ + [[tabs-width]] === width The width of the tab bar if it's vertical, in px or as percentage of the window. diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 2bfcabce7..2de0c3eb2 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -680,6 +680,11 @@ def data(readonly=False): SettingValue(typ.Bool(), 'true'), "Whether to show favicons in the tab bar."), + ('favicon-scale', + SettingValue(typ.Float(minval=0.0), '1.0'), + "Scale for favicons in the tab bar. The tab size is unchanged, " + "so big favicons also require extra `tabs->padding`."), + ('width', SettingValue(typ.PercOrInt(minperc=0, maxperc=100, minint=1), '20%'), diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index ce96607fa..f5a0b3c55 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -22,7 +22,8 @@ import collections import functools -from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QSize, QRect, QTimer, QUrl +from PyQt5.QtCore import (pyqtSignal, pyqtSlot, Qt, QSize, QRect, QPoint, + QTimer, QUrl) from PyQt5.QtWidgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle, QStyle, QStylePainter, QStyleOptionTab) from PyQt5.QtGui import QIcon, QPalette, QColor @@ -273,6 +274,7 @@ class TabBar(QTabBar): self.set_font() config_obj = objreg.get('config') config_obj.changed.connect(self.set_font) + config_obj.changed.connect(self.set_icon_size) self.vertical = False self._page_fullscreen = False self._auto_hide_timer = QTimer() @@ -374,7 +376,13 @@ class TabBar(QTabBar): def set_font(self): """Set the tab bar font.""" self.setFont(config.get('fonts', 'tabbar')) + self.set_icon_size() + + @config.change_filter('tabs', 'favicon-scale') + def set_icon_size(self): + """Set the tab bar favicon size.""" size = self.fontMetrics().height() - 2 + size *= config.get('tabs', 'favicon-scale') self.setIconSize(QSize(size, size)) @config.change_filter('colors', 'tabs.bg.bar') @@ -775,7 +783,7 @@ class TabBarStyle(QCommonStyle): tab_icon_size = QSize( min(actual_size.width(), icon_size.width()), min(actual_size.height(), icon_size.height())) - icon_rect = QRect(text_rect.left(), text_rect.top() + 1, - tab_icon_size.width(), tab_icon_size.height()) + 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._style.visualRect(opt.direction, opt.rect, icon_rect) return icon_rect diff --git a/tests/unit/mainwindow/test_tabwidget.py b/tests/unit/mainwindow/test_tabwidget.py index 2d3e9bda2..7a3fd68af 100644 --- a/tests/unit/mainwindow/test_tabwidget.py +++ b/tests/unit/mainwindow/test_tabwidget.py @@ -44,6 +44,7 @@ class TestTabWidget: 'select-on-remove': 1, 'show': 'always', 'show-favicons': True, + 'favicon-scale': 1.0, 'padding': configtypes.PaddingValues(0, 0, 5, 5), 'indicator-width': 3, 'indicator-padding': configtypes.PaddingValues(2, 2, 0, 4),