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/websnap.cpp | |
parent | create function fix (diff) | |
download | rekonq-8e929438e9b3ecd83499cc58bbbd406175195543.tar.xz |
fix previews:
-tab preview uses websnap
-remove scrollbars
-antialiased preview
Diffstat (limited to 'src/websnap.cpp')
-rw-r--r-- | src/websnap.cpp | 44 |
1 files changed, 28 insertions, 16 deletions
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(); |