Permalink
Browse files

move screenshot taking code into webview, and re-do it automaticly, i…

…f no screenshot saved already.
  • Loading branch information...
1 parent 035bff7 commit ee537194b7fcd7f29f384b6dff342127ab0466d6 @gzsombor committed Oct 15, 2009
Showing with 45 additions and 20 deletions.
  1. +4 −16 src/tabwidget.cpp
  2. +39 −4 src/webview.cpp
  3. +2 −0 src/webview.h
View
@@ -683,24 +683,12 @@ void TabWidget::webViewLoadFinished(bool ok)
if (index != currentIndex())
return;
- if (ok)
+ if (ok) {
emit showStatusBarMessage(tr("Finished loading"));
- else
+ webView->takeScreenShot();
+ } else {
emit showStatusBarMessage(tr("Failed to load"));
-
-
- QString directory = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
- QWebPage *page = webView->page();
- QImage image(page->viewportSize(), QImage::Format_ARGB32);
- QPainter painter(&image);
- page->mainFrame()->render(&painter);
- painter.end();
- QString filename = QString(QLatin1String("%1/%2.png"))
- .arg(directory)
- .arg(webView->page()->mainFrame()->url().toString().replace(QLatin1String("/"),QLatin1String("")));
- image.save(filename);
- webView->addScreenShot(filename);
-
+ }
}
void TabWidget::webViewIconChanged()
View
@@ -963,6 +963,7 @@ void WebView::paintEvent(QPaintEvent *event)
}
if (!m_thumbnail.isNull()) {
+ // qDebug() << "m_thumbnail painting ...";
QPixmap toaster;
m_height += 50;
QPainter painter(this);
@@ -1035,17 +1036,48 @@ QPixmap WebView::currentScreenImage()
if (!history()->items().count())
return QPixmap();
QString urlString = history()->items().at(m_quickhistorycurrentitem).url().toString();
- QString directory = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
- QString filename = QString(QLatin1String("%1/%2.png"))
- .arg(directory)
- .arg(urlString.replace(QLatin1String("/"),QLatin1String("")));
+ QString filename = getScreenShotPath(urlString);
QPixmap screenshot;
bool loaded = screenshot.load(filename);
+ if (!loaded) {
+ // try to take a screenshot & save it ...
+ if (takeScreenShot()) {
+ // try again ...
+ screenshot.load(filename);
+ }
+ }
return screenshot;
}
+bool WebView::takeScreenShot()
+{
+ QImage image(m_page->viewportSize(), QImage::Format_ARGB32);
+ QPainter painter(&image);
+ m_page->mainFrame()->render(&painter);
+ painter.end();
+ QString filename = getScreenShotPath(m_page->mainFrame()->url().toString());
+ if (image.save(filename)) {
+ addScreenShot(filename);
+ return true;
+ }
+ return false;
+}
+
+QString WebView::getScreenShotPath(QString urlString)
+{
+ QString directory = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
+ return QString(QLatin1String("%1/%2.png"))
+ .arg(directory)
+ .arg(urlString.replace(QLatin1String("/"),QLatin1String("")));
+}
+
void WebView::displayThumb(const QPixmap &thumb, int x)
{
+ if (thumb.isNull()) {
+ // qDebug() << "displayThumb with null : " << x;
+ return;
+ }
+ // qDebug() << "displayThumb " << thumb.isNull() << thumb.size() << x << m_thumbnail.isNull() << m_thumbnail.size();
m_height = 0;
m_thumbnail = thumb;
m_thumbx = x;
@@ -1054,6 +1086,7 @@ void WebView::displayThumb(const QPixmap &thumb, int x)
void WebView::clearThumb()
{
+ // qDebug() << "clearThumb " << m_thumbnail.isNull() << m_thumbnail.size();
m_thumbnail = 0L;
repaint();
}
@@ -1063,6 +1096,8 @@ void WebView::loadLookBackItem()
if (lookBackItem() != history()->currentItemIndex())
history()->goToItem(history()->items().at(lookBackItem()));
// m_screenshot = 0L;
+// qDebug() << "loadLookBackItem " << m_thumbnail.isNull() << m_thumbnail.size();
+
m_thumbnail = 0L;
}
View
@@ -106,6 +106,7 @@ class WebView : public QWebView
int lookBackItem();
void clearScreenShot() { m_screenshot = 0L; }
void addScreenShot(const QString &filename) { m_screenshotfiles << filename; }
+ bool takeScreenShot();
QPixmap currentScreenImage();
void clearThumb();
void loadLookBackItem();
@@ -136,6 +137,7 @@ public slots:
private:
int levelForZoom(int zoom);
+ QString getScreenShotPath(QString urlString);
private slots:
void setProgress(int progress);

0 comments on commit ee53719

Please sign in to comment.