mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Ladybird: Add a location bar and allow navigating to new pages :^)
This commit is contained in:
parent
88d256c109
commit
8b7000e151
Notes:
sideshowbarker
2024-07-17 02:50:19 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8b7000e151 Pull-request: https://github.com/SerenityOS/serenity/pull/16583 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg
7 changed files with 60 additions and 18 deletions
7
Ladybird/.gitignore
vendored
7
Ladybird/.gitignore
vendored
|
@ -1,8 +1,5 @@
|
|||
.qmake.stash
|
||||
Makefile
|
||||
WebView.o
|
||||
ladybird
|
||||
main.o
|
||||
moc_WebView.cpp
|
||||
moc_WebView.o
|
||||
moc_predefs.h
|
||||
*.o
|
||||
moc_*
|
||||
|
|
27
Ladybird/BrowserWindow.cpp
Normal file
27
Ladybird/BrowserWindow.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "BrowserWindow.h"
|
||||
#include "WebView.h"
|
||||
#include <QStatusBar>
|
||||
|
||||
BrowserWindow::BrowserWindow()
|
||||
{
|
||||
m_toolbar = new QToolBar;
|
||||
m_toolbar->setFixedHeight(28);
|
||||
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);
|
||||
}
|
||||
|
||||
void BrowserWindow::location_edit_return_pressed()
|
||||
{
|
||||
view().load(m_location_edit->text().toUtf8().data());
|
||||
}
|
23
Ladybird/BrowserWindow.h
Normal file
23
Ladybird/BrowserWindow.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <QLineEdit>
|
||||
#include <QMainWindow>
|
||||
#include <QToolBar>
|
||||
|
||||
#pragma once
|
||||
|
||||
class WebView;
|
||||
|
||||
class BrowserWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
BrowserWindow();
|
||||
|
||||
WebView& view() { return *m_view; }
|
||||
|
||||
public slots:
|
||||
void location_edit_return_pressed();
|
||||
|
||||
private:
|
||||
QToolBar* m_toolbar { nullptr };
|
||||
QLineEdit* m_location_edit { nullptr };
|
||||
WebView* m_view { nullptr };
|
||||
};
|
|
@ -138,8 +138,9 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual void page_did_start_loading(AK::URL const&) override
|
||||
virtual void page_did_start_loading(AK::URL const& url) override
|
||||
{
|
||||
emit m_view.loadStarted(url.to_string().characters());
|
||||
}
|
||||
|
||||
virtual void page_did_finish_loading(AK::URL const&) override
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
signals:
|
||||
void linkHovered(QString, int timeout = 0);
|
||||
void linkUnhovered();
|
||||
void loadStarted(QString);
|
||||
|
||||
private:
|
||||
OwnPtr<HeadlessBrowserPageClient> m_page_client;
|
||||
|
|
|
@ -20,8 +20,8 @@ INCLUDEPATH += \
|
|||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
# Input
|
||||
HEADERS += WebView.h
|
||||
SOURCES += main.cpp WebView.cpp
|
||||
HEADERS += WebView.h BrowserWindow.h
|
||||
SOURCES += main.cpp WebView.cpp BrowserWindow.cpp
|
||||
|
||||
QMAKE_LIBDIR += /home/kling/src/serenity/Build/lagom/
|
||||
|
||||
|
|
|
@ -4,14 +4,13 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "BrowserWindow.h"
|
||||
#include "WebView.h"
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QStatusBar>
|
||||
#include <QWidget>
|
||||
|
||||
extern void initialize_web_engine();
|
||||
|
@ -29,24 +28,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
Core::EventLoop event_loop;
|
||||
|
||||
QApplication app(arguments.argc, arguments.argv);
|
||||
QMainWindow window;
|
||||
BrowserWindow window;
|
||||
window.setWindowTitle("Ladybird");
|
||||
window.resize(800, 600);
|
||||
window.show();
|
||||
|
||||
WebView view;
|
||||
window.setCentralWidget(&view);
|
||||
|
||||
QObject::connect(&view, &WebView::linkHovered, window.statusBar(), &QStatusBar::showMessage);
|
||||
QObject::connect(&view, &WebView::linkUnhovered, window.statusBar(), &QStatusBar::clearMessage);
|
||||
|
||||
auto qt_event_loop_driver = Core::Timer::create_repeating(50, [&] {
|
||||
app.processEvents();
|
||||
});
|
||||
qt_event_loop_driver->start();
|
||||
|
||||
if (!url.is_empty()) {
|
||||
view.load(url);
|
||||
window.view().load(url);
|
||||
}
|
||||
|
||||
return event_loop.exec();
|
||||
|
|
Loading…
Reference in a new issue