diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-07-25 17:03:32 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-07-25 17:03:32 +0530 |
| commit | 51be15cd7c9f39276f27d416356744041e62c22c (patch) | |
| tree | 0ba09371265f4b3d9923b60308d9aecce8c37e20 /src | |
| parent | 7e3b6182c4581fcb39ab1d0ef2eb07fe9fa1d8b6 (diff) | |
| download | null-browser-51be15cd7c9f39276f27d416356744041e62c22c.tar.gz null-browser-51be15cd7c9f39276f27d416356744041e62c22c.zip | |
Add edge decoration widgets
Diffstat (limited to '')
| -rw-r--r-- | src/WindowActionRouter.cpp | 3 | ||||
| -rw-r--r-- | src/widgets/BrowserApp.cpp | 3 | ||||
| -rw-r--r-- | src/widgets/BrowserWindow.cpp | 7 | ||||
| -rw-r--r-- | src/widgets/BrowserWindow.hpp | 2 | ||||
| -rw-r--r-- | src/widgets/Decorations.cpp | 43 | ||||
| -rw-r--r-- | src/widgets/Decorations.hpp | 19 | ||||
| -rw-r--r-- | src/widgets/EdgeDecoration.cpp | 67 | ||||
| -rw-r--r-- | src/widgets/EdgeDecoration.hpp | 30 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 5 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.hpp | 2 |
10 files changed, 175 insertions, 6 deletions
diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp index 3e8d99e..1c68a35 100644 --- a/src/WindowActionRouter.cpp +++ b/src/WindowActionRouter.cpp @@ -3,11 +3,12 @@ #include <unordered_map> #include "LuaRuntime.hpp" -#include "WindowActionRouter.hpp" #include "keymap/KeymapEvaluator.hpp" #include "widgets/BrowserWindow.hpp" #include "widgets/WebViewStack.hpp" +#include "WindowActionRouter.hpp" + QVariant WindowActionRouter::fetch_config_value(const QString &key) { return configuration->get_config(key); } diff --git a/src/widgets/BrowserApp.cpp b/src/widgets/BrowserApp.cpp index 9326d45..49054b8 100644 --- a/src/widgets/BrowserApp.cpp +++ b/src/widgets/BrowserApp.cpp @@ -6,9 +6,10 @@ #include "LuaRuntime.hpp" #include "WindowActionRouter.hpp" #include "events/NotificationReceivedEvent.hpp" -#include "widgets/BrowserApp.hpp" #include "widgets/BrowserWindow.hpp" +#include "widgets/BrowserApp.hpp" + BrowserApp::BrowserApp(Configuration &configuration) : configuration(configuration) { auto &lua = LuaRuntime::instance(); lua.start_event_loop(); diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp index c565cb9..fe2285b 100644 --- a/src/widgets/BrowserWindow.cpp +++ b/src/widgets/BrowserWindow.cpp @@ -7,9 +7,11 @@ #include "Configuration.hpp" #include "keymap/KeymapEvaluator.hpp" -#include "widgets/BrowserWindow.hpp" +#include "widgets/Decorations.hpp" #include "widgets/WebViewStack.hpp" +#include "widgets/BrowserWindow.hpp" + BrowserWindow::BrowserWindow(const Configuration &configuration, QWebEngineProfile *profile, const QStringList &urls) : QMainWindow(nullptr), configuration(configuration) { @@ -23,7 +25,8 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, QWebEngineProfi // Stack of web views webview_stack = new WebViewStack(&configuration, profile, this); - layout->addWidget(webview_stack); + decorations = new Decorations(webview_stack, profile, this); + layout->addWidget(decorations); // Open webviews for given urls if (urls.isEmpty()) { diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp index 6c49006..7dc6ee4 100644 --- a/src/widgets/BrowserWindow.hpp +++ b/src/widgets/BrowserWindow.hpp @@ -4,6 +4,7 @@ #include "Configuration.hpp" #include "utils.hpp" +#include "widgets/Decorations.hpp" #include "widgets/WebViewStack.hpp" using WindowId = qsizetype; @@ -47,6 +48,7 @@ signals: private: const Configuration &configuration; WebViewStack *webview_stack; + Decorations *decorations; WindowId win_id = -1; }; diff --git a/src/widgets/Decorations.cpp b/src/widgets/Decorations.cpp new file mode 100644 index 0000000..659f972 --- /dev/null +++ b/src/widgets/Decorations.cpp @@ -0,0 +1,43 @@ +#include <QWidget> +#include <QtCore> +#include <qboxlayout.h> +#include <qlabel.h> +#include <qwidget.h> + +#include "Decorations.hpp" + +Decorations::Decorations(QWidget *content_widget, QWebEngineProfile *profile, QWidget *parent) + : QWidget(parent) { + decoration_top = new EdgeDecoration(false, profile, this); + decoration_bottom = new EdgeDecoration(false, profile, this); + decoration_left = new EdgeDecoration(true, profile, this); + decoration_right = new EdgeDecoration(true, profile, this); + + QString content = R"HTML( + <div> + Hello world testing testing + <button>Btn 1</button><button>Btn 2</button> + </div> + )HTML"; + decoration_bottom->set_html(content); + decoration_bottom->set_enabled(true); + + auto *vbox = new QVBoxLayout(); + vbox->setContentsMargins(0, 0, 0, 0); + vbox->setSpacing(0); + setLayout(vbox); + + auto *container = new QWidget(this); + auto *hbox = new QHBoxLayout(); + hbox->setContentsMargins(0, 0, 0, 0); + hbox->setSpacing(0); + container->setLayout(hbox); + + vbox->addWidget(decoration_top); + vbox->addWidget(container); + vbox->addWidget(decoration_bottom); + + hbox->addWidget(decoration_left); + hbox->addWidget(content_widget); + hbox->addWidget(decoration_right); +} diff --git a/src/widgets/Decorations.hpp b/src/widgets/Decorations.hpp new file mode 100644 index 0000000..e35e83c --- /dev/null +++ b/src/widgets/Decorations.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "widgets/EdgeDecoration.hpp" +#include <QWidget> +#include <QtCore> +#include <qwebengineprofile.h> + +class Decorations : public QWidget { + Q_OBJECT + +public: + Decorations(QWidget *content_widget, QWebEngineProfile *profile, QWidget *parent = nullptr); + +private: + EdgeDecoration *decoration_top; + EdgeDecoration *decoration_bottom; + EdgeDecoration *decoration_left; + EdgeDecoration *decoration_right; +}; diff --git a/src/widgets/EdgeDecoration.cpp b/src/widgets/EdgeDecoration.cpp new file mode 100644 index 0000000..58db639 --- /dev/null +++ b/src/widgets/EdgeDecoration.cpp @@ -0,0 +1,67 @@ +#include <QWidget> +#include <QtCore> +#include <qboxlayout.h> +#include <qlabel.h> +#include <qwebengineview.h> + +#include "widgets/WebView.hpp" +#include "widgets/WebViewStack.hpp" + +#include "widgets/EdgeDecoration.hpp" + +QString default_html_layout = R"HTML( + {{body}} + <style> + :where(html, body) { + margin: 0; + padding: 0; + background: black; + color: white; + overflow: hidden; + } + </style> +)HTML"; + +EdgeDecoration::EdgeDecoration(bool vertical, QWebEngineProfile *profile, QWidget *parent) + : QWidget(parent), vertical(vertical), profile(profile) { + auto *vbox = new QVBoxLayout(); + vbox->setContentsMargins(0, 0, 0, 0); + vbox->setSpacing(0); + setLayout(vbox); +} + +void EdgeDecoration::set_html(const QString &content) { + html_content = content; + setup_webview(); +} + +void EdgeDecoration::set_size(u_int16_t size_value) { + size = size_value; + setup_webview(); +} + +void EdgeDecoration::set_enabled(bool enabled_value) { + enabled = enabled_value; + setup_webview(); +} + +void EdgeDecoration::setup_webview() { + if (enabled) { + if (webview == nullptr) { + webview = new WebView(WebViewStack::next_webview_id++, profile, this); + layout()->addWidget(webview); + } + + webview->setHtml(default_html_layout.replace("{{body}}", html_content)); + if (vertical) + setFixedWidth(size); + else + setFixedHeight(size); + } else { + if (webview != nullptr) { + layout()->removeWidget(webview); + webview->deleteLater(); + webview = nullptr; + } + } +} diff --git a/src/widgets/EdgeDecoration.hpp b/src/widgets/EdgeDecoration.hpp new file mode 100644 index 0000000..c83227a --- /dev/null +++ b/src/widgets/EdgeDecoration.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include <QWidget> +#include <QtCore> +#include <cstdint> +#include <qwebengineprofile.h> +#include <qwebengineview.h> + +#include "widgets/WebView.hpp" + +class EdgeDecoration : public QWidget { + Q_OBJECT + +public: + EdgeDecoration(bool vertical, QWebEngineProfile *profile, QWidget *parent = nullptr); + + void set_size(uint16_t size_value); + void set_html(const QString &content); + void set_enabled(bool enabled_value); + +private: + bool vertical; + WebView *webview = nullptr; + QWebEngineProfile *profile; + bool enabled; + QString html_content; + uint16_t size = 24; + + void setup_webview(); +}; diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 6bbd5b5..45d9c88 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -12,9 +12,10 @@ #include "WindowActionRouter.hpp" #include "events/PermissionRequestedEvent.hpp" #include "events/UrlChangedEvent.hpp" + #include "widgets/WebViewStack.hpp" -static WebViewId next_webview_id = 1; +WebViewId WebViewStack::next_webview_id = 1; WebViewStack::WebViewStack(const Configuration *configuration, QWebEngineProfile *profile, QWidget *parent) @@ -46,7 +47,7 @@ void WebViewStack::open_url(const QUrl &url, OpenType open_type, WebViewId webvi } WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) { - auto *webview = new WebView(next_webview_id++, profile); + auto *webview = new WebView(WebViewStack::next_webview_id++, profile); webview->setUrl(url); layout->addWidget(webview); webview_list.append(webview); diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp index cee0593..a5c4d4c 100644 --- a/src/widgets/WebViewStack.hpp +++ b/src/widgets/WebViewStack.hpp @@ -28,6 +28,8 @@ class WebViewStack : public QWidget { Q_OBJECT public: + static WebViewId next_webview_id; + WebViewStack(const Configuration *configuration, QWebEngineProfile *profile = new QWebEngineProfile, QWidget *parent = nullptr); |
