From d201abbd56715f53b48b27ccc0f1bf0b346f449e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 18 Sep 2009 17:21:37 +0200 Subject: It finally works! Need some fixes to be merged.. --- src/homepage.cpp | 3 --- src/previewimage.cpp | 15 ++++++++++----- src/previewimage.h | 14 ++++++-------- src/webpluginfactory.cpp | 16 +++++++--------- src/websnap.cpp | 27 +++++++++++++++++---------- src/websnap.h | 9 ++++----- 6 files changed, 44 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/homepage.cpp b/src/homepage.cpp index 00f0611a..76c4f393 100644 --- a/src/homepage.cpp +++ b/src/homepage.cpp @@ -94,13 +94,10 @@ QString HomePage::speedDial() QString speed = QString(); for(int i = 0; i< urls.count(); ++i) { - QString pageName = QString("page") + QString::number(i); - speed += "
"; speed += ""; speed += ""; speed += ""; - speed += ""; speed += ""; speed += "
"; speed += names.at(i) + "
"; diff --git a/src/previewimage.cpp b/src/previewimage.cpp index 300b7ee7..2d963171 100644 --- a/src/previewimage.cpp +++ b/src/previewimage.cpp @@ -28,22 +28,27 @@ #include #include +#include - -PreviewImage::PreviewImage(const KUrl &url, const QString &fileName) +PreviewImage::PreviewImage(const QString &url) : QLabel() - , m_url(url) - , m_fileName(fileName) + , ws(0) { QString path = KStandardDirs::locate("appdata", "pics/loading.mng"); //QString("thumbs/") + m_fileName, true); setPixmap( QPixmap(path) ); + kDebug() << url; + ws = new WebSnap( KUrl(url) ); + connect(ws, SIGNAL(finished()), this, SLOT(setSiteImage())); } PreviewImage::~PreviewImage() { + kDebug() << "bye bye.."; } -void PreviewImage::doItYourself() +void PreviewImage::setSiteImage() { + kDebug() << "Done. works?"; + setPixmap( ws->previewImage() ); } diff --git a/src/previewimage.h b/src/previewimage.h index e0ee3aec..7cb6c00b 100644 --- a/src/previewimage.h +++ b/src/previewimage.h @@ -28,9 +28,10 @@ #define PREVIEW_IMAGE_H +#include "websnap.h" + #include #include -#include class PreviewImage : public QLabel @@ -38,20 +39,17 @@ class PreviewImage : public QLabel Q_OBJECT public: - explicit PreviewImage(const KUrl &url, const QString &fileName); + PreviewImage(const QString &url); - PreviewImage(const PreviewImage &); // Q_DECLARE_METATYPE requires a copy-constructor - ~PreviewImage(); public slots: - void doItYourself(); + void setSiteImage(); private: QPixmap m_pixmap; - KUrl m_url; - QString m_fileName; + + WebSnap *ws; }; -// Q_DECLARE_METATYPE(PreviewImage) #endif // PREVIEW_IMAGE_H diff --git a/src/webpluginfactory.cpp b/src/webpluginfactory.cpp index 9ff0011d..9d7755c5 100644 --- a/src/webpluginfactory.cpp +++ b/src/webpluginfactory.cpp @@ -50,19 +50,17 @@ QObject *WebPluginFactory::create(const QString &mimeType, const QStringList &argumentNames, const QStringList &argumentValues) const { + kDebug() << "loading mimeType: " << mimeType; + if(mimeType == QString("application/image-preview") ) { - QString url, fileName; - int i = 0; - Q_FOREACH(const QString &key, argumentNames) + for(int i = 0; isetAttribute(QWebSettings::PrivateBrowsingEnabled, true); - m_targetSize = QSize(200, 150); connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(saveResult(bool))); QTimer::singleShot(0, this, SLOT(load())); } @@ -59,6 +56,7 @@ WebSnap::WebSnap(const KUrl &url, const QString &fileName) void WebSnap::load() { + kDebug() << "loading.."; m_page.mainFrame()->load(m_url); } @@ -74,21 +72,30 @@ void WebSnap::saveResult(bool ok) // find proper size, we stick to sensible aspect ratio QSize size = m_page.mainFrame()->contentsSize(); - size.setHeight(size.width() * 150 / 200); + size.setHeight(size.width() * HEIGHT / WIDTH ); // create the target surface - m_image->fill(Qt::transparent); + m_image = QPixmap(WIDTH, HEIGHT); + m_image.fill(Qt::transparent); // render and rescale - QPainter p(m_image); + QPainter p(&m_image); m_page.setViewportSize(m_page.mainFrame()->contentsSize()); m_page.mainFrame()->render(&p); p.end(); - *m_image = (*m_image).scaled(WIDTH, HEIGHT, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); + m_image = m_image.scaled(WIDTH, HEIGHT, Qt::KeepAspectRatioByExpanding); - QString path = KStandardDirs::locateLocal("cache", QString("thumbs/") + m_fileName, true); - if( m_image->save(path) ) + + QString path = KStandardDirs::locateLocal("cache", QString("thumbs/uno.png"), true); + if( m_image.save(path) ) { + kDebug() << "finished"; emit finished(); } } + + +QPixmap WebSnap::previewImage() +{ + return m_image; +} diff --git a/src/websnap.h b/src/websnap.h index be2ad10b..7e77da49 100644 --- a/src/websnap.h +++ b/src/websnap.h @@ -31,7 +31,7 @@ #include #include -#include +#include #include @@ -45,9 +45,9 @@ class WebSnap : public QObject Q_OBJECT public: - WebSnap(const KUrl &url, const QString &fileName); + WebSnap(const KUrl &url); - QImage *previewImage(); + QPixmap previewImage(); signals: void finished(); @@ -59,9 +59,8 @@ private slots: private: QWebPage m_page; KUrl m_url; - QImage *m_image; + QPixmap m_image; QString m_fileName; - QSize m_targetSize; }; #endif // WEB_SNAP_H -- cgit v1.2.1