diff options
Diffstat (limited to '')
| -rw-r--r-- | src/LuaRuntime.hpp | 4 | ||||
| -rw-r--r-- | src/LuaRuntimeApi.hpp | 12 | ||||
| -rw-r--r-- | src/WindowActionRouter.cpp | 6 | ||||
| -rw-r--r-- | src/widgets/BrowserWindow.hpp | 1 | ||||
| -rw-r--r-- | src/widgets/Decorations.cpp | 25 | ||||
| -rw-r--r-- | src/widgets/Decorations.hpp | 12 | ||||
| -rw-r--r-- | src/widgets/EdgeDecoration.cpp | 18 | ||||
| -rw-r--r-- | src/widgets/EdgeDecoration.hpp | 7 |
8 files changed, 71 insertions, 14 deletions
diff --git a/src/LuaRuntime.hpp b/src/LuaRuntime.hpp index 527501e..58362af 100644 --- a/src/LuaRuntime.hpp +++ b/src/LuaRuntime.hpp @@ -7,6 +7,7 @@ #include "AsyncEventLoop.hpp" #include "lua.h" #include "utils.hpp" +#include "widgets/Decorations.hpp" #include "widgets/WebViewStack.hpp" #ifndef PROJECT_LUA_PATH @@ -46,7 +47,7 @@ signals: void history_back_requested(WebViewId webview_id, qsizetype history_index); void history_forward_requested(WebViewId webview_id, qsizetype history_index); - void keymap_add_requested(QString mode, QString keyseq, std::function<void()>); + void keymap_add_requested(QString mode, QString keyseq, std::function<void()> action); void keymap_mode_update_requested(const QString &mode); void url_opened(QString url, OpenType open_type, WebViewId webview_id); void webview_closed(WebViewId webview_id); @@ -59,6 +60,7 @@ signals: void webview_scroll_requested(WebViewId webview_id, int deltax, int deltay); void webview_scroll_top_requested(WebViewId webview_id); void webview_scroll_bottom_requested(WebViewId webview_id); + void decoration_set_enabled(DecorationType type, bool enabled); protected: LuaRuntime(); diff --git a/src/LuaRuntimeApi.hpp b/src/LuaRuntimeApi.hpp index 5ec72cc..d8e6073 100644 --- a/src/LuaRuntimeApi.hpp +++ b/src/LuaRuntimeApi.hpp @@ -5,6 +5,7 @@ #include "LuaRuntime.hpp" #include "WindowActionRouter.hpp" #include "events/Event.hpp" +#include "widgets/Decorations.hpp" int lua_api_view_set_url(lua_State *state) { const char *url = lua_tostring(state, 1); @@ -265,6 +266,16 @@ int lua_api_view_scroll_bottom(lua_State *state) { return 1; } +int lua_api_decorations_set_enabled(lua_State *state) { + auto type = (DecorationType)lua_tointeger(state, 1); + bool enabled = lua_toboolean(state, 2); + qDebug() << type << enabled; + auto &runtime = LuaRuntime::instance(); + emit runtime.decoration_set_enabled(type, enabled); + lua_pushnil(state); + return 1; +} + // NOLINTNEXTLINE static luaL_Reg internals_api[] = { luaL_Reg{"event_add_listener", &lua_event_register}, @@ -289,5 +300,6 @@ static luaL_Reg internals_api[] = { luaL_Reg{"search_set_text", &lua_api_search_set_text}, luaL_Reg{"search_previous", &lua_api_search_previous}, luaL_Reg{"search_next", &lua_api_search_next}, + luaL_Reg{"decorations_set_enabled", &lua_api_decorations_set_enabled}, luaL_Reg{nullptr, nullptr}, }; diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp index 1c68a35..ba479f0 100644 --- a/src/WindowActionRouter.cpp +++ b/src/WindowActionRouter.cpp @@ -94,6 +94,12 @@ void WindowActionRouter::initialize(Configuration *config) { [this](WebViewId webview_id) { WITH_WEBVIEW_WINDOW(webview_id, window, { window->scroll_to_bottom(webview_id); }); }); + connect(&runtime, &LuaRuntime::decoration_set_enabled, this, + [this](DecorationType type, bool enabled) { + qDebug() << "routing" << type << enabled << window_map.size(); + for (auto &win_match : window_map) + win_match.second->set_decoration_enabled(type, enabled); + }); } void WindowActionRouter::find_current_search_text(WebViewId webview_id, bool forward) { 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 <QWidget> #include <QtCore> +#include <optional> #include <qboxlayout.h> #include <qlabel.h> #include <qwidget.h> #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 </div> )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<EdgeDecoration *> decoration = get_decoration_widget(type); + + if (decoration.has_value()) + decoration.value()->set_enabled(enabled); +} + +std::optional<EdgeDecoration *> 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 <QWidget> #include <QtCore> +#include <optional> #include <qwebengineprofile.h> +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<EdgeDecoration *> 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 <QWidget> #include <QtCore> #include <cstdint> +#include <optional> #include <qwebengineprofile.h> #include <qwebengineview.h> @@ -20,10 +21,10 @@ public: private: bool vertical; - WebView *webview = nullptr; + std::optional<WebView *> webview = std::nullopt; QWebEngineProfile *profile; - bool enabled; - QString html_content; + bool enabled = false; + QString html_content = ""; uint16_t size = 24; void setup_webview(); |
