mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Using faster thumbnail generation also in Speed Dial.
- thanks to Ariya Hidayat #378
This commit is contained in:
parent
7e778072b6
commit
a34057d1ea
@ -26,6 +26,7 @@
|
||||
#include <QDebug>
|
||||
#include <QWebFrame>
|
||||
#include <QWebPage>
|
||||
#include <QImage>
|
||||
|
||||
#define ENSURE_LOADED if (!m_loaded) loadSettings();
|
||||
|
||||
@ -259,7 +260,7 @@ void SpeedDial::loadThumbnail(const QString &url, bool loadTitle)
|
||||
PageThumbnailer* thumbnailer = new PageThumbnailer(this);
|
||||
thumbnailer->setUrl(QUrl::fromEncoded(url.toUtf8()));
|
||||
thumbnailer->setLoadTitle(loadTitle);
|
||||
connect(thumbnailer, SIGNAL(thumbnailCreated(QPixmap)), this, SLOT(thumbnailCreated(QPixmap)));
|
||||
connect(thumbnailer, SIGNAL(thumbnailCreated(const QPixmap&)), this, SLOT(thumbnailCreated(const QPixmap&)));
|
||||
|
||||
thumbnailer->start();
|
||||
}
|
||||
@ -310,7 +311,7 @@ void SpeedDial::setSdSize(int count)
|
||||
m_sizeOfSpeedDials = count;
|
||||
}
|
||||
|
||||
void SpeedDial::thumbnailCreated(const QPixmap &image)
|
||||
void SpeedDial::thumbnailCreated(const QPixmap &pixmap)
|
||||
{
|
||||
PageThumbnailer* thumbnailer = qobject_cast<PageThumbnailer*>(sender());
|
||||
if (!thumbnailer) {
|
||||
@ -322,13 +323,13 @@ void SpeedDial::thumbnailCreated(const QPixmap &image)
|
||||
QString url = thumbnailer->url().toString();
|
||||
QString fileName = m_thumbnailsDir + QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md4).toHex() + ".png";
|
||||
|
||||
if (image.isNull()) {
|
||||
if (pixmap.isNull()) {
|
||||
fileName = "qrc:/html/broken-page.png";
|
||||
title = tr("Unable to load");
|
||||
loadTitle = true;
|
||||
}
|
||||
else {
|
||||
if (!image.save(fileName)) {
|
||||
if (!pixmap.save(fileName, "PNG")) {
|
||||
qWarning() << "SpeedDial::thumbnailCreated Cannot save thumbnail to " << fileName;
|
||||
}
|
||||
|
||||
|
@ -65,19 +65,19 @@ signals:
|
||||
void pagesChanged();
|
||||
|
||||
public slots:
|
||||
Q_INVOKABLE void changed(const QString &allPages);
|
||||
Q_INVOKABLE void loadThumbnail(const QString &url, bool loadTitle = false);
|
||||
Q_INVOKABLE void removeImageForUrl(const QString &url);
|
||||
void changed(const QString &allPages);
|
||||
void loadThumbnail(const QString &url, bool loadTitle = false);
|
||||
void removeImageForUrl(const QString &url);
|
||||
|
||||
Q_INVOKABLE QString getOpenFileName();
|
||||
Q_INVOKABLE QString urlFromUserInput(const QString &url);
|
||||
Q_INVOKABLE void setBackgroundImage(const QString &image);
|
||||
Q_INVOKABLE void setBackgroundImageSize(const QString &size);
|
||||
Q_INVOKABLE void setPagesInRow(int count);
|
||||
Q_INVOKABLE void setSdSize(int count);
|
||||
QString getOpenFileName();
|
||||
QString urlFromUserInput(const QString &url);
|
||||
void setBackgroundImage(const QString &image);
|
||||
void setBackgroundImageSize(const QString &size);
|
||||
void setPagesInRow(int count);
|
||||
void setSdSize(int count);
|
||||
|
||||
private slots:
|
||||
void thumbnailCreated(const QPixmap &image);
|
||||
void thumbnailCreated(const QPixmap &pixmap);
|
||||
|
||||
private:
|
||||
QList<QWebFrame*> cleanFrames();
|
||||
|
@ -118,14 +118,16 @@ void PageThumbnailer::createThumbnail(bool status)
|
||||
|
||||
m_title = m_page->mainFrame()->title();
|
||||
|
||||
QImage image(m_page->viewportSize(), QImage::Format_ARGB32_Premultiplied);
|
||||
QPainter painter(&image);
|
||||
m_page->mainFrame()->render(&painter);
|
||||
QPixmap pixmap(2 * m_size);
|
||||
|
||||
qreal scalingFactor = 2 * static_cast<qreal>(m_size.width()) / 1280;
|
||||
|
||||
QPainter painter(&pixmap);
|
||||
painter.scale(scalingFactor, scalingFactor);
|
||||
m_page->mainFrame()->render(&painter, QWebFrame::ContentsLayer);
|
||||
painter.end();
|
||||
|
||||
QImage scaledImage = image.scaled(m_size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
||||
|
||||
emit thumbnailCreated(QPixmap::fromImage(scaledImage));
|
||||
emit thumbnailCreated(pixmap.scaled(m_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
}
|
||||
|
||||
PageThumbnailer::~PageThumbnailer()
|
||||
|
@ -22,11 +22,11 @@
|
||||
#include <QSize>
|
||||
#include <QUrl>
|
||||
#include <QWebPluginFactory>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "qz_namespace.h"
|
||||
|
||||
class QWebPage;
|
||||
class QPixmap;
|
||||
|
||||
class QT_QUPZILLA_EXPORT CleanPluginFactory : public QWebPluginFactory
|
||||
{
|
||||
@ -59,7 +59,7 @@ public:
|
||||
void start();
|
||||
|
||||
signals:
|
||||
void thumbnailCreated(QPixmap);
|
||||
void thumbnailCreated(const QPixmap&);
|
||||
|
||||
public slots:
|
||||
|
||||
|
@ -253,21 +253,17 @@ QPixmap WebTab::renderTabPreview()
|
||||
WebPage* page = m_view->page();
|
||||
QSize oldSize = page->viewportSize();
|
||||
|
||||
int renderWidth = qMin(page->mainFrame()->contentsSize().width(), 1280);
|
||||
int renderHeight = renderWidth / 23 * 15;
|
||||
|
||||
const int verticalScrollBarWidth = page->mainFrame()->scrollBarGeometry(Qt::Vertical).width();
|
||||
const int horizontalScrollBarHeight = page->mainFrame()->scrollBarGeometry(Qt::Horizontal).height();
|
||||
|
||||
page->setViewportSize(QSize(renderWidth, renderHeight));
|
||||
|
||||
renderWidth -= verticalScrollBarWidth;
|
||||
renderHeight -= horizontalScrollBarHeight;
|
||||
|
||||
const int previewWidth = 230;
|
||||
const int previewHeight = 150;
|
||||
const int verticalScrollBarWidth = page->mainFrame()->scrollBarGeometry(Qt::Vertical).width();
|
||||
const int horizontalScrollBarWidth = page->mainFrame()->scrollBarGeometry(Qt::Horizontal).height();
|
||||
|
||||
int renderWidth = qMin(page->mainFrame()->contentsSize().width(), 1280) - verticalScrollBarWidth;
|
||||
int renderHeight = (renderWidth / 23 * 15) - horizontalScrollBarWidth;
|
||||
qreal scalingFactor = 2 * static_cast<qreal>(previewWidth) / renderWidth;
|
||||
|
||||
page->setViewportSize(QSize(renderWidth, renderHeight));
|
||||
|
||||
QPixmap pageImage(2 * previewWidth, 2 * previewHeight);
|
||||
pageImage.fill(Qt::transparent);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user