diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-07-25 23:17:02 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-07-25 23:17:02 +0530 |
| commit | 031b22e0bb0f1d132731aea3776917731a8ab4ce (patch) | |
| tree | 1c3775d5aba426669a0ea0b8821a7b4b0808aab0 /src/widgets | |
| parent | 81dcf7de91c1866d565f7aa9eb38f7fbd1cd7ad7 (diff) | |
| download | null-browser-031b22e0bb0f1d132731aea3776917731a8ab4ce.tar.gz null-browser-031b22e0bb0f1d132731aea3776917731a8ab4ce.zip | |
Add decorations.*.view lua api + support decoration views for open url
Diffstat (limited to '')
| -rw-r--r-- | src/widgets/BrowserWindow.hpp | 16 | ||||
| -rw-r--r-- | src/widgets/Decorations.cpp | 9 | ||||
| -rw-r--r-- | src/widgets/Decorations.hpp | 30 | ||||
| -rw-r--r-- | src/widgets/EdgeDecoration.hpp | 10 |
4 files changed, 54 insertions, 11 deletions
diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp index 2927683..207524a 100644 --- a/src/widgets/BrowserWindow.hpp +++ b/src/widgets/BrowserWindow.hpp @@ -18,12 +18,12 @@ public: DEFINE_GETTER(get_id, win_id) DEFINE_SETTER(set_id, win_id) - DELEGATE(webview_stack, has_webview, has_webview) + // DELEGATE(webview_stack, has_webview, has_webview) DELEGATE(webview_stack, current_webview_id, current_webview_id) DELEGATE(webview_stack, get_webview_list, get_webview_list) DELEGATE(webview_stack, set_search_text, set_search_text) DELEGATE(webview_stack, open_devtools, open_devtools) - DELEGATE(webview_stack, open_url, open_url) + // DELEGATE(webview_stack, open_url, open_url) DELEGATE(webview_stack, webview_history_back, history_back) DELEGATE(webview_stack, webview_history_forward, history_forward) DELEGATE(webview_stack, close, close_webview) @@ -33,6 +33,18 @@ public: DELEGATE(webview_stack, scroll_to_bottom, scroll_to_bottom) DELEGATE(decorations, set_enabled, set_decoration_enabled) DELEGATE(decorations, get_enabled, get_decoration_enabled) + DELEGATE(decorations, get_view_id, get_decoration_view_id) + + bool has_webview(WebViewId webview_id) { + return webview_stack->has_webview(webview_id) || decorations->has_webview(webview_id); + } + + void open_url(const QUrl &url, OpenType open_type, WebViewId webview_id) { + if (decorations->has_webview(webview_id)) + decorations->open_url(url, webview_id); + else + webview_stack->open_url(url, open_type, webview_id); + } bool on_window_key_event(QKeyEvent *event); diff --git a/src/widgets/Decorations.cpp b/src/widgets/Decorations.cpp index 82c1a65..9df4c23 100644 --- a/src/widgets/Decorations.cpp +++ b/src/widgets/Decorations.cpp @@ -15,15 +15,6 @@ Decorations::Decorations(QWidget *content_widget, QWebEngineProfile *profile, QW 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); diff --git a/src/widgets/Decorations.hpp b/src/widgets/Decorations.hpp index 30df104..57fc526 100644 --- a/src/widgets/Decorations.hpp +++ b/src/widgets/Decorations.hpp @@ -1,6 +1,7 @@ #pragma once #include "widgets/EdgeDecoration.hpp" +#include "widgets/WebViewStack.hpp" #include <QWidget> #include <QtCore> #include <optional> @@ -22,11 +23,40 @@ public: void set_enabled(DecorationType type, bool enabled); bool get_enabled(DecorationType type); + std::optional<WebViewId> get_view_id(DecorationType type) { + auto decoration = get_decoration_widget(type); + return decoration.has_value() ? decoration.value()->get_view_id() : std::nullopt; + } + + bool has_webview(WebViewId view_id) { + for (auto *decoration : decorations()) + if (decoration->get_view_id() == view_id) + return true; + return false; + } + + void open_url(const QUrl &url, WebViewId view_id) { + for (auto *decoration : decorations()) { + if (decoration->get_view_id() == view_id) { + decoration->set_url(url); + return; + } + } + } + private: EdgeDecoration *decoration_top; EdgeDecoration *decoration_bottom; EdgeDecoration *decoration_left; EdgeDecoration *decoration_right; + std::vector<EdgeDecoration *> decorations() { + return { + decoration_top, + decoration_bottom, + decoration_left, + decoration_right, + }; + } std::optional<EdgeDecoration *> get_decoration_widget(DecorationType type); }; diff --git a/src/widgets/EdgeDecoration.hpp b/src/widgets/EdgeDecoration.hpp index 3ee0ab5..f627636 100644 --- a/src/widgets/EdgeDecoration.hpp +++ b/src/widgets/EdgeDecoration.hpp @@ -9,6 +9,7 @@ #include "utils.hpp" #include "widgets/WebView.hpp" +#include "widgets/WebViewStack.hpp" class EdgeDecoration : public QWidget { Q_OBJECT @@ -19,9 +20,18 @@ public: void set_size(uint16_t size_value); void set_html(const QString &content); void set_enabled(bool enabled_value); + void set_url(const QUrl &url) { + if (!webview.has_value()) + return; + webview.value()->setUrl(url); + } DEFINE_GETTER(is_enabled, enabled) + std::optional<WebViewId> get_view_id() { + return webview.has_value() ? std::make_optional(webview.value()->get_id()) : std::nullopt; + } + private: bool vertical; std::optional<WebView *> webview = std::nullopt; |
