diff options
author | megabigbug <megabigbug@arrakis.(none)> | 2009-09-22 15:45:18 +0200 |
---|---|---|
committer | megabigbug <megabigbug@arrakis.(none)> | 2009-09-22 15:45:18 +0200 |
commit | c64f84da6627ecd09d74f1e0ff2aa62f47a30c60 (patch) | |
tree | 25620771556c019b808332f074aa9816fe08d828 /src/websnap.cpp | |
parent | small fix of tab preview behavior (diff) | |
parent | Fixing foreach macros.. (diff) | |
download | rekonq-c64f84da6627ecd09d74f1e0ff2aa62f47a30c60.tar.xz |
Merge branch 'master' of git://gitorious.org/rekonq/mainline
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(); |