2011-12-04 16:54:57 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-12-04 16:54:57 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-11-28 19:17:48 +01:00
|
|
|
#include "pagethumbnailer.h"
|
|
|
|
|
2015-08-30 10:33:10 +02:00
|
|
|
#include <QTimer>
|
2015-08-28 20:43:37 +02:00
|
|
|
#include <QApplication>
|
2015-10-09 19:31:08 +02:00
|
|
|
|
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QQuickItem>
|
|
|
|
#include <QQuickWidget>
|
2011-11-28 19:17:48 +01:00
|
|
|
|
|
|
|
PageThumbnailer::PageThumbnailer(QObject* parent)
|
|
|
|
: QObject(parent)
|
2015-10-09 19:31:08 +02:00
|
|
|
, m_view(new QQuickWidget())
|
2014-01-01 18:35:54 +01:00
|
|
|
, m_size(QSize(450, 253))
|
2012-01-02 17:23:31 +01:00
|
|
|
, m_loadTitle(false)
|
2011-11-28 19:17:48 +01:00
|
|
|
{
|
2015-10-09 19:31:08 +02:00
|
|
|
m_view->setAttribute(Qt::WA_DontShowOnScreen);
|
|
|
|
m_view->setSource(QUrl(QSL("qrc:data/thumbnailer.qml")));
|
|
|
|
m_view->rootContext()->setContextProperty(QSL("thumbnailer"), this);
|
2015-08-28 20:43:37 +02:00
|
|
|
m_view->show();
|
2011-11-28 19:17:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PageThumbnailer::setSize(const QSize &size)
|
|
|
|
{
|
|
|
|
if (size.isValid()) {
|
|
|
|
m_size = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageThumbnailer::setUrl(const QUrl &url)
|
|
|
|
{
|
|
|
|
if (url.isValid()) {
|
|
|
|
m_url = url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-02 23:25:27 +01:00
|
|
|
QUrl PageThumbnailer::url()
|
|
|
|
{
|
|
|
|
return m_url;
|
|
|
|
}
|
|
|
|
|
2011-12-23 13:47:38 +01:00
|
|
|
bool PageThumbnailer::loadTitle()
|
|
|
|
{
|
|
|
|
return m_loadTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageThumbnailer::setLoadTitle(bool load)
|
|
|
|
{
|
|
|
|
m_loadTitle = load;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString PageThumbnailer::title()
|
|
|
|
{
|
2013-02-09 20:52:25 +01:00
|
|
|
QString title = m_title.isEmpty() ? m_url.host() : m_title;
|
|
|
|
if (title.isEmpty()) {
|
|
|
|
title = m_url.toString();
|
|
|
|
}
|
|
|
|
return title;
|
2011-12-23 13:47:38 +01:00
|
|
|
}
|
|
|
|
|
2011-11-28 19:17:48 +01:00
|
|
|
void PageThumbnailer::start()
|
|
|
|
{
|
2015-10-09 19:31:08 +02:00
|
|
|
if (m_view->rootObject()) {
|
|
|
|
m_view->rootObject()->setProperty("url", m_url);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QTimer::singleShot(0, this, [this]() {
|
|
|
|
emit thumbnailCreated(QPixmap());
|
|
|
|
});
|
|
|
|
}
|
2011-11-28 19:17:48 +01:00
|
|
|
}
|
|
|
|
|
2011-12-11 12:34:51 +01:00
|
|
|
void PageThumbnailer::createThumbnail(bool status)
|
2011-11-28 19:17:48 +01:00
|
|
|
{
|
2011-12-11 12:34:51 +01:00
|
|
|
if (!status) {
|
|
|
|
emit thumbnailCreated(QPixmap());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-30 10:33:10 +02:00
|
|
|
QTimer::singleShot(1000, this, [this]() {
|
2015-10-09 19:31:08 +02:00
|
|
|
m_title = m_view->rootObject()->property("title").toString().trimmed();
|
|
|
|
emit thumbnailCreated(QPixmap::fromImage(m_view->grabFramebuffer().scaled(m_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
|
2015-08-30 10:33:10 +02:00
|
|
|
});
|
2011-12-02 23:25:27 +01:00
|
|
|
}
|
2011-11-28 19:17:48 +01:00
|
|
|
|
2011-12-02 23:25:27 +01:00
|
|
|
PageThumbnailer::~PageThumbnailer()
|
|
|
|
{
|
2015-08-28 20:43:37 +02:00
|
|
|
m_view->deleteLater();
|
2011-11-28 19:17:48 +01:00
|
|
|
}
|