aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/widgets/BrowserApp.cpp7
-rw-r--r--src/widgets/BrowserWindow.cpp27
-rw-r--r--src/widgets/BrowserWindow.hpp3
-rw-r--r--src/widgets/WebView.cpp3
-rw-r--r--src/widgets/WebView.hpp3
-rw-r--r--src/widgets/WebViewStack.cpp44
-rw-r--r--src/widgets/WebViewStack.hpp8
7 files changed, 36 insertions, 59 deletions
diff --git a/src/widgets/BrowserApp.cpp b/src/widgets/BrowserApp.cpp
index 4977a2a..26124d6 100644
--- a/src/widgets/BrowserApp.cpp
+++ b/src/widgets/BrowserApp.cpp
@@ -20,8 +20,8 @@ BrowserApp::BrowserApp() {
// NOTE: TMP
lua.load_file("./config.lua");
- connect(&window_action_router, &WindowActionRouter::new_window_requested,
- this, [this](const QUrl &url) { create_window({url.toString()}); });
+ connect(&window_action_router, &WindowActionRouter::new_window_requested, this,
+ [this](const QUrl &url) { create_window({url.toString()}); });
};
BrowserWindow *BrowserApp::create_window(const QStringList &urls) {
@@ -40,8 +40,7 @@ bool BrowserApp::eventFilter(QObject *target, QEvent *event) {
for (const auto &match : WindowActionRouter::instance().windows()) {
auto *win = match.second;
- if (auto *target_widget = dynamic_cast<QWidget *>(target);
- win->isAncestorOf(target_widget)) {
+ if (auto *target_widget = dynamic_cast<QWidget *>(target); win->isAncestorOf(target_widget)) {
auto *key_event = static_cast<QKeyEvent *>(event);
const bool should_skip = win->on_window_key_event(key_event);
return should_skip;
diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp
index 38392a0..ff05b0e 100644
--- a/src/widgets/BrowserWindow.cpp
+++ b/src/widgets/BrowserWindow.cpp
@@ -10,8 +10,7 @@
#include "widgets/BrowserWindow.hpp"
#include "widgets/WebViewStack.hpp"
-BrowserWindow::BrowserWindow(const Configuration &configuration,
- const QStringList &urls)
+BrowserWindow::BrowserWindow(const Configuration &configuration, const QStringList &urls)
: configuration(configuration) {
setCentralWidget(new QWidget());
@@ -23,8 +22,7 @@ BrowserWindow::BrowserWindow(const Configuration &configuration,
centralWidget()->setLayout(layout);
// Web engine
- auto *web_view_stack =
- new WebViewStack(&configuration, new QWebEngineProfile("null-browser"));
+ auto *web_view_stack = new WebViewStack(&configuration, new QWebEngineProfile("null-browser"));
layout->addWidget(web_view_stack);
auto &keymap_evaluator = KeymapEvaluator::instance();
@@ -36,19 +34,17 @@ BrowserWindow::BrowserWindow(const Configuration &configuration,
keymap_evaluator.add_keymap(KeyMode::Insert, "<esc>", [&keymap_evaluator]() {
keymap_evaluator.set_current_mode(KeyMode::Normal);
});
- keymap_evaluator.add_keymap(KeyMode::Normal, "<c-t>a",
- []() { qDebug() << "Stuff"; });
+ keymap_evaluator.add_keymap(KeyMode::Normal, "<c-t>a", []() { qDebug() << "Stuff"; });
win_mediator = new WindowMediator(web_view_stack);
- connect(web_view_stack, &WebViewStack::current_webview_changed, this,
- [this](int index) {
- auto webviews = win_mediator->get_webview_list();
- if (index >= 0 && index < webviews.count()) {
- const auto &webview = webviews.at(index);
- setWindowTitle(webview.title);
- }
- });
+ connect(web_view_stack, &WebViewStack::current_webview_changed, this, [this](int index) {
+ auto webviews = win_mediator->get_webview_list();
+ if (index >= 0 && index < webviews.count()) {
+ const auto &webview = webviews.at(index);
+ setWindowTitle(webview.title);
+ }
+ });
auto &lua = LuaRuntime::instance();
lua.queue_task([this, urls]() {
@@ -62,8 +58,7 @@ void BrowserWindow::closeEvent(QCloseEvent * /*event*/) { emit closed(); }
bool BrowserWindow::on_window_key_event(QKeyEvent *event) {
auto &keymap_evaluator = KeymapEvaluator::instance();
- const bool should_skip =
- keymap_evaluator.evaluate(event->modifiers(), (Qt::Key)event->key());
+ const bool should_skip = keymap_evaluator.evaluate(event->modifiers(), (Qt::Key)event->key());
return should_skip;
}
diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp
index c83b4b7..e657970 100644
--- a/src/widgets/BrowserWindow.hpp
+++ b/src/widgets/BrowserWindow.hpp
@@ -12,8 +12,7 @@ class BrowserWindow : public QMainWindow {
Q_OBJECT
public:
- BrowserWindow(const Configuration &configuration,
- const QStringList &urls = {});
+ BrowserWindow(const Configuration &configuration, const QStringList &urls = {});
DEFINE_GETTER(mediator, win_mediator)
DEFINE_GETTER(get_id, win_id)
diff --git a/src/widgets/WebView.cpp b/src/widgets/WebView.cpp
index 2ba5c4c..300f8ae 100644
--- a/src/widgets/WebView.cpp
+++ b/src/widgets/WebView.cpp
@@ -3,6 +3,5 @@
#include "widgets/WebView.hpp"
-WebView::WebView(uint32_t webview_id, QWebEngineProfile *profile,
- QWidget *parent_node)
+WebView::WebView(uint32_t webview_id, QWebEngineProfile *profile, QWidget *parent_node)
: QWebEngineView(profile, parent_node), id(webview_id) {}
diff --git a/src/widgets/WebView.hpp b/src/widgets/WebView.hpp
index 0f2aae6..3f73316 100644
--- a/src/widgets/WebView.hpp
+++ b/src/widgets/WebView.hpp
@@ -10,8 +10,7 @@ class WebView : public QWebEngineView {
Q_OBJECT
public:
- WebView(uint32_t webview_id, QWebEngineProfile *profile,
- QWidget *parent_node = nullptr);
+ WebView(uint32_t webview_id, QWebEngineProfile *profile, QWidget *parent_node = nullptr);
DEFINE_GETTER(get_id, id)
private:
diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp
index 9b7af78..5134101 100644
--- a/src/widgets/WebViewStack.cpp
+++ b/src/widgets/WebViewStack.cpp
@@ -4,7 +4,6 @@
#include <QWebEngineProfile>
#include <cstdint>
#include <cstdlib>
-#include <memory>
#include <vector>
#include "WindowActionRouter.hpp"
@@ -13,21 +12,19 @@
static WebViewId next_webview_id = 1;
-WebViewStack::WebViewStack(const Configuration *configuration,
- QWebEngineProfile *profile, QWidget *parent)
+WebViewStack::WebViewStack(const Configuration *configuration, QWebEngineProfile *profile,
+ QWidget *parent)
: QWidget(parent), configuration(configuration), profile(profile) {
layout = new QStackedLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setStackingMode(QStackedLayout::StackOne);
- connect(layout, &QStackedLayout::currentChanged, this,
- &WebViewStack::current_webview_changed);
+ connect(layout, &QStackedLayout::currentChanged, this, &WebViewStack::current_webview_changed);
create_new_webview(configuration->new_tab_url, true);
}
-void WebViewStack::open_url(const QUrl &url, OpenType open_type,
- WebViewId webview_id) {
+void WebViewStack::open_url(const QUrl &url, OpenType open_type, WebViewId webview_id) {
switch (open_type) {
case OpenType::OpenUrl:
set_webview_url(url, webview_id);
@@ -52,12 +49,11 @@ WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) {
connect(webview->page(), &QWebEnginePage::newWindowRequested, this,
&WebViewStack::on_new_webview_request);
- connect(webview->page(), &QWebEnginePage::urlChanged, this,
- [webview](const QUrl &url) {
- // TODO: Add window id
- WindowActionRouter::instance().dispatch_event(
- new UrlChangedEvent(url.toString(), webview->get_id(), 0));
- });
+ connect(webview->page(), &QWebEnginePage::urlChanged, this, [webview](const QUrl &url) {
+ // TODO: Add window id
+ WindowActionRouter::instance().dispatch_event(
+ new UrlChangedEvent(url.toString(), webview->get_id(), 0));
+ });
if (focus)
focus_webview(webview->get_id());
@@ -70,14 +66,12 @@ WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) {
QList<WebViewData> WebViewStack::get_webview_list() {
QList<WebViewData> urls;
for (auto &view : webview_list)
- urls.append(WebViewData{.id = view->get_id(),
- .url = view->url().toString(),
- .title = view->title()});
+ urls.append(
+ WebViewData{.id = view->get_id(), .url = view->url().toString(), .title = view->title()});
return urls;
}
-void WebViewStack::on_new_webview_request(
- const QWebEngineNewWindowRequest &request) {
+void WebViewStack::on_new_webview_request(const QWebEngineNewWindowRequest &request) {
qDebug() << request.destination();
switch (request.destination()) {
case QWebEngineNewWindowRequest::InNewTab:
@@ -135,8 +129,7 @@ void WebViewStack::close(WebViewId webview_id) {
}
}
-void WebViewStack::webview_history_back(WebViewId webview_id,
- qsizetype history_index) {
+void WebViewStack::webview_history_back(WebViewId webview_id, qsizetype history_index) {
auto *webview = get_webview(webview_id);
if (webview == nullptr) {
qDebug() << "Invalid webview id" << webview_id;
@@ -150,8 +143,7 @@ void WebViewStack::webview_history_back(WebViewId webview_id,
history->back();
}
-void WebViewStack::webview_history_forward(WebViewId webview_id,
- qsizetype history_index) {
+void WebViewStack::webview_history_forward(WebViewId webview_id, qsizetype history_index) {
auto *webview = get_webview(webview_id);
if (webview == nullptr) {
qDebug() << "Invalid webview id" << webview_id;
@@ -184,9 +176,7 @@ WebView *WebViewStack::current_webview() {
return webview_list.at(current_webview_index());
}
-uint32_t WebViewStack::current_webview_index() {
- return layout->currentIndex();
-}
+uint32_t WebViewStack::current_webview_index() { return layout->currentIndex(); }
uint32_t WebViewStack::count() { return webview_list.length(); }
@@ -203,9 +193,7 @@ WebView *WebViewStack::get_webview(WebViewId webview_id) {
return webview_list.at(webview_index);
}
-bool WebViewStack::has_webview(WebViewId webview_id) {
- return get_webview(webview_id) != nullptr;
-}
+bool WebViewStack::has_webview(WebViewId webview_id) { return get_webview(webview_id) != nullptr; }
QUrl WebViewStack::current_url() {
auto *webview = current_webview();
diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp
index 67d443f..5d09aaf 100644
--- a/src/widgets/WebViewStack.hpp
+++ b/src/widgets/WebViewStack.hpp
@@ -14,7 +14,7 @@ enum OpenType : uint8_t {
OpenUrl,
OpenUrlInTab,
OpenUrlInBgTab,
- OpenUrlInWindow
+ OpenUrlInWindow,
};
struct WebViewData {
@@ -28,8 +28,7 @@ class WebViewStack : public QWidget {
public:
WebViewStack(const Configuration *configuration,
- QWebEngineProfile *profile = new QWebEngineProfile,
- QWidget *parent = nullptr);
+ QWebEngineProfile *profile = new QWebEngineProfile, QWidget *parent = nullptr);
QList<WebViewData> get_webview_list();
WebView *current_webview();
@@ -56,8 +55,7 @@ protected:
WebView *get_webview(WebViewId webview_id);
public slots:
- void open_url(const QUrl &url, OpenType open_type = OpenType::OpenUrl,
- WebViewId webview_id = 0);
+ void open_url(const QUrl &url, OpenType open_type = OpenType::OpenUrl, WebViewId webview_id = 0);
void webview_history_back(WebViewId webview_id, qsizetype history_index);
void webview_history_forward(WebViewId webview_id, qsizetype history_index);
void close(WebViewId webview_id);