From 8e929438e9b3ecd83499cc58bbbd406175195543 Mon Sep 17 00:00:00 2001 From: megabigbug Date: Sun, 20 Sep 2009 15:40:53 +0200 Subject: fix previews: -tab preview uses websnap -remove scrollbars -antialiased preview --- src/mainview.cpp | 15 ++------------- src/mainview.h | 1 - src/websnap.cpp | 44 ++++++++++++++++++++++++++++---------------- src/websnap.h | 3 ++- 4 files changed, 32 insertions(+), 31 deletions(-) (limited to 'src') 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 @@ -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(); -- cgit v1.2.1 From 3841557b91d7e1b168c741b5fdac08d5b0761234 Mon Sep 17 00:00:00 2001 From: megabigbug Date: Sun, 20 Sep 2009 16:18:47 +0200 Subject: small fix of tab preview behavior --- src/mainview.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/mainview.cpp b/src/mainview.cpp index 87dbfaa1..6ef99b9b 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -621,8 +621,8 @@ void MainView::mouseMoveEvent(QMouseEvent *event) m_currentTabPreview=tab; } - //if current tab then hide previous tab preview - if (tab==m_tabBar->currentIndex()) + //if current tab or not found then hide previous tab preview + if (tab==m_tabBar->currentIndex() || tab==-1) { if ( m_previewPopup) { @@ -669,7 +669,6 @@ void MainView::showTabPreview(int tab) } m_previewPopup = new KPassivePopup(this); - m_previewPopup->setAutoDelete(true); m_previewPopup->setFrameShape(QFrame::NoFrame); m_previewPopup->setFixedSize(w, h); QLabel *l = new QLabel(); -- cgit v1.2.1 From a57d19624df8d86d4327b4498bb3b4446227040f Mon Sep 17 00:00:00 2001 From: Shaneeb Kamran Date: Mon, 21 Sep 2009 00:06:39 +0600 Subject: Fixed problem with the add tab button of tab bar --- src/tabbar.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/tabbar.cpp b/src/tabbar.cpp index d676af55..3f3faabc 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -73,7 +73,18 @@ TabBar::~TabBar() void TabBar::postLaunch() { - m_addTabButton->setDefaultAction(Application::instance()->mainWindow()->actionByName("new_tab")); + // Find the correct MainWindow of this tab button + MainWindowList list = Application::instance()->mainWindowList(); + MainWindow *window; + foreach (window, list) + { + if (window->isAncestorOf(this)) + { + m_addTabButton->setDefaultAction(window->actionByName("new_tab")); + break; + } + } + m_addTabButton->setAutoRaise(true); m_addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly); m_addTabButton->show(); -- cgit v1.2.1 From c376a1988f8bd026b46a45a640abc810dc7f6fda Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 22 Sep 2009 12:24:54 +0200 Subject: Fixing foreach macros.. --- src/cookiejar.cpp | 2 +- src/homepage.cpp | 2 +- src/networkaccessmanager.cpp | 2 +- src/sessionmanager.cpp | 2 +- src/tabbar.cpp | 13 ++++++------- src/webpage.cpp | 2 +- src/webview.cpp | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/cookiejar.cpp b/src/cookiejar.cpp index cd7b97fa..a8ba18bc 100644 --- a/src/cookiejar.cpp +++ b/src/cookiejar.cpp @@ -84,7 +84,7 @@ QList CookieJar::cookiesForUrl(const QUrl & url) const bool CookieJar::setCookiesFromUrl(const QList & cookieList, const QUrl & url) { QByteArray cookieHeader; - foreach(const QNetworkCookie& cookie, cookieList) + Q_FOREACH(const QNetworkCookie& cookie, cookieList) { cookieHeader = "Set-Cookie: "; cookieHeader += cookie.toRawForm(); diff --git a/src/homepage.cpp b/src/homepage.cpp index aa679999..8dccc3fd 100644 --- a/src/homepage.cpp +++ b/src/homepage.cpp @@ -127,7 +127,7 @@ QString HomePage::recentlyClosedTabs() KUrl::List links = Application::instance()->mainWindow()->mainView()->recentlyClosedTabs(); - foreach(const KUrl &url, links) + Q_FOREACH(const KUrl &url, links) { closed += "
  • " + url.prettyUrl() + "
  • "; } diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp index b2958d9e..6a89d104 100644 --- a/src/networkaccessmanager.cpp +++ b/src/networkaccessmanager.cpp @@ -117,7 +117,7 @@ void NetworkAccessManager::resetDiskCache() QDir cacheDir(location + QString("/http") ); QStringList fileList = cacheDir.entryList(); - foreach(QString str, fileList) + Q_FOREACH(QString str, fileList) { QFile file(str); file.remove(); diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp index c93a229d..0c2c5c32 100644 --- a/src/sessionmanager.cpp +++ b/src/sessionmanager.cpp @@ -66,7 +66,7 @@ void SessionManager::saveSession() } QDataStream out(&sessionFile); MainWindowList wl = Application::instance()->mainWindowList(); - foreach(QPointer w, wl) + Q_FOREACH(QPointer w, wl) { out << QByteArray("window"); MainView *mv = w->mainView(); diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 3f3faabc..dfc1482c 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -75,14 +75,13 @@ void TabBar::postLaunch() { // Find the correct MainWindow of this tab button MainWindowList list = Application::instance()->mainWindowList(); - MainWindow *window; - foreach (window, list) + Q_FOREACH(QPointer w, list) { - if (window->isAncestorOf(this)) - { - m_addTabButton->setDefaultAction(window->actionByName("new_tab")); - break; - } + if (w->isAncestorOf(this)) + { + m_addTabButton->setDefaultAction(w->actionByName("new_tab")); + break; + } } m_addTabButton->setAutoRaise(true); diff --git a/src/webpage.cpp b/src/webpage.cpp index 697cf448..d5d1cd7c 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -200,7 +200,7 @@ void WebPage::manageNetworkErrors(QNetworkReply* reply) return; } QList children = firstFrame->childFrames(); - foreach(QWebFrame *frame, children) + Q_FOREACH(QWebFrame *frame, children) { frames.append(frame); } diff --git a/src/webview.cpp b/src/webview.cpp index 8a74e76b..21a24c4f 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -175,7 +175,7 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) KService::Ptr service; KUriFilterData data; - foreach (const QString &engine, favoriteEngines) + Q_FOREACH(const QString &engine, favoriteEngines) { if(!engine.isEmpty()) { -- cgit v1.2.1