mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:37:43 +00:00
Ladybird: Add reset zoom level button to toolbar
This is a port of the Browser feature.
This commit is contained in:
parent
b7f9b316ed
commit
bdbea0baeb
4 changed files with 36 additions and 6 deletions
|
@ -336,7 +336,7 @@ void BrowserWindow::set_current_tab(Tab* tab)
|
||||||
{
|
{
|
||||||
m_current_tab = tab;
|
m_current_tab = tab;
|
||||||
if (tab)
|
if (tab)
|
||||||
update_zoom_menu_text();
|
update_displayed_zoom_level();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::debug_request(DeprecatedString const& request, DeprecatedString const& argument)
|
void BrowserWindow::debug_request(DeprecatedString const& request, DeprecatedString const& argument)
|
||||||
|
@ -523,7 +523,7 @@ void BrowserWindow::zoom_in()
|
||||||
if (!m_current_tab)
|
if (!m_current_tab)
|
||||||
return;
|
return;
|
||||||
m_current_tab->view().zoom_in();
|
m_current_tab->view().zoom_in();
|
||||||
update_zoom_menu_text();
|
update_displayed_zoom_level();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::zoom_out()
|
void BrowserWindow::zoom_out()
|
||||||
|
@ -531,7 +531,7 @@ void BrowserWindow::zoom_out()
|
||||||
if (!m_current_tab)
|
if (!m_current_tab)
|
||||||
return;
|
return;
|
||||||
m_current_tab->view().zoom_out();
|
m_current_tab->view().zoom_out();
|
||||||
update_zoom_menu_text();
|
update_displayed_zoom_level();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::reset_zoom()
|
void BrowserWindow::reset_zoom()
|
||||||
|
@ -539,7 +539,7 @@ void BrowserWindow::reset_zoom()
|
||||||
if (!m_current_tab)
|
if (!m_current_tab)
|
||||||
return;
|
return;
|
||||||
m_current_tab->view().reset_zoom();
|
m_current_tab->view().reset_zoom();
|
||||||
update_zoom_menu_text();
|
update_displayed_zoom_level();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::select_all()
|
void BrowserWindow::select_all()
|
||||||
|
@ -548,11 +548,12 @@ void BrowserWindow::select_all()
|
||||||
tab->view().select_all();
|
tab->view().select_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::update_zoom_menu_text()
|
void BrowserWindow::update_displayed_zoom_level()
|
||||||
{
|
{
|
||||||
VERIFY(m_zoom_menu && m_current_tab);
|
VERIFY(m_zoom_menu && m_current_tab);
|
||||||
auto zoom_level_text = MUST(String::formatted("&Zoom ({}%)", round_to<int>(m_current_tab->view().zoom_level() * 100)));
|
auto zoom_level_text = MUST(String::formatted("&Zoom ({}%)", round_to<int>(m_current_tab->view().zoom_level() * 100)));
|
||||||
m_zoom_menu->setTitle(qstring_from_ak_string(zoom_level_text));
|
m_zoom_menu->setTitle(qstring_from_ak_string(zoom_level_text));
|
||||||
|
m_current_tab->update_reset_zoom_button();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::copy_selected_text()
|
void BrowserWindow::copy_selected_text()
|
||||||
|
|
|
@ -60,7 +60,7 @@ private:
|
||||||
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = "");
|
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = "");
|
||||||
|
|
||||||
void set_current_tab(Tab* tab);
|
void set_current_tab(Tab* tab);
|
||||||
void update_zoom_menu_text();
|
void update_displayed_zoom_level();
|
||||||
|
|
||||||
QTabWidget* m_tabs_container { nullptr };
|
QTabWidget* m_tabs_container { nullptr };
|
||||||
Vector<NonnullOwnPtr<Tab>> m_tabs;
|
Vector<NonnullOwnPtr<Tab>> m_tabs;
|
||||||
|
|
|
@ -31,6 +31,7 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path)
|
||||||
m_view = new WebContentView(webdriver_content_ipc_path);
|
m_view = new WebContentView(webdriver_content_ipc_path);
|
||||||
m_toolbar = new QToolBar(this);
|
m_toolbar = new QToolBar(this);
|
||||||
m_location_edit = new LocationEdit(this);
|
m_location_edit = new LocationEdit(this);
|
||||||
|
m_reset_zoom_button = new QToolButton(m_toolbar);
|
||||||
|
|
||||||
m_hover_label = new QLabel(this);
|
m_hover_label = new QLabel(this);
|
||||||
m_hover_label->hide();
|
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_reload_action);
|
||||||
m_toolbar->addAction(m_home_action);
|
m_toolbar->addAction(m_home_action);
|
||||||
m_toolbar->addWidget(m_location_edit);
|
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] {
|
QObject::connect(m_view, &WebContentView::activate_tab, [this] {
|
||||||
m_window->activate_tab(tab_index());
|
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()
|
void Tab::focus_location_editor()
|
||||||
{
|
{
|
||||||
m_location_edit->setFocus();
|
m_location_edit->setFocus();
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
|
#include <QToolButton>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class BrowserWindow;
|
class BrowserWindow;
|
||||||
|
@ -35,6 +36,8 @@ public:
|
||||||
|
|
||||||
void debug_request(DeprecatedString const& request, DeprecatedString const& argument);
|
void debug_request(DeprecatedString const& request, DeprecatedString const& argument);
|
||||||
|
|
||||||
|
void update_reset_zoom_button();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void focus_location_editor();
|
void focus_location_editor();
|
||||||
void location_edit_return_pressed();
|
void location_edit_return_pressed();
|
||||||
|
@ -56,6 +59,8 @@ private:
|
||||||
|
|
||||||
QBoxLayout* m_layout;
|
QBoxLayout* m_layout;
|
||||||
QToolBar* m_toolbar { nullptr };
|
QToolBar* m_toolbar { nullptr };
|
||||||
|
QToolButton* m_reset_zoom_button { nullptr };
|
||||||
|
QAction* m_reset_zoom_button_action { nullptr };
|
||||||
LocationEdit* m_location_edit { nullptr };
|
LocationEdit* m_location_edit { nullptr };
|
||||||
WebContentView* m_view { nullptr };
|
WebContentView* m_view { nullptr };
|
||||||
BrowserWindow* m_window { nullptr };
|
BrowserWindow* m_window { nullptr };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue