1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

Ladybird: Add reset zoom level button to toolbar

This is a port of the Browser feature.
This commit is contained in:
MacDue 2023-03-29 00:25:42 +01:00 committed by Andreas Kling
parent b7f9b316ed
commit bdbea0baeb
4 changed files with 36 additions and 6 deletions

View file

@ -31,6 +31,7 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path)
m_view = new WebContentView(webdriver_content_ipc_path);
m_toolbar = new QToolBar(this);
m_location_edit = new LocationEdit(this);
m_reset_zoom_button = new QToolButton(m_toolbar);
m_hover_label = new QLabel(this);
m_hover_label->hide();
@ -63,6 +64,17 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path)
m_toolbar->addAction(m_reload_action);
m_toolbar->addAction(m_home_action);
m_toolbar->addWidget(m_location_edit);
m_reset_zoom_button_action = m_toolbar->addWidget(m_reset_zoom_button);
m_reset_zoom_button_action->setVisible(false);
QObject::connect(m_reset_zoom_button, &QAbstractButton::clicked, [this] {
view().reset_zoom();
update_reset_zoom_button();
});
QObject::connect(m_view, &WebContentView::link_unhovered, [this] {
m_hover_label->hide();
});
QObject::connect(m_view, &WebContentView::activate_tab, [this] {
m_window->activate_tab(tab_index());
@ -155,6 +167,18 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path)
});
}
void Tab::update_reset_zoom_button()
{
auto zoom_level = view().zoom_level();
if (zoom_level != 1.0f) {
auto zoom_level_text = MUST(String::formatted("{}%", round_to<int>(zoom_level * 100)));
m_reset_zoom_button->setText(qstring_from_ak_string(zoom_level_text));
m_reset_zoom_button_action->setVisible(true);
} else {
m_reset_zoom_button_action->setVisible(false);
}
}
void Tab::focus_location_editor()
{
m_location_edit->setFocus();