aboutsummaryrefslogtreecommitdiff
path: root/include/widgets/WebViewStack.hpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-11 23:02:44 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-12 00:13:47 +0530
commit35d8464f8975ab35c1e2f1a076302d9f95bfb22c (patch)
tree0b4e26e36fb27dd32c0e174e4ef829f1f77c1daf /include/widgets/WebViewStack.hpp
parent0d5b7cb2a8bea5d91c58dd40f80d60bca384b766 (diff)
downloadnull-browser-35d8464f8975ab35c1e2f1a076302d9f95bfb22c.tar.gz
null-browser-35d8464f8975ab35c1e2f1a076302d9f95bfb22c.zip
Refactor browsermanager to webviewstack
Diffstat (limited to 'include/widgets/WebViewStack.hpp')
-rw-r--r--include/widgets/WebViewStack.hpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/include/widgets/WebViewStack.hpp b/include/widgets/WebViewStack.hpp
new file mode 100644
index 0000000..1d10715
--- /dev/null
+++ b/include/widgets/WebViewStack.hpp
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <QStackedLayout>
+#include <QWebEngineProfile>
+#include <QWebEngineView>
+#include <sys/types.h>
+
+enum OpenType { OpenUrl, OpenUrlInTab, OpenUrlInBgTab, OpenUrlInWindow };
+
+class WebViewStack : public QWidget {
+ Q_OBJECT
+
+public:
+ inline static const QUrl NewtabURL = QUrl("about:blank");
+
+public:
+ WebViewStack(QWebEngineProfile *profile = new QWebEngineProfile,
+ QWidget *parent = nullptr);
+
+ void openUrl(QUrl url = WebViewStack::NewtabURL,
+ OpenType openType = OpenType::OpenUrl);
+
+ std::vector<QUrl> urls();
+ u_int32_t currentWebViewIndex();
+ u_int32_t count();
+ QUrl currentUrl();
+
+ void focusWebView(long index);
+ void next();
+ void previous();
+
+ void close(long index);
+ void closeCurrent();
+
+private:
+ void setCurrentUrl(QUrl url);
+ QWebEngineView *createNewWebView(QUrl url = WebViewStack::NewtabURL,
+ bool focus = false);
+
+private slots:
+ void onNewWebViewRequest(QWebEngineNewWindowRequest &request);
+
+private:
+ QWebEngineProfile *profile;
+ QStackedLayout *layout;
+ QList<QWebEngineView *> webViewList;
+};