From 4d8d9d6e4eb149b46af315269e9578eb6bbfc241 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 17 Oct 2009 02:39:24 +0200 Subject: STEP 1 creating a new Preview Image Object, based on QWidget and containing the pixmap AND the url --- src/homepage.cpp | 12 +++++++----- src/previewimage.cpp | 49 ++++++++++++++++++++++++++++++++++-------------- src/previewimage.h | 15 ++++++++++----- src/webpluginfactory.cpp | 6 +++++- src/websnap.cpp | 38 ++++++++++++++++++++++++++++--------- src/websnap.h | 1 + 6 files changed, 87 insertions(+), 34 deletions(-) (limited to 'src') 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 += "
"; speed += ""; + speed += urls.at(i) + "\" >"; + speed += ""; speed += ""; speed += ""; speed += ""; - speed += "
"; - speed += "" + text + "
"; + speed += ""; } return speed; } +// FIXME : port to new PreviewImage API to use... QString HomePage::lastVisitedSites() { QString last; @@ -293,9 +294,10 @@ QString HomePage::fillClosedTabs() closed += "
"; closed += ""; + closed += ""; + closed += ""; closed += ""; - closed += "
"; - closed += "" + text + "
"; + closed += ""; } 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 #include #include +#include -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 +#include #include #include #include -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 #include +#include #include -- cgit v1.2.1