From 35d8464f8975ab35c1e2f1a076302d9f95bfb22c Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Tue, 11 Mar 2025 23:02:44 +0530 Subject: Refactor browsermanager to webviewstack --- include/widgets/BrowserManager.hpp | 44 ----------------------------------- include/widgets/MainWindow.hpp | 8 ++++--- include/widgets/WebViewStack.hpp | 47 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 47 deletions(-) delete mode 100644 include/widgets/BrowserManager.hpp create mode 100644 include/widgets/WebViewStack.hpp (limited to 'include/widgets') diff --git a/include/widgets/BrowserManager.hpp b/include/widgets/BrowserManager.hpp deleted file mode 100644 index 8cf265d..0000000 --- a/include/widgets/BrowserManager.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -enum OpenType { OpenUrl, OpenUrlInTab, OpenUrlInBgTab, OpenUrlInWindow }; - -class BrowserManager : public QWidget { - Q_OBJECT - -public: - inline static const QUrl NewtabURL = QUrl("about:blank"); - -public: - BrowserManager(QWebEngineProfile *profile = new QWebEngineProfile); - - QUrl currentUrl(); - void setCurrentUrl(QUrl url); - - QWebEngineView *createNewWebView(QUrl url = BrowserManager::NewtabURL, - bool focus = false); - - void openUrl(QUrl url = BrowserManager::NewtabURL, - OpenType openType = OpenType::OpenUrl); - - std::vector webViewUrls(); - u_int32_t currentWebViewIndex(); - u_int32_t webViewCount(); - void focusWebView(long index); - void nextWebView(); - void previousWebView(); - - void closeWebView(long index); - void closeCurrentWebView(); - - void onNewWebViewRequest(QWebEngineNewWindowRequest &request); - -private: - QWebEngineProfile *profile; - QStackedLayout *layout; - QList webViewList; -}; diff --git a/include/widgets/MainWindow.hpp b/include/widgets/MainWindow.hpp index 4731fe4..99a3895 100644 --- a/include/widgets/MainWindow.hpp +++ b/include/widgets/MainWindow.hpp @@ -6,8 +6,8 @@ #include #include "LuaRuntime.hpp" -#include "widgets/BrowserManager.hpp" #include "widgets/InputLine.hpp" +#include "widgets/WebViewStack.hpp" class EvaluationType { public: @@ -20,10 +20,12 @@ class MainWindow : public QMainWindow { public: MainWindow(); -protected: +private: void keyPressEvent(QKeyEvent *event) override; void onInputSubmit(QString input); + void evaluateCommand(QString command); + void hideInputLine(); void showInputLine(); void showURLInput(QString url, OpenType openType); @@ -32,7 +34,7 @@ protected: void setEvaluationType(EvaluationType *); private: - BrowserManager *browserManager; + WebViewStack *webViewStack; InputLine *inputLine; LuaRuntime *luaRuntime; QStackedLayout *layout; 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 +#include +#include +#include + +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 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 webViewList; +}; -- cgit v1.3.1