summaryrefslogtreecommitdiff
path: root/plugins/webengine/webview.cpp
blob: fc2e46420c12904bcf583c03831377baa1951fb0 (plain)
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
46
/* ============================================================
 *     The rekonq project
 * ============================================================
 * SPDX-License-Identifier: GPL-3.0-only
 * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
 * ============================================================
 * Description: Qt WebEngine View
 * ============================================================ */

#include "webview.h"
#include <QVBoxLayout>
#include <QWebEngineView>

WebView::WebView(const QUrl &url, QWidget *parent) : RekonqView(url, parent), view(new QWebEngineView(this))
{
  auto *layout = new QVBoxLayout;
  layout->setContentsMargins(0, 0, 0, 0);
  layout->addWidget(view);
  setLayout(layout);

  connect(view, &QWebEngineView::iconChanged, this, [this](const QIcon &icon) { emit iconChanged(icon); });
  connect(view, &QWebEngineView::urlChanged, this, [this](const QUrl &u) { emit urlChanged(u); });
  connect(view, &QWebEngineView::titleChanged, this, [this](const QString &title) { emit titleChanged(title); });

  // load progress
  connect(view, &QWebEngineView::loadStarted, this, [this]() {
    m_loadProgress = 0;
    emit loadStarted();
  });
  connect(view, &QWebEngineView::loadProgress, this, [this](int progress) {
    m_loadProgress = progress;
    emit loadProgress(progress);
  });
  connect(view, &QWebEngineView::loadFinished, this, [this]() {
    m_loadProgress = 100;
    emit loadFinished();
  });

  view->load(url);
}

void WebView::load(const QUrl &url) { view->load(url); }

QUrl WebView::url() const { return view->url(); }
QString WebView::title() const { return view->title(); }
QIcon WebView::icon() const { return view->icon(); }