diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-07-26 00:39:23 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-07-26 00:39:23 +0530 |
| commit | 3f56d76a2b0d528c05ab8d0a38059ca82ba90952 (patch) | |
| tree | daae7849815c122803f8ddd08cbfcb87552eab8a /src/widgets | |
| parent | 031b22e0bb0f1d132731aea3776917731a8ab4ce (diff) | |
| download | null-browser-3f56d76a2b0d528c05ab8d0a38059ca82ba90952.tar.gz null-browser-3f56d76a2b0d528c05ab8d0a38059ca82ba90952.zip | |
Add set_html for views + example use with decorations
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/BrowserWindow.hpp | 7 | ||||
| -rw-r--r-- | src/widgets/Decorations.hpp | 9 | ||||
| -rw-r--r-- | src/widgets/EdgeDecoration.cpp | 12 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 10 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.hpp | 1 |
5 files changed, 33 insertions, 6 deletions
diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp index 207524a..92eafa7 100644 --- a/src/widgets/BrowserWindow.hpp +++ b/src/widgets/BrowserWindow.hpp @@ -46,6 +46,13 @@ public: webview_stack->open_url(url, open_type, webview_id); } + void set_html(const QString &html, WebViewId webview_id) { + if (decorations->has_webview(webview_id)) + decorations->set_html(html, webview_id); + else + webview_stack->set_html(html, webview_id); + } + bool on_window_key_event(QKeyEvent *event); void closeEvent(QCloseEvent * /*event*/) override { emit closed(); }; diff --git a/src/widgets/Decorations.hpp b/src/widgets/Decorations.hpp index 57fc526..8eac419 100644 --- a/src/widgets/Decorations.hpp +++ b/src/widgets/Decorations.hpp @@ -44,6 +44,15 @@ public: } } + void set_html(const QString &html, WebViewId view_id) { + for (auto *decoration : decorations()) { + if (decoration->get_view_id() == view_id) { + decoration->set_html(html); + return; + } + } + } + private: EdgeDecoration *decoration_top; EdgeDecoration *decoration_bottom; diff --git a/src/widgets/EdgeDecoration.cpp b/src/widgets/EdgeDecoration.cpp index 4cbb004..8880294 100644 --- a/src/widgets/EdgeDecoration.cpp +++ b/src/widgets/EdgeDecoration.cpp @@ -15,7 +15,7 @@ QString default_html_layout = R"HTML( :where(html, body) { margin: 0; padding: 0; - background: black; + background: #333; color: white; overflow: hidden; } @@ -30,8 +30,8 @@ EdgeDecoration::EdgeDecoration(bool vertical, QWebEngineProfile *profile, QWidge setLayout(vbox); } -void EdgeDecoration::set_html(const QString &content) { - html_content = content; +void EdgeDecoration::set_enabled(bool enabled_value) { + enabled = enabled_value; setup_webview(); } @@ -40,8 +40,8 @@ void EdgeDecoration::set_size(u_int16_t size_value) { setup_webview(); } -void EdgeDecoration::set_enabled(bool enabled_value) { - enabled = enabled_value; +void EdgeDecoration::set_html(const QString &content) { + html_content = content; setup_webview(); } @@ -52,7 +52,7 @@ void EdgeDecoration::setup_webview() { layout()->addWidget(webview.value()); } - webview.value()->setHtml(default_html_layout.replace("{{body}}", html_content)); + webview.value()->setHtml(QString(default_html_layout).replace("{{body}}", html_content)); if (vertical) webview.value()->setFixedWidth(size); else diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 45d9c88..698cb88 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -318,3 +318,13 @@ void WebViewStack::scroll_to_bottom(WebViewId webview_id) { webview->scroll_to_bottom(); } + +void WebViewStack::set_html(const QString &html, WebViewId webview_id) { + auto *webview = get_webview(webview_id); + if (webview == nullptr) { + qDebug() << "Webview does not exist"; + return; + } + + webview->setHtml(html); +} diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp index a5c4d4c..3da96aa 100644 --- a/src/widgets/WebViewStack.hpp +++ b/src/widgets/WebViewStack.hpp @@ -72,6 +72,7 @@ public slots: void scroll(WebViewId webview_id, int deltax, int deltay); void scroll_to_top(WebViewId webview_id); void scroll_to_bottom(WebViewId webview_id); + void set_html(const QString &html, WebViewId webview_id = 0); protected slots: void on_new_webview_request(QWebEngineNewWindowRequest &request); |
