summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/homepage.cpp12
-rw-r--r--src/previewimage.cpp49
-rw-r--r--src/previewimage.h15
-rw-r--r--src/webpluginfactory.cpp6
-rw-r--r--src/websnap.cpp38
-rw-r--r--src/websnap.h1
6 files changed, 87 insertions, 34 deletions
diff --git a/src/homepage.cpp b/src/homepage.cpp
index fabb2a91..7d1e2671 100644
--- a/src/homepage.cpp
+++ b/src/homepage.cpp
@@ -123,18 +123,19 @@ QString HomePage::fillFavorites()
}
speed += "<div class=\"thumbnail\">";
speed += "<object type=\"application/image-preview\" data=\"";
- speed += urls.at(i) + "\" width=\"200\">";
+ speed += urls.at(i) + "\" >";
+ speed += "<param name=\"title\" value=\"" + text + "\" />";
speed += "<param name=\"index\" value=\"" + QString::number(i) + "\" />";
speed += "<param name=\"isFavorite\" value=\"true\" />";
speed += "</object>";
- speed += "<br />";
- speed += "<a href=\"" + urls.at(i) + "\">" + text + "</a></div>";
+ speed += "</div>";
}
return speed;
}
+// FIXME : port to new PreviewImage API to use...
QString HomePage::lastVisitedSites()
{
QString last;
@@ -293,9 +294,10 @@ QString HomePage::fillClosedTabs()
closed += "<div class=\"thumbnail\">";
closed += "<object type=\"application/image-preview\" data=\"";
closed += url.prettyUrl() + "\" width=\"200\">";
+ closed += "<param name=\"title\" value=\"" + text + "\" />";
+ closed += "<param name=\"index\" value=\"" + QString::number(i) + "\" />";
closed += "</object>";
- closed += "<br />";
- closed += "<a href=\"" + url.prettyUrl() + "\">" + text + "</a></div>";
+ closed += "</div>";
}
return closed;
diff --git a/src/previewimage.cpp b/src/previewimage.cpp
index ae23cde0..42b275b2 100644
--- a/src/previewimage.cpp
+++ b/src/previewimage.cpp
@@ -48,17 +48,26 @@
#include <QMovie>
#include <QMouseEvent>
#include <QHBoxLayout>
+#include <QVBoxLayout>
-PreviewImage::PreviewImage(const QUrl &url, int index, bool isFavorite)
- : QLabel()
+PreviewImage::PreviewImage(const QUrl &url, const QString &title, int index, bool isFavorite)
+ : QWidget()
, ws(0)
- , m_url(0)
, loadingSnapshot(false)
+ , m_url(0)
+ , m_title(title)
, m_isFavorite(isFavorite)
, m_index(index)
, m_button(0)
+ , m_imageLabel(new QLabel)
+ , m_textLabel(new QLabel)
{
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(m_imageLabel);
+ mainLayout->addWidget(m_textLabel);
+ setLayout(mainLayout);
+
loadUrlPreview(url);
setAlignment(Qt::AlignCenter);
}
@@ -67,6 +76,8 @@ PreviewImage::PreviewImage(const QUrl &url, int index, bool isFavorite)
PreviewImage::~PreviewImage()
{
delete ws;
+ delete m_imageLabel;
+ delete m_textLabel;
}
@@ -86,7 +97,8 @@ void PreviewImage::loadUrlPreview(const QUrl& url)
if(QFile::exists(m_savePath))
{
m_pixmap.load(m_savePath);
- setPixmap(m_pixmap);
+ m_imageLabel->setPixmap(m_pixmap);
+ m_textLabel->setText(m_title);
}
else
{
@@ -99,8 +111,9 @@ void PreviewImage::loadUrlPreview(const QUrl& url)
// load an animation waiting for site preview
QMovie *movie = new QMovie(path, QByteArray(), this);
movie->setSpeed(50);
- setMovie(movie);
+ m_imageLabel->setMovie(movie);
movie->start();
+ m_textLabel->setText( i18n("Loading preview...") );
}
}
@@ -108,13 +121,19 @@ void PreviewImage::loadUrlPreview(const QUrl& url)
void PreviewImage::snapFinished()
{
loadingSnapshot = false;
- QMovie *m = movie();
+ QMovie *m = m_imageLabel->movie();
delete m;
+<<<<<<< HEAD
setMovie(0);
+=======
+ m_imageLabel->setMovie(0);
+
+>>>>>>> STEP 1
m_pixmap = ws->previewImage();
- setPixmap(m_pixmap);
-
+ m_imageLabel->setPixmap(m_pixmap);
+ m_textLabel->setText(m_title);
+
m_pixmap.save(m_savePath);
if(m_index > -1)
@@ -140,10 +159,11 @@ void PreviewImage::showEmptyPreview()
{
if(!m_isFavorite)
return;
-
- clear();
-
- QHBoxLayout *layout = new QHBoxLayout(this);
+
+ m_imageLabel->clear();
+ m_textLabel->clear();
+
+ QVBoxLayout *layout = new QVBoxLayout;
m_button = new QToolButton(this);
m_button->setDefaultAction(historyMenu());
m_button->setPopupMode(QToolButton::InstantPopup);
@@ -152,6 +172,7 @@ void PreviewImage::showEmptyPreview()
m_button->setAutoRaise(true);
m_button->setIconSize(QSize(48, 48));
layout->addWidget(m_button);
+ m_imageLabel->setLayout(layout);
}
@@ -193,7 +214,7 @@ void PreviewImage::mousePressEvent(QMouseEvent *event)
*/
return;
};
- QLabel::mousePressEvent(event);
+ QWidget::mousePressEvent(event);
}
@@ -287,7 +308,7 @@ void PreviewImage::setUrlFromAction()
if(m_button)
{
- layout()->deleteLater();
+ m_imageLabel->layout()->deleteLater();
m_button->menu()->deleteLater();
m_button->deleteLater();
}
diff --git a/src/previewimage.h b/src/previewimage.h
index 5568dd29..6bc27d8d 100644
--- a/src/previewimage.h
+++ b/src/previewimage.h
@@ -35,16 +35,17 @@
// Qt Includes
#include <QLabel>
+#include <QFrame>
#include <QImage>
#include <QUrl>
#include <QToolButton>
-class PreviewImage : public QLabel
+class PreviewImage : public QWidget
{
Q_OBJECT
public:
- PreviewImage(const QUrl &url, int index, bool isFavorite);
+ PreviewImage(const QUrl &url, const QString &title, int index, bool isFavorite);
~PreviewImage();
QString guessNameFromUrl(QUrl url);
@@ -70,14 +71,18 @@ private:
QPixmap m_pixmap;
WebSnap *ws;
- QUrl m_url;
- QString m_savePath;
-
+ QString m_savePath;
bool loadingSnapshot;
+
+ QUrl m_url;
+ QString m_title;
bool m_isFavorite;
int m_index;
QToolButton *m_button;
+
+ QLabel *m_imageLabel;
+ QLabel *m_textLabel;
};
#endif // PREVIEW_IMAGE_H
diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp
index b9d50697..3daffbb6 100644
--- a/src/webpluginfactory.cpp
+++ b/src/webpluginfactory.cpp
@@ -57,10 +57,14 @@ QObject *WebPluginFactory::create(const QString &mimeType,
if(mimeType == QString("application/image-preview") )
{
+ QString title;
int number = -1;
bool isFavorite = false;
int i;
+ i = argumentNames.indexOf( QString("title") );
+ if(i > -1)
+ title = argumentValues.at(i);
i = argumentNames.indexOf( QString("isFavorite") );
if(i > -1)
isFavorite = true;
@@ -68,7 +72,7 @@ QObject *WebPluginFactory::create(const QString &mimeType,
if(i > -1)
number = argumentValues.at(i).toInt();
- return new PreviewImage(url, number, isFavorite);
+ return new PreviewImage(url, title, number, isFavorite);
}
// this let QtWebKit using builtin plugins
diff --git a/src/websnap.cpp b/src/websnap.cpp
index 577370ba..5727bc6f 100644
--- a/src/websnap.cpp
+++ b/src/websnap.cpp
@@ -95,24 +95,44 @@ QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h)
size = QSize(width,width*((0.0+h)/w));
page.setViewportSize(size);
}
-
- // create the target surface
- QPixmap image = QPixmap(size);
- image.fill(Qt::transparent);
-
- // render
- QPainter p(&image);
+
+ // create the page image
+ QImage pageImage = QImage(size, QImage::Format_ARGB32_Premultiplied);
+ pageImage.fill(Qt::transparent);
+ // render it
+ QPainter p(&pageImage);
page.mainFrame()->render(&p);
p.end();
- image = image.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
+ pageImage = pageImage.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
+ // background image
+ QSize fixedSize(w + 30, h + 26);
+ QImage backImage = QImage(fixedSize, QImage::Format_ARGB32_Premultiplied);
+ QString backImagePath = KStandardDirs::locate("appdata", "pics/bg.png");
+ backImage.load( backImagePath );
+
+ // create target
+ QImage resultImage = QImage(fixedSize, QImage::Format_ARGB32_Premultiplied);
+ resultImage.fill(Qt::transparent);
+
+ QPainter pt(&resultImage);
+ pt.setCompositionMode(QPainter::CompositionMode_Source);
+ pt.fillRect(resultImage.rect(), Qt::transparent);
+ pt.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ pt.drawImage(0, 0, backImage);
+ pt.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ pt.drawImage(15, 13, pageImage);
+ pt.setCompositionMode(QPainter::CompositionMode_DestinationOver);
+ pt.fillRect(resultImage.rect(), Qt::transparent);
+ pt.end();
+
// restore page settings
page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAsNeeded);
page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAsNeeded);
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);
- return image;
+ return QPixmap::fromImage(resultImage);
}
diff --git a/src/websnap.h b/src/websnap.h
index 53686677..6c5b4af9 100644
--- a/src/websnap.h
+++ b/src/websnap.h
@@ -34,6 +34,7 @@
// Qt Includes
#include <QtCore/QObject>
#include <QPixmap>
+#include <QImage>
#include <QWebPage>