Merge remote-tracking branch 'origin/pr/4261'

This commit is contained in:
Florian Bruhin 2018-09-28 12:34:04 +02:00
commit 3eed63346e
3 changed files with 35 additions and 1 deletions

View File

@ -1602,6 +1602,23 @@ tabs.min_width:
This setting does not apply to pinned tabs, unless `tabs.pinned.shrink` is False.
tabs.max_width:
default: -1
type:
name: Int
minval: -1
maxval: maxint
desc: >-
Maximum width (in pixels) of tabs (-1 for no maximum).
This setting only applies when tabs are horizontal.
This setting does not apply to pinned tabs, unless `tabs.pinned.shrink` is
False.
This setting may not apply properly if max_width is smaller than the
minimum size of tab contents, or smaller than tabs.min_width.
tabs.width.indicator:
renamed: tabs.indicator.width

View File

@ -616,6 +616,9 @@ class TabBar(QTabBar):
# Qt shrink us down. If for some reason (tests, bugs)
# self.width() gives 0, use a sane min of 10 px
width = max(self.width(), 10)
max_width = config.cache['tabs.max_width']
if max_width > 0:
width = min(max_width, width)
size = QSize(width, height)
qtutils.ensure_valid(size)
return size

View File

@ -38,6 +38,7 @@ class TestTabWidget:
qtbot.addWidget(w)
monkeypatch.setattr(tabwidget.objects, 'backend',
usertypes.Backend.QtWebKit)
w.show()
return w
@pytest.fixture
@ -108,7 +109,7 @@ class TestTabWidget:
for i in range(num_tabs):
if i in pinned_num and shrink_pinned and not vertical:
assert (first_size.width() <
assert (first_size.width() >
widget.tabBar().tabSizeHint(i).width())
assert (first_size_min.width() <
widget.tabBar().minimumTabSizeHint(i).width())
@ -128,6 +129,19 @@ class TestTabWidget:
benchmark(widget.update_tab_titles)
def test_tab_min_width(self, widget, fake_web_tab, config_stub, qtbot):
widget.addTab(fake_web_tab(), 'foobar')
widget.addTab(fake_web_tab(), 'foobar1')
min_size = widget.tabBar().tabRect(0).width() + 10
config_stub.val.tabs.min_width = min_size
assert widget.tabBar().tabRect(0).width() == min_size
def test_tab_max_width(self, widget, fake_web_tab, config_stub, qtbot):
widget.addTab(fake_web_tab(), 'foobar')
max_size = widget.tabBar().tabRect(0).width() - 10
config_stub.val.tabs.max_width = max_size
assert widget.tabBar().tabRect(0).width() == max_size
@pytest.mark.parametrize("num_tabs", [4, 10])
def test_add_remove_tab_benchmark(self, benchmark, browser,
qtbot, fake_web_tab, num_tabs):