From 384b3f1d066443b67b9d3d6389846a44e976876f Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 5 Mar 2010 12:41:28 +0100 Subject: Ok, things seem working well now. Anyway, it needs some days of testing.. --- src/tabbar.cpp | 12 +++++------- src/websnap.cpp | 9 +++++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 43432ec4..25351ac0 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -150,15 +150,15 @@ void TabBar::showTabPreview(int tab) { MainView *mv = qobject_cast(parent()); - WebTab *view = mv->webTab(tab); - WebTab *currentView = mv->webTab(currentIndex()); + WebTab *indexedTab = mv->webTab(tab); + WebTab *currentTab = mv->webTab(currentIndex()); // check if view && currentView exist before using them :) - if(!currentView || !view) + if(!currentTab || !indexedTab) return; int w = tabSizeHint(tab).width(); - int h = w * ( (0.0 + currentView->height()) / currentView->width() ); + int h = w * ( (0.0 + currentTab->height()) / currentTab->width() ); //delete previous tab preview delete m_previewPopup.data(); @@ -170,9 +170,7 @@ void TabBar::showTabPreview(int tab) m_previewPopup.data()->setFixedSize(w, h); QLabel *l = new QLabel(); - QWebPage copyPage(view->page()); - copyPage.setViewportSize(currentView->page()->viewportSize()); - l->setPixmap(WebSnap::renderPreview(copyPage, w, h)); + l->setPixmap( WebSnap::renderPreview( *indexedTab->page() , w, h) ); m_previewPopup.data()->setView(l); m_previewPopup.data()->layout()->setAlignment(Qt::AlignTop); diff --git a/src/websnap.cpp b/src/websnap.cpp index 2916418b..ceb24b4f 100644 --- a/src/websnap.cpp +++ b/src/websnap.cpp @@ -75,11 +75,14 @@ void WebSnap::load() } +// NOTE please, be careful modifying this. +// You are playing with fire.. QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h) { // prepare page page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); + QSize oldSize = page.viewportSize(); // find the best size QSize size; @@ -90,7 +93,8 @@ QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h) // create the page image QImage pageImage = QImage(size, QImage::Format_ARGB32_Premultiplied); - pageImage.fill(Qt::transparent); + pageImage.fill(Qt::transparent); + // render it QPainter p(&pageImage); page.mainFrame()->render(&p); @@ -100,7 +104,8 @@ QPixmap WebSnap::renderPreview(const QWebPage &page, int w, int h) // restore page settings page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAsNeeded); page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded); - + page.setViewportSize(oldSize); + return QPixmap::fromImage(pageImage); } -- cgit v1.2.1