mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
PageThumbnailer: Rewrite to load thumbnails with QML WebEngineView
This way it is possible to get thumbnail even without showing the webview.
This commit is contained in:
parent
50d5eeef0c
commit
1d37a6867c
|
@ -1,7 +1,8 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>data/bookmarks.json</file>
|
||||
<file>data/browsedata.db</file>
|
||||
<file>data/profiles.ini</file>
|
||||
<file>data/bookmarks.json</file>
|
||||
<file>data/thumbnailer.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
15
src/lib/data/data/thumbnailer.qml
Normal file
15
src/lib/data/data/thumbnailer.qml
Normal file
|
@ -0,0 +1,15 @@
|
|||
import QtQuick 2.2
|
||||
import QtWebEngine 1.0
|
||||
|
||||
WebEngineView {
|
||||
width: 1280
|
||||
height: 720
|
||||
|
||||
onLoadingChanged: {
|
||||
if (loadRequest.status == WebEngineView.LoadStartedStatus)
|
||||
return;
|
||||
|
||||
var ok = loadRequest.status == WebEngineView.LoadSucceededStatus;
|
||||
thumbnailer.createThumbnail(ok);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
QT += webenginewidgets webenginewidgets-private webchannel network widgets sql script
|
||||
QT += webenginewidgets webenginewidgets-private webchannel network widgets sql script quickwidgets
|
||||
|
||||
TARGET = QupZilla
|
||||
TEMPLATE = lib
|
||||
|
|
|
@ -19,24 +19,21 @@
|
|||
|
||||
#include <QTimer>
|
||||
#include <QApplication>
|
||||
#include <QWebEngineView>
|
||||
|
||||
#include <QQmlContext>
|
||||
#include <QQuickItem>
|
||||
#include <QQuickWidget>
|
||||
|
||||
PageThumbnailer::PageThumbnailer(QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_view(new QWebEngineView())
|
||||
, m_view(new QQuickWidget())
|
||||
, m_size(QSize(450, 253))
|
||||
, m_loadTitle(false)
|
||||
{
|
||||
// Every page should fit in this resolution
|
||||
m_view->resize(QSize(1280, 720));
|
||||
|
||||
// Well ...
|
||||
QWidget *w = QApplication::activeWindow();
|
||||
m_view->setAttribute(Qt::WA_DontShowOnScreen);
|
||||
m_view->setSource(QUrl(QSL("qrc:data/thumbnailer.qml")));
|
||||
m_view->rootContext()->setContextProperty(QSL("thumbnailer"), this);
|
||||
m_view->show();
|
||||
if (w) {
|
||||
QApplication::setActiveWindow(w);
|
||||
w->activateWindow();
|
||||
}
|
||||
}
|
||||
|
||||
void PageThumbnailer::setSize(const QSize &size)
|
||||
|
@ -79,9 +76,14 @@ QString PageThumbnailer::title()
|
|||
|
||||
void PageThumbnailer::start()
|
||||
{
|
||||
m_view->load(m_url);
|
||||
|
||||
connect(m_view, &QWebEngineView::loadFinished, this, &PageThumbnailer::createThumbnail);
|
||||
if (m_view->rootObject()) {
|
||||
m_view->rootObject()->setProperty("url", m_url);
|
||||
}
|
||||
else {
|
||||
QTimer::singleShot(0, this, [this]() {
|
||||
emit thumbnailCreated(QPixmap());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void PageThumbnailer::createThumbnail(bool status)
|
||||
|
@ -92,8 +94,8 @@ void PageThumbnailer::createThumbnail(bool status)
|
|||
}
|
||||
|
||||
QTimer::singleShot(1000, this, [this]() {
|
||||
m_title = m_view->title().trimmed();
|
||||
emit thumbnailCreated(m_view->grab().scaled(m_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
m_title = m_view->rootObject()->property("title").toString().trimmed();
|
||||
emit thumbnailCreated(QPixmap::fromImage(m_view->grabFramebuffer().scaled(m_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class QWebEngineView;
|
||||
class QQuickWidget;
|
||||
class QPixmap;
|
||||
|
||||
class QUPZILLA_EXPORT PageThumbnailer : public QObject
|
||||
|
@ -49,12 +49,10 @@ signals:
|
|||
void thumbnailCreated(const QPixmap &);
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void createThumbnail(bool status);
|
||||
|
||||
private:
|
||||
QWebEngineView* m_view;
|
||||
QQuickWidget *m_view;
|
||||
|
||||
QSize m_size;
|
||||
QUrl m_url;
|
||||
|
|
Loading…
Reference in New Issue
Block a user