blob: 0ec2a748475ce2d44757d8348b73a7e3245d4b70 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include <QMainWindow>
#include <QWebEngineView>
#include <QtCore>
#include "widgets/WebView.hpp"
WebView::WebView(uint32_t webview_id, QWebEngineProfile *profile, QWidget *parent_node)
: QWebEngineView(profile, parent_node), id(webview_id) {}
void WebView::open_devtools() {
if (devtools_window != nullptr)
return;
devtools_window = new DevtoolsWindow(page()->profile());
devtools_window->show();
connect(devtools_window, &DevtoolsWindow::closed, this, [this]() {
devtools_window->deleteLater();
devtools_window = nullptr;
});
page()->setDevToolsPage(devtools_window->page());
}
void WebView::scroll_increment(int deltax, int deltay) {
auto code = QString(R"((() => {
const $el = document.scrollingElement;
$el.scrollTo($el.scrollLeft + %1, $el.scrollTop + %2);
})())")
.arg(deltax)
.arg(deltay);
page()->runJavaScript(code);
}
void WebView::scroll_to_top() {
auto code = QString(R"(document.scrollingElement.scrollTo(0, 0))");
page()->runJavaScript(code);
}
void WebView::scroll_to_bottom() {
auto code =
QString(R"(document.scrollingElement.scrollTo(0, document.scrollingElement.scrollHeight))");
page()->runJavaScript(code);
}
|