aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/BrowserWindow.hpp1
-rw-r--r--src/widgets/Decorations.cpp25
-rw-r--r--src/widgets/Decorations.hpp12
-rw-r--r--src/widgets/EdgeDecoration.cpp18
-rw-r--r--src/widgets/EdgeDecoration.hpp7
5 files changed, 50 insertions, 13 deletions
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();