diff options
author | megabigbug <megabigbug@arrakis.(none)> | 2009-09-20 15:40:53 +0200 |
---|---|---|
committer | megabigbug <megabigbug@arrakis.(none)> | 2009-09-20 15:40:53 +0200 |
commit | 8e929438e9b3ecd83499cc58bbbd406175195543 (patch) | |
tree | 212bd98a92bc9894e0bd5123e66de2a179aa9748 /src | |
parent | create function fix (diff) | |
download | rekonq-8e929438e9b3ecd83499cc58bbbd406175195543.tar.xz |
fix previews:
-tab preview uses websnap
-remove scrollbars
-antialiased preview
Diffstat (limited to 'src')
-rw-r--r-- | src/mainview.cpp | 15 | ||||
-rw-r--r-- | src/mainview.h | 1 | ||||
-rw-r--r-- | src/websnap.cpp | 44 | ||||
-rw-r--r-- | src/websnap.h | 3 |
4 files changed, 32 insertions, 31 deletions
diff --git a/src/mainview.cpp b/src/mainview.cpp index 87dbfaa1..97199e69 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -42,6 +42,7 @@ #include "webview.h" #include "sessionmanager.h" #include "homepage.h" +#include "websnap.h" // KDE Includes #include <KUrl> @@ -645,18 +646,6 @@ void MainView::leaveEvent(QEvent *event) KTabWidget::leaveEvent(event); } -QPixmap MainView::renderTabPreview(int tab, int w, int h) -{ - QPixmap image = QPixmap(webView(tab)->width(), webView(tab)->height()); - image.fill(Qt::transparent); - QPainter p(&image); - webView(tab)->page()->mainFrame()->render(&p); - p.end(); - image = image.scaled(w, h, Qt::KeepAspectRatioByExpanding); - - return image; -} - void MainView::showTabPreview(int tab) { int w=200; @@ -673,7 +662,7 @@ void MainView::showTabPreview(int tab) m_previewPopup->setFrameShape(QFrame::NoFrame); m_previewPopup->setFixedSize(w, h); QLabel *l = new QLabel(); - l->setPixmap(renderTabPreview(tab, w, h)); + l->setPixmap(WebSnap::renderPreview(webView(tab)->page(), w, h)); m_previewPopup->setView(l); m_previewPopup->layout()->setAlignment(Qt::AlignTop); m_previewPopup->layout()->setMargin(0); diff --git a/src/mainview.h b/src/mainview.h index cd212dbd..5410b70e 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -96,7 +96,6 @@ public: virtual void mouseMoveEvent(QMouseEvent *event); virtual void leaveEvent(QEvent *event); void showTabPreview(int tab); - QPixmap renderTabPreview(int tab, int w, int h); signals: // tab widget signals diff --git a/src/websnap.cpp b/src/websnap.cpp index c669dee0..59275522 100644 --- a/src/websnap.cpp +++ b/src/websnap.cpp @@ -61,6 +61,32 @@ void WebSnap::load() m_page.mainFrame()->load( QUrl(m_url) ); } +QPixmap WebSnap::renderPreview(QWebPage *page,int w, int h) +{ + // prepare page + page->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); //Why it doesn't work with one setScrollBarPolicy ? bug in qtwebkit ? + page->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); + page->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); + page->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); + + // create the target surface + QPixmap image = QPixmap(page->viewportSize()); + image.fill(Qt::transparent); + + // render + QPainter p(&image); + page->mainFrame()->render(&p); + p.end(); + image = image.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); + + // 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; +} void WebSnap::saveResult(bool ok) { @@ -70,24 +96,10 @@ void WebSnap::saveResult(bool ok) kDebug() << "Error loading site.."; return; } - - // find proper image size and later resize it.. - QSize size = m_page.mainFrame()->contentsSize(); - - // create the target surface - m_image = QPixmap( size ); - m_image.fill(Qt::transparent); - - // render and rescale - QPainter p(&m_image); - m_page.setViewportSize( size ); - m_page.mainFrame()->render(&p); - p.end(); - m_image = m_image.scaled(WIDTH, HEIGHT, Qt::KeepAspectRatioByExpanding); - QString path = KStandardDirs::locateLocal("cache", QString("thumbs/rek") + m_pos + ".png", true); - if( m_image.save(path) ) + m_image = renderPreview(&m_page, WIDTH, HEIGHT); + if(m_image.save(path)) { kDebug() << "finished"; emit finished(); diff --git a/src/websnap.h b/src/websnap.h index 2bcdfef8..63f8dccf 100644 --- a/src/websnap.h +++ b/src/websnap.h @@ -48,7 +48,8 @@ public: WebSnap(const QString &url, const QString &pos); QPixmap previewImage(); - + static QPixmap renderPreview(QWebPage *page, int w, int h); + signals: void finished(); |