mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-13 10:32:11 +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>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
|
<file>data/bookmarks.json</file>
|
||||||
<file>data/browsedata.db</file>
|
<file>data/browsedata.db</file>
|
||||||
<file>data/profiles.ini</file>
|
<file>data/profiles.ini</file>
|
||||||
<file>data/bookmarks.json</file>
|
<file>data/thumbnailer.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</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
|
TARGET = QupZilla
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
|
|
|
@ -19,24 +19,21 @@
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QWebEngineView>
|
|
||||||
|
#include <QQmlContext>
|
||||||
|
#include <QQuickItem>
|
||||||
|
#include <QQuickWidget>
|
||||||
|
|
||||||
PageThumbnailer::PageThumbnailer(QObject* parent)
|
PageThumbnailer::PageThumbnailer(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_view(new QWebEngineView())
|
, m_view(new QQuickWidget())
|
||||||
, m_size(QSize(450, 253))
|
, m_size(QSize(450, 253))
|
||||||
, m_loadTitle(false)
|
, m_loadTitle(false)
|
||||||
{
|
{
|
||||||
// Every page should fit in this resolution
|
m_view->setAttribute(Qt::WA_DontShowOnScreen);
|
||||||
m_view->resize(QSize(1280, 720));
|
m_view->setSource(QUrl(QSL("qrc:data/thumbnailer.qml")));
|
||||||
|
m_view->rootContext()->setContextProperty(QSL("thumbnailer"), this);
|
||||||
// Well ...
|
|
||||||
QWidget *w = QApplication::activeWindow();
|
|
||||||
m_view->show();
|
m_view->show();
|
||||||
if (w) {
|
|
||||||
QApplication::setActiveWindow(w);
|
|
||||||
w->activateWindow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageThumbnailer::setSize(const QSize &size)
|
void PageThumbnailer::setSize(const QSize &size)
|
||||||
|
@ -79,9 +76,14 @@ QString PageThumbnailer::title()
|
||||||
|
|
||||||
void PageThumbnailer::start()
|
void PageThumbnailer::start()
|
||||||
{
|
{
|
||||||
m_view->load(m_url);
|
if (m_view->rootObject()) {
|
||||||
|
m_view->rootObject()->setProperty("url", m_url);
|
||||||
connect(m_view, &QWebEngineView::loadFinished, this, &PageThumbnailer::createThumbnail);
|
}
|
||||||
|
else {
|
||||||
|
QTimer::singleShot(0, this, [this]() {
|
||||||
|
emit thumbnailCreated(QPixmap());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PageThumbnailer::createThumbnail(bool status)
|
void PageThumbnailer::createThumbnail(bool status)
|
||||||
|
@ -92,8 +94,8 @@ void PageThumbnailer::createThumbnail(bool status)
|
||||||
}
|
}
|
||||||
|
|
||||||
QTimer::singleShot(1000, this, [this]() {
|
QTimer::singleShot(1000, this, [this]() {
|
||||||
m_title = m_view->title().trimmed();
|
m_title = m_view->rootObject()->property("title").toString().trimmed();
|
||||||
emit thumbnailCreated(m_view->grab().scaled(m_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
emit thumbnailCreated(QPixmap::fromImage(m_view->grabFramebuffer().scaled(m_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include "qzcommon.h"
|
#include "qzcommon.h"
|
||||||
|
|
||||||
class QWebEngineView;
|
class QQuickWidget;
|
||||||
class QPixmap;
|
class QPixmap;
|
||||||
|
|
||||||
class QUPZILLA_EXPORT PageThumbnailer : public QObject
|
class QUPZILLA_EXPORT PageThumbnailer : public QObject
|
||||||
|
@ -49,12 +49,10 @@ signals:
|
||||||
void thumbnailCreated(const QPixmap &);
|
void thumbnailCreated(const QPixmap &);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private slots:
|
|
||||||
void createThumbnail(bool status);
|
void createThumbnail(bool status);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWebEngineView* m_view;
|
QQuickWidget *m_view;
|
||||||
|
|
||||||
QSize m_size;
|
QSize m_size;
|
||||||
QUrl m_url;
|
QUrl m_url;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user