mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
Ladybird: Expanded toolbar with browser history and home button
This patch takes the browser history code from the Serenity browser and wires it up to the QT interface. This is tied in with a few extra toolbar buttons associated with each tab.
This commit is contained in:
parent
67ab6dd2e6
commit
7681ef25da
7 changed files with 194 additions and 9 deletions
|
@ -7,9 +7,9 @@
|
|||
|
||||
#include "Tab.h"
|
||||
#include "BrowserWindow.h"
|
||||
#include "History.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QStatusBar>
|
||||
#include <utility>
|
||||
|
||||
extern String s_serenity_resource_root;
|
||||
|
||||
|
@ -26,21 +26,67 @@ Tab::Tab(QMainWindow* window)
|
|||
m_layout->addWidget(m_toolbar);
|
||||
m_layout->addWidget(m_view);
|
||||
|
||||
auto back_icon_path = QString("%1/res/icons/16x16/go-back.png").arg(s_serenity_resource_root.characters());
|
||||
auto forward_icon_path = QString("%1/res/icons/16x16/go-forward.png").arg(s_serenity_resource_root.characters());
|
||||
auto home_icon_path = QString("%1/res/icons/16x16/go-home.png").arg(s_serenity_resource_root.characters());
|
||||
auto reload_icon_path = QString("%1/res/icons/16x16/reload.png").arg(s_serenity_resource_root.characters());
|
||||
auto* reload_action = new QAction(QIcon(reload_icon_path), "Reload");
|
||||
reload_action->setShortcut(QKeySequence("Ctrl+R"));
|
||||
m_toolbar->addAction(reload_action);
|
||||
m_back_action = make<QAction>(QIcon(back_icon_path), "Back");
|
||||
m_back_action->setShortcut(QKeySequence("Alt+Left"));
|
||||
m_forward_action = make<QAction>(QIcon(forward_icon_path), "Forward");
|
||||
m_forward_action->setShortcut(QKeySequence("Alt+Right"));
|
||||
m_home_action = make<QAction>(QIcon(home_icon_path), "Home");
|
||||
m_reload_action = make<QAction>(QIcon(reload_icon_path), "Reload");
|
||||
m_reload_action->setShortcut(QKeySequence("Ctrl+R"));
|
||||
|
||||
m_toolbar->addAction(m_back_action);
|
||||
m_toolbar->addAction(m_forward_action);
|
||||
m_toolbar->addAction(m_reload_action);
|
||||
m_toolbar->addAction(m_home_action);
|
||||
m_toolbar->addWidget(m_location_edit);
|
||||
|
||||
QObject::connect(m_view, &WebView::linkHovered, m_window->statusBar(), &QStatusBar::showMessage);
|
||||
QObject::connect(m_view, &WebView::linkUnhovered, m_window->statusBar(), &QStatusBar::clearMessage);
|
||||
|
||||
QObject::connect(m_view, &WebView::loadStarted, m_location_edit, &QLineEdit::setText);
|
||||
QObject::connect(m_view, &WebView::loadStarted, [this](const URL& url) {
|
||||
m_location_edit->setText(url.to_string().characters());
|
||||
m_history.push(url, m_title.toUtf8().data());
|
||||
});
|
||||
QObject::connect(m_location_edit, &QLineEdit::returnPressed, this, &Tab::location_edit_return_pressed);
|
||||
QObject::connect(m_view, &WebView::title_changed, this, &Tab::page_title_changed);
|
||||
QObject::connect(m_view, &WebView::favicon_changed, this, &Tab::page_favicon_changed);
|
||||
|
||||
QObject::connect(reload_action, &QAction::triggered, this, &Tab::reload);
|
||||
QObject::connect(m_back_action, &QAction::triggered, this, &Tab::back);
|
||||
QObject::connect(m_forward_action, &QAction::triggered, this, &Tab::forward);
|
||||
QObject::connect(m_home_action, &QAction::triggered, this, &Tab::home);
|
||||
QObject::connect(m_reload_action, &QAction::triggered, this, &Tab::reload);
|
||||
}
|
||||
|
||||
void Tab::navigate(QString const& url)
|
||||
{
|
||||
view().load(url.toUtf8().data());
|
||||
}
|
||||
|
||||
void Tab::back()
|
||||
{
|
||||
if (!m_history.can_go_back())
|
||||
return;
|
||||
|
||||
m_history.go_back();
|
||||
view().load(m_history.current().url.to_string());
|
||||
}
|
||||
|
||||
void Tab::forward()
|
||||
{
|
||||
if (!m_history.can_go_forward())
|
||||
return;
|
||||
|
||||
m_history.go_forward();
|
||||
view().load(m_history.current().url.to_string());
|
||||
}
|
||||
|
||||
void Tab::home()
|
||||
{
|
||||
navigate("https://www.serenityos.org/");
|
||||
}
|
||||
|
||||
void Tab::reload()
|
||||
|
@ -50,11 +96,12 @@ void Tab::reload()
|
|||
|
||||
void Tab::location_edit_return_pressed()
|
||||
{
|
||||
view().load(m_location_edit->text().toUtf8().data());
|
||||
navigate(m_location_edit->text());
|
||||
}
|
||||
|
||||
void Tab::page_title_changed(QString title)
|
||||
{
|
||||
m_title = title;
|
||||
emit title_changed(tab_index(), std::move(title));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue