summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-06-28 17:49:28 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-06-28 17:49:28 +0200
commitceef608527587443098df9284211cebec2e882b9 (patch)
treeff075538236ad5ff6eef0765a635918c10d17ce0
parentMerge branch 'master' of gitorious.org:rekonq/mainline (diff)
parentadd comments (diff)
downloadrekonq-ceef608527587443098df9284211cebec2e882b9.tar.xz
Merge commit 'refs/merge-requests/143' of git://gitorious.org/rekonq/mainline into m143
-rw-r--r--src/webpage.cpp11
-rw-r--r--src/websnap.cpp72
-rw-r--r--src/websnap.h12
-rw-r--r--src/webview.cpp8
4 files changed, 86 insertions, 17 deletions
diff --git a/src/webpage.cpp b/src/webpage.cpp
index 32b785b4..9e539f7a 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -46,6 +46,7 @@
#include "networkaccessmanager.h"
#include "adblockmanager.h"
#include "urlbar.h"
+//#include "websnap.h"
#include "sslinfodialog_p.h"
@@ -479,6 +480,16 @@ void WebPage::loadFinished(bool ok)
{
wallet()->fillFormData(mainFrame());
}
+
+/* this dead code is for try WebSnap::renderVisiblePagePreview()
+ if (ok)
+ {
+ QPixmap preview = WebSnap::renderVisiblePagePreview(*this);
+ QString path = WebSnap::imagePathFromUrl(mainFrame()->url().toString());
+ QFile::remove(path);
+ preview.save(path);
+ }
+*/
}
diff --git a/src/websnap.cpp b/src/websnap.cpp
index c4e50b3c..29201215 100644
--- a/src/websnap.cpp
+++ b/src/websnap.cpp
@@ -101,28 +101,37 @@ QPixmap WebSnap::renderTabPreview(const QWebPage &page, int w, int h)
return pageImage.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
-
-
-// NOTE please, be careful modifying this.
-// You are playing with fire..
-QPixmap WebSnap::renderPagePreview(const QWebPage &page, int w, int h)
+/*
+// This code is an attempt to render a page currently displayed in a tab without alterate it.
+// It currently does not work but can give ideas:
+// - activate/disable scrollbars of a webview causes problems => this method try to not do that
+// - the viewport and the scroll position must be modified an restored
+// - page.setViewportSize(size); does not seem to work when the page is currently displayed in a webview
+
+QPixmap WebSnap::renderVisiblePagePreview(const QWebPage &page, int w, int h)
{
- // prepare page
+ // save page settings
QSize oldSize = page.viewportSize();
-
- // find the best size
+ QPoint oldScrollPosition = page.mainFrame()->scrollPosition();
+
+ // minimum width
+ int width = 640;
+
+ // find best width
QSize size;
- int width = page.mainFrame()->contentsSize().width();
- if (width < 640)
+ while(page.mainFrame()->scrollBarMaximum(Qt::Horizontal) && width<1920)
{
- width = 640;
+ width+=5;
+ size = QSize(width, width * ((0.0 + h) / w));
+ page.setViewportSize(size);
}
- size = QSize(width, width * ((0.0 + h) / w));
- page.setViewportSize(size);
- //render
- QPixmap pageImage = WebSnap::render(page, page.viewportSize().width(), page.viewportSize().height());
+ // scroll to top
+ page.mainFrame()->setScrollBarValue(Qt::Vertical, 0);
+ // render
+ QPixmap pageImage = WebSnap::render(page, page.viewportSize().width(), page.viewportSize().height());
+
// detect scrollbar size
int scrollbarWidth = (page.mainFrame()->scrollBarMaximum(Qt::Horizontal) ? 17 : 0); //TODO: detect QStyle size for scrollbars
int scrollbarHeight = (page.mainFrame()->scrollBarMaximum(Qt::Vertical) ? 17 : 0);
@@ -130,13 +139,42 @@ QPixmap WebSnap::renderPagePreview(const QWebPage &page, int w, int h)
// resize image
pageImage = pageImage.copy(0, 0, width - scrollbarWidth, size.height() - scrollbarHeight);
pageImage = pageImage.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
-
+
// restore page settings
page.setViewportSize(oldSize);
-
+ page.mainFrame()->setScrollPosition(oldScrollPosition);
+
return pageImage;
}
+*/
+
+QPixmap WebSnap::renderClosingPagePreview(const QWebPage &page, int w, int h)
+{
+ //scroll to top
+ page.mainFrame()->setScrollBarValue(Qt::Vertical, 0);
+
+ // reduce as much as possible
+ page.setViewportSize(QSize(10, 10));
+
+ return renderPagePreview(page, w, h);
+}
+
+
+QPixmap WebSnap::renderPagePreview(const QWebPage &page, int w, int h)
+{
+ //prepare page
+ page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
+ int width = page.mainFrame()->contentsSize().width();
+ page.setViewportSize(QSize(width, width * ((0.0 + h) / w)));
+ //render
+ QPixmap pageImage = WebSnap::render(page, page.viewportSize().width(), page.viewportSize().height());
+
+ // resize image
+ pageImage = pageImage.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
+
+ return pageImage;
+}
QString WebSnap::imagePathFromUrl(const KUrl &url)
diff --git a/src/websnap.h b/src/websnap.h
index d1006c18..3baa01fd 100644
--- a/src/websnap.h
+++ b/src/websnap.h
@@ -89,7 +89,19 @@ public:
* @return the pixmap snapped from the page
*/
static QPixmap renderPagePreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT);
+
+ // static QPixmap renderVisiblePagePreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT); TODO: try to make this method work => more previews for the urlbar
+ /**
+ * Snaps a pixmap of size w * h from a page of a tab that is currently closing
+ *
+ * @param page the page to snap
+ * @param w the image width
+ * @param h the image height
+ *
+ * @return the pixmap snapped from the page
+ */
+ static QPixmap renderClosingPagePreview(const QWebPage &page, int w = WIDTH, int h = HEIGHT);
/**
* Snaps a pixmap of size w * h from a page for tab preview
diff --git a/src/webview.cpp b/src/webview.cpp
index f6c90bdd..3b81b0bb 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -38,6 +38,7 @@
#include "webpage.h"
#include "bookmarksmanager.h"
#include "searchengine.h"
+#include "websnap.h"
// KDE Includes
#include <KService>
@@ -111,6 +112,13 @@ WebView::~WebView()
{
delete _scrollTimer;
disconnect();
+
+ WebPage* p = page();
+
+ QPixmap preview = WebSnap::renderClosingPagePreview(*p);
+ QString path = WebSnap::imagePathFromUrl(p->mainFrame()->url().toString());
+ QFile::remove(path);
+ preview.save(path);
}