From 2c7d36b4aa53ffa638a7aa7046767f10e7a152bf Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Fri, 25 Jul 2025 18:56:49 +0530 Subject: Expose decorations enable/disable lua api --- src/widgets/BrowserWindow.hpp | 1 + src/widgets/Decorations.cpp | 25 ++++++++++++++++++++++++- src/widgets/Decorations.hpp | 12 ++++++++++++ src/widgets/EdgeDecoration.cpp | 18 +++++++++--------- src/widgets/EdgeDecoration.hpp | 7 ++++--- 5 files changed, 50 insertions(+), 13 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp index 7dc6ee4..98686fd 100644 --- a/src/widgets/BrowserWindow.hpp +++ b/src/widgets/BrowserWindow.hpp @@ -31,6 +31,7 @@ public: DELEGATE(webview_stack, scroll, scroll) DELEGATE(webview_stack, scroll_to_top, scroll_to_top) DELEGATE(webview_stack, scroll_to_bottom, scroll_to_bottom) + DELEGATE(decorations, set_enabled, set_decoration_enabled) bool on_window_key_event(QKeyEvent *event); diff --git a/src/widgets/Decorations.cpp b/src/widgets/Decorations.cpp index 659f972..d559776 100644 --- a/src/widgets/Decorations.cpp +++ b/src/widgets/Decorations.cpp @@ -1,10 +1,12 @@ #include #include +#include #include #include #include #include "Decorations.hpp" +#include "widgets/EdgeDecoration.hpp" Decorations::Decorations(QWidget *content_widget, QWebEngineProfile *profile, QWidget *parent) : QWidget(parent) { @@ -20,7 +22,7 @@ Decorations::Decorations(QWidget *content_widget, QWebEngineProfile *profile, QW )HTML"; decoration_bottom->set_html(content); - decoration_bottom->set_enabled(true); + // decoration_bottom->set_enabled(true); auto *vbox = new QVBoxLayout(); vbox->setContentsMargins(0, 0, 0, 0); @@ -41,3 +43,24 @@ Decorations::Decorations(QWidget *content_widget, QWebEngineProfile *profile, QW hbox->addWidget(content_widget); hbox->addWidget(decoration_right); } + +void Decorations::set_enabled(DecorationType type, bool enabled) { + std::optional decoration = get_decoration_widget(type); + + if (decoration.has_value()) + decoration.value()->set_enabled(enabled); +} + +std::optional Decorations::get_decoration_widget(DecorationType type) { + switch (type) { + case DecorationType::DecorationTop: + return decoration_top; + case DecorationType::DecorationBottom: + return decoration_bottom; + case DecorationType::DecorationLeft: + return decoration_left; + case DecorationType::DecorationRight: + return decoration_right; + } + return nullptr; +} diff --git a/src/widgets/Decorations.hpp b/src/widgets/Decorations.hpp index e35e83c..d58ee7f 100644 --- a/src/widgets/Decorations.hpp +++ b/src/widgets/Decorations.hpp @@ -3,17 +3,29 @@ #include "widgets/EdgeDecoration.hpp" #include #include +#include #include +enum DecorationType : uint8_t { + DecorationTop = 1, + DecorationBottom = 2, + DecorationLeft = 3, + DecorationRight = 4, +}; + class Decorations : public QWidget { Q_OBJECT public: Decorations(QWidget *content_widget, QWebEngineProfile *profile, QWidget *parent = nullptr); + void set_enabled(DecorationType type, bool enabled); + private: EdgeDecoration *decoration_top; EdgeDecoration *decoration_bottom; EdgeDecoration *decoration_left; EdgeDecoration *decoration_right; + + std::optional get_decoration_widget(DecorationType type); }; diff --git a/src/widgets/EdgeDecoration.cpp b/src/widgets/EdgeDecoration.cpp index 58db639..4cbb004 100644 --- a/src/widgets/EdgeDecoration.cpp +++ b/src/widgets/EdgeDecoration.cpp @@ -47,21 +47,21 @@ void EdgeDecoration::set_enabled(bool enabled_value) { void EdgeDecoration::setup_webview() { if (enabled) { - if (webview == nullptr) { + if (!webview.has_value()) { webview = new WebView(WebViewStack::next_webview_id++, profile, this); - layout()->addWidget(webview); + layout()->addWidget(webview.value()); } - webview->setHtml(default_html_layout.replace("{{body}}", html_content)); + webview.value()->setHtml(default_html_layout.replace("{{body}}", html_content)); if (vertical) - setFixedWidth(size); + webview.value()->setFixedWidth(size); else - setFixedHeight(size); + webview.value()->setFixedHeight(size); } else { - if (webview != nullptr) { - layout()->removeWidget(webview); - webview->deleteLater(); - webview = nullptr; + if (webview.has_value()) { + layout()->removeWidget(webview.value()); + webview.value()->deleteLater(); + webview = std::nullopt; } } } diff --git a/src/widgets/EdgeDecoration.hpp b/src/widgets/EdgeDecoration.hpp index c83227a..59390dc 100644 --- a/src/widgets/EdgeDecoration.hpp +++ b/src/widgets/EdgeDecoration.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -20,10 +21,10 @@ public: private: bool vertical; - WebView *webview = nullptr; + std::optional webview = std::nullopt; QWebEngineProfile *profile; - bool enabled; - QString html_content; + bool enabled = false; + QString html_content = ""; uint16_t size = 24; void setup_webview(); -- cgit v1.3.1