Add tabs.max_width setting

This commit is contained in:
Jay Kamat 2018-09-26 21:01:21 -07:00
parent 4352d9dcee
commit e01682f51d
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5
3 changed files with 38 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

@ -610,6 +610,9 @@ class TabBar(QTabBar):
# Request as much space as possible so we fill the tabbar, let
# Qt shrink us down
width = self.width()
max_width = config.cache['tabs.max_width']
if max_width > 0:
width = min(max_width, width)
# If we don't have enough space, we return the minimum size
width = max(width, minimum_size.width())

View File

@ -38,6 +38,7 @@ class TestTabWidget:
qtbot.addWidget(w)
monkeypatch.setattr(tabwidget.objects, 'backend',
usertypes.Backend.QtWebKit)
monkeypatch.setattr(w.tabBar(), 'width', w.width)
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,22 @@ class TestTabWidget:
benchmark(widget.update_tab_titles)
def test_tab_min_width(self, widget, fake_web_tab, config_stub):
"""Ensure by default, all tab sizes are the same."""
widget.addTab(fake_web_tab(), 'foobar')
normal_size = widget.tabBar().minimumTabSizeHint(0).width()
normal_size += 100
config_stub.val.tabs.min_width = normal_size
assert widget.tabBar().minimumTabSizeHint(0).width() == normal_size
def test_tab_max_width(self, widget, fake_web_tab, config_stub):
"""Ensure by default, all tab sizes are the same."""
widget.addTab(fake_web_tab(), 'foobar')
normal_size = widget.tabBar().tabSizeHint(0).width()
normal_size -= 10
config_stub.val.tabs.max_width = normal_size
assert widget.tabBar().tabSizeHint(0).width() == normal_size
@pytest.mark.parametrize("num_tabs", [4, 10])
def test_add_remove_tab_benchmark(self, benchmark, browser,
qtbot, fake_web_tab, num_tabs):