diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-09 19:47:50 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-09 19:47:50 +0530 |
| commit | 61f99089288138989cf244d174882aa5088b738b (patch) | |
| tree | ea1202b098b92e85b16e670d1c3ea1b86fcaef58 /include/widgets | |
| parent | 1e2302be2b47fbeb340db7482ed8476c829a7f66 (diff) | |
| download | null-browser-61f99089288138989cf244d174882aa5088b738b.tar.gz null-browser-61f99089288138989cf244d174882aa5088b738b.zip | |
Refactor directory structure
Diffstat (limited to 'include/widgets')
| -rw-r--r-- | include/widgets/BrowserManager.hpp | 39 | ||||
| -rw-r--r-- | include/widgets/CommandInput.hpp | 28 | ||||
| -rw-r--r-- | include/widgets/MainWindow.hpp | 24 |
3 files changed, 91 insertions, 0 deletions
diff --git a/include/widgets/BrowserManager.hpp b/include/widgets/BrowserManager.hpp new file mode 100644 index 0000000..84d6f6a --- /dev/null +++ b/include/widgets/BrowserManager.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include <QStackedLayout> +#include <QWebEngineProfile> +#include <QWebEngineView> +#include <sys/types.h> + +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); + + std::vector<QUrl> 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<QWebEngineView *> webViewList; +}; diff --git a/include/widgets/CommandInput.hpp b/include/widgets/CommandInput.hpp new file mode 100644 index 0000000..a6ca0ed --- /dev/null +++ b/include/widgets/CommandInput.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include <QBoxLayout> +#include <QKeyEvent> +#include <QLineEdit> + +class CommandInput : public QWidget { + Q_OBJECT + +public: + CommandInput(QString defaultInput = "", QWidget *parentNode = nullptr); + void setInputFocus(bool focussed); + bool isInputFocussed(); + QString getInputCommand(); + void setInputText(QString text); + +signals: + void submitted(QString command); + void cancelled(); + +protected: + void keyPressEvent(QKeyEvent *event) override; + void emitSubmit(); + +private: + QBoxLayout *layout; + QLineEdit *input; +}; diff --git a/include/widgets/MainWindow.hpp b/include/widgets/MainWindow.hpp new file mode 100644 index 0000000..8ba0ed9 --- /dev/null +++ b/include/widgets/MainWindow.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <QMainWindow> +#include <QObject> +#include <QWebEngineView> + +#include "widgets/BrowserManager.hpp" +#include "widgets/CommandInput.hpp" + +class MainWindow : public QMainWindow { +public: + MainWindow(); + +protected: + void keyPressEvent(QKeyEvent *event) override; + void toggleURLInput(); + void evaluateCommand(QString command); + void hideURLInput(); + void showURLInput(); + +private: + BrowserManager *browserManager; + CommandInput *commandInput; +}; |
