2022-07-03 19:26:51 +00:00
|
|
|
#include "BrowserWindow.h"
|
|
|
|
#include "WebView.h"
|
2022-07-05 17:42:45 +00:00
|
|
|
#include <LibCore/EventLoop.h>
|
2022-07-05 19:10:50 +00:00
|
|
|
#include <QAction>
|
2022-07-03 19:26:51 +00:00
|
|
|
#include <QStatusBar>
|
|
|
|
|
2022-07-05 19:10:50 +00:00
|
|
|
extern String s_serenity_resource_root;
|
|
|
|
|
2022-07-05 17:42:45 +00:00
|
|
|
BrowserWindow::BrowserWindow(Core::EventLoop& event_loop)
|
|
|
|
: m_event_loop(event_loop)
|
2022-07-03 19:26:51 +00:00
|
|
|
{
|
|
|
|
m_toolbar = new QToolBar;
|
2022-07-05 19:10:50 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2022-07-03 19:26:51 +00:00
|
|
|
m_location_edit = new QLineEdit;
|
|
|
|
m_toolbar->addWidget(m_location_edit);
|
|
|
|
|
|
|
|
addToolBar(m_toolbar);
|
|
|
|
|
|
|
|
m_view = new WebView;
|
|
|
|
setCentralWidget(m_view);
|
|
|
|
|
|
|
|
QObject::connect(m_view, &WebView::linkHovered, statusBar(), &QStatusBar::showMessage);
|
|
|
|
QObject::connect(m_view, &WebView::linkUnhovered, statusBar(), &QStatusBar::clearMessage);
|
|
|
|
|
|
|
|
QObject::connect(m_view, &WebView::loadStarted, m_location_edit, &QLineEdit::setText);
|
|
|
|
QObject::connect(m_location_edit, &QLineEdit::returnPressed, this, &BrowserWindow::location_edit_return_pressed);
|
2022-07-04 00:11:58 +00:00
|
|
|
QObject::connect(m_view, &WebView::title_changed, this, &BrowserWindow::page_title_changed);
|
2022-07-05 04:53:11 +00:00
|
|
|
QObject::connect(m_view, &WebView::favicon_changed, this, &BrowserWindow::page_favicon_changed);
|
2022-07-05 19:10:50 +00:00
|
|
|
|
|
|
|
QObject::connect(reload_action, &QAction::triggered, this, &BrowserWindow::reload);
|
2022-07-03 19:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWindow::location_edit_return_pressed()
|
|
|
|
{
|
|
|
|
view().load(m_location_edit->text().toUtf8().data());
|
|
|
|
}
|
2022-07-04 00:11:58 +00:00
|
|
|
|
|
|
|
void BrowserWindow::page_title_changed(QString title)
|
|
|
|
{
|
|
|
|
if (title.isEmpty())
|
|
|
|
setWindowTitle("Ladybird");
|
|
|
|
else
|
|
|
|
setWindowTitle(QString("%1 - Ladybird").arg(title));
|
|
|
|
}
|
2022-07-05 04:53:11 +00:00
|
|
|
|
|
|
|
void BrowserWindow::page_favicon_changed(QIcon icon)
|
|
|
|
{
|
|
|
|
setWindowIcon(icon);
|
|
|
|
}
|
2022-07-05 17:42:45 +00:00
|
|
|
|
|
|
|
void BrowserWindow::closeEvent(QCloseEvent* event)
|
|
|
|
{
|
|
|
|
QWidget::closeEvent(event);
|
|
|
|
|
|
|
|
// FIXME: Ladybird only supports one window at the moment. When we support
|
|
|
|
// multiple windows, we'll only want to fire off the quit event when
|
|
|
|
// all of the browser windows have closed.
|
|
|
|
m_event_loop.quit(0);
|
|
|
|
}
|
2022-07-05 19:10:50 +00:00
|
|
|
|
|
|
|
void BrowserWindow::reload()
|
|
|
|
{
|
|
|
|
view().reload();
|
|
|
|
}
|