feat: show zoom percentage in statusbar resolving #2870

This commit is contained in:
Skeptic Spriggan 2025-11-08 00:06:19 +01:00
parent 395bdfe2b1
commit bc42d5c3be
3 changed files with 31 additions and 14 deletions

View File

@ -252,7 +252,7 @@ class StatusBar(QWidget):
if segment == 'scroll_raw':
widget.set_raw()
elif segment in ('history', 'progress'):
elif segment in ('history', 'progress', 'zoom'):
widget.enabled = True
if tab:
widget.on_tab_changed(tab)

View File

@ -18,9 +18,10 @@ class Zoom(textbase.TextBase):
def on_zoom_changed(self, factor: float) -> None:
"""Update percentage when factor changed."""
if factor == 1 and config.val.statusbar.zoom.show == 'non-default':
self.setText("")
self.hide()
return
percentage = int(100 * factor)
self.show()
percentage = round(100 * factor)
self.setText(f"[{percentage}%]")
def on_tab_changed(self, tab: browsertab.AbstractTab) -> None:

View File

@ -15,18 +15,17 @@ def zoom(qtbot: pytestqt.qtbot.QtBot, config_stub: Any) -> Zoom:
return widget
@pytest.mark.parametrize('factor, show, expected', [
(1, 'always', '[100%]'),
(1.5, 'always', '[150%]'),
(2, 'always', '[200%]'),
(0.5, 'always', '[50%]'),
(0.25, 'always', '[25%]'),
(1, 'non-default', ''),
(1.5, 'non-default', '[150%]'),
(2, 'non-default', '[200%]'),
(0.5, 'non-default', '[50%]'),
(0.25, 'non-default', '[25%]'),
@pytest.mark.parametrize('factor, expected', [
(0.25, '[25%]'),
(0.5, '[50%]'),
(0.75, '[75%]'),
(1.5, '[150%]'),
(2, '[200%]'),
(3, '[300%]'),
(4, '[400%]'),
(5, '[500%]'),
])
@pytest.mark.parametrize("show", ["non-default", "always"])
def test_percentage_texts(zoom: Zoom, factor: float, show: str, expected: str,
config_stub: Any) -> None:
"""Test text displayed by the widget based on the zoom factor of a tab and a config value.
@ -41,6 +40,23 @@ def test_percentage_texts(zoom: Zoom, factor: float, show: str, expected: str,
assert zoom.text() == expected
@pytest.mark.parametrize('show, expected', [
("always", '[100%]'),
("non-default", ''),
])
def test_default_percentage_text(zoom: Zoom, show: str, expected: str,
config_stub: Any) -> None:
"""Test default percentage text based on a config value.
Args:
show: config value for `statusbar.zoom.show`.
expected: expected text given show config value.
"""
config_stub.val.statusbar.zoom.show = show
zoom.on_zoom_changed(factor=1)
assert zoom.text() == expected
def test_tab_change(zoom: Zoom, fake_web_tab: Any) -> None:
"""Test zoom factor change when switching tabs."""
zoom.on_zoom_changed(factor=2)