aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/WebView.cpp16
-rw-r--r--src/widgets/WebView.hpp28
-rw-r--r--src/widgets/WebViewStack.cpp10
-rw-r--r--src/widgets/WebViewStack.hpp1
4 files changed, 55 insertions, 0 deletions
diff --git a/src/widgets/WebView.cpp b/src/widgets/WebView.cpp
index 300f8ae..aead605 100644
--- a/src/widgets/WebView.cpp
+++ b/src/widgets/WebView.cpp
@@ -1,3 +1,4 @@
+#include <QMainWindow>
#include <QWebEngineView>
#include <QtCore>
@@ -5,3 +6,18 @@
WebView::WebView(uint32_t webview_id, QWebEngineProfile *profile, QWidget *parent_node)
: QWebEngineView(profile, parent_node), id(webview_id) {}
+
+void WebView::open_devtools() {
+ if (devtools_window != nullptr)
+ return;
+
+ devtools_window = new DevtoolsWindow(page()->profile());
+ devtools_window->show();
+
+ connect(devtools_window, &DevtoolsWindow::closed, this, [this]() {
+ devtools_window->deleteLater();
+ devtools_window = nullptr;
+ });
+
+ page()->setDevToolsPage(devtools_window->page());
+}
diff --git a/src/widgets/WebView.hpp b/src/widgets/WebView.hpp
index 98dceba..16c039c 100644
--- a/src/widgets/WebView.hpp
+++ b/src/widgets/WebView.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <QMainWindow>
#include <QWebEngineView>
#include <QtCore>
#include <cstdint>
@@ -7,6 +8,29 @@
#include "utils.hpp"
+class DevtoolsWindow : public QMainWindow {
+ Q_OBJECT
+
+public:
+ DevtoolsWindow(QWebEngineProfile *profile, QWidget *parent = nullptr,
+ Qt::WindowFlags flags = Qt::WindowFlags())
+ : QMainWindow(parent, flags) {
+ webengineview = new QWebEngineView(profile, this);
+ this->setCentralWidget(webengineview);
+ }
+
+ DELEGATE(webengineview, page, page)
+
+signals:
+ void closed();
+
+protected:
+ void closeEvent(QCloseEvent * /* event */) override { emit closed(); }
+
+private:
+ QWebEngineView *webengineview;
+};
+
class WebView : public QWebEngineView {
Q_OBJECT
@@ -14,6 +38,10 @@ public:
WebView(uint32_t webview_id, QWebEngineProfile *profile, QWidget *parent_node = nullptr);
DEFINE_GETTER(get_id, id)
+ void open_devtools();
+
private:
uint32_t id;
+
+ DevtoolsWindow *devtools_window = nullptr;
};
diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp
index 16fd3e9..9eef92a 100644
--- a/src/widgets/WebViewStack.cpp
+++ b/src/widgets/WebViewStack.cpp
@@ -199,6 +199,16 @@ void WebViewStack::focus_webview(WebViewId webview_id) {
layout->setCurrentIndex((int)webview_index);
}
+void WebViewStack::open_devtools(WebViewId webview_id) {
+ auto *webview = get_webview(webview_id);
+ if (webview == nullptr) {
+ qDebug() << "Webview does not exist";
+ return;
+ }
+
+ webview->open_devtools();
+}
+
void WebViewStack::set_search_text(const QString &text, WebViewId webview_id, bool forward) {
auto *webview = get_webview(webview_id);
if (webview == nullptr) {
diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp
index e41af43..fb78255 100644
--- a/src/widgets/WebViewStack.hpp
+++ b/src/widgets/WebViewStack.hpp
@@ -66,6 +66,7 @@ public slots:
void close(WebViewId webview_id);
void focus_webview(WebViewId webview_id);
void set_search_text(const QString &text, WebViewId webview_id, bool forward = true);
+ void open_devtools(WebViewId webview_id);
protected slots:
void on_new_webview_request(const QWebEngineNewWindowRequest &request);