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"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "networkmanagerproxy.h"
|
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QWebPage>
|
|
|
|
#include <QWebFrame>
|
|
|
|
#include <QPainter>
|
|
|
|
|
2011-11-28 19:17:48 +01:00
|
|
|
CleanPluginFactory::CleanPluginFactory(QObject* parent)
|
|
|
|
: QWebPluginFactory(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QWebPluginFactory::Plugin> CleanPluginFactory::plugins() const
|
|
|
|
{
|
|
|
|
return QList<QWebPluginFactory::Plugin>();
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject* CleanPluginFactory::create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(mimeType)
|
|
|
|
Q_UNUSED(url)
|
|
|
|
Q_UNUSED(argumentNames)
|
|
|
|
Q_UNUSED(argumentValues)
|
|
|
|
|
2011-11-29 23:12:07 +01:00
|
|
|
return new QObject;
|
2011-11-28 19:17:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PageThumbnailer::PageThumbnailer(QObject* parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_page(new QWebPage(this))
|
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
|
|
|
{
|
2011-12-04 19:15:44 +01:00
|
|
|
NetworkManagerProxy* networkProxy = new NetworkManagerProxy(this);
|
|
|
|
networkProxy->setPrimaryNetworkAccessManager(mApp->networkManager());
|
|
|
|
m_page->setNetworkAccessManager(networkProxy);
|
2011-11-28 19:17:48 +01:00
|
|
|
|
|
|
|
m_page->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
|
|
|
|
m_page->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
|
2011-11-29 23:12:07 +01:00
|
|
|
|
2012-02-05 16:00:23 +01:00
|
|
|
// HD Ready -,-
|
2011-11-29 23:12:07 +01:00
|
|
|
// Every page should fit in this resolution
|
2011-11-28 19:17:48 +01:00
|
|
|
m_page->setViewportSize(QSize(1280, 720));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-29 23:12:07 +01:00
|
|
|
void PageThumbnailer::setEnableFlash(bool enable)
|
|
|
|
{
|
|
|
|
if (!enable) {
|
|
|
|
m_page->setPluginFactory(new CleanPluginFactory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-28 19:17:48 +01:00
|
|
|
void PageThumbnailer::start()
|
|
|
|
{
|
|
|
|
m_page->mainFrame()->load(m_url);
|
|
|
|
|
2011-12-11 12:34:51 +01:00
|
|
|
connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(createThumbnail(bool)));
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-09 20:52:25 +01:00
|
|
|
m_title = m_page->mainFrame()->title().trimmed();
|
2011-12-23 13:47:38 +01:00
|
|
|
|
2012-04-12 15:24:57 +02:00
|
|
|
QPixmap pixmap(2 * m_size);
|
|
|
|
|
|
|
|
qreal scalingFactor = 2 * static_cast<qreal>(m_size.width()) / 1280;
|
2011-11-28 19:17:48 +01:00
|
|
|
|
2012-04-12 15:24:57 +02:00
|
|
|
QPainter painter(&pixmap);
|
|
|
|
painter.scale(scalingFactor, scalingFactor);
|
|
|
|
m_page->mainFrame()->render(&painter, QWebFrame::ContentsLayer);
|
|
|
|
painter.end();
|
2011-11-28 19:17:48 +01:00
|
|
|
|
2012-04-12 15:24:57 +02:00
|
|
|
emit thumbnailCreated(pixmap.scaled(m_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
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()
|
|
|
|
{
|
2011-12-04 19:15:44 +01:00
|
|
|
m_page->deleteLater();
|
2011-11-28 19:17:48 +01:00
|
|
|
}
|