summaryrefslogtreecommitdiff
path: root/src/websnap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/websnap.cpp')
-rw-r--r--src/websnap.cpp45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/websnap.cpp b/src/websnap.cpp
index 577370ba..bb2baf49 100644
--- a/src/websnap.cpp
+++ b/src/websnap.cpp
@@ -74,7 +74,7 @@ void WebSnap::load()
}
-QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h)
+QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h, bool border)
{
// prepare page
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); // Why it doesn't work with one setScrollBarPolicy?
@@ -95,16 +95,15 @@ QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h)
size = QSize(width,width*((0.0+h)/w));
page.setViewportSize(size);
}
-
- // create the target surface
- QPixmap image = QPixmap(size);
- image.fill(Qt::transparent);
-
- // render
- QPainter p(&image);
+
+ // create the page image
+ QImage pageImage = QImage(size, QImage::Format_ARGB32_Premultiplied);
+ pageImage.fill(Qt::transparent);
+ // render it
+ QPainter p(&pageImage);
page.mainFrame()->render(&p);
p.end();
- image = image.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
+ pageImage = pageImage.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
// restore page settings
page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAsNeeded);
@@ -112,7 +111,31 @@ QPixmap WebSnap::renderPreview(const QWebPage &page,int w, int h)
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);
- return image;
+ if(!border)
+ return QPixmap::fromImage(pageImage);
+
+ // background image
+ QSize fixedSize(w + 30, h + 26);
+ QImage backImage = QImage(fixedSize, QImage::Format_ARGB32_Premultiplied);
+ QString backImagePath = KStandardDirs::locate("appdata", "pics/bg.png");
+ backImage.load( backImagePath );
+
+ // create target
+ QImage resultImage = QImage(fixedSize, QImage::Format_ARGB32_Premultiplied);
+ resultImage.fill(Qt::transparent);
+
+ QPainter pt(&resultImage);
+ pt.setCompositionMode(QPainter::CompositionMode_Source);
+ pt.fillRect(resultImage.rect(), Qt::transparent);
+ pt.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ pt.drawImage(0, 0, backImage);
+ pt.setCompositionMode(QPainter::CompositionMode_SourceOver);
+ pt.drawImage(15, 13, pageImage);
+ pt.setCompositionMode(QPainter::CompositionMode_DestinationOver);
+ pt.fillRect(resultImage.rect(), Qt::transparent);
+ pt.end();
+
+ return QPixmap::fromImage(resultImage);
}
@@ -125,7 +148,7 @@ void WebSnap::saveResult(bool ok)
return;
}
- m_image = renderPreview(m_page, WIDTH, HEIGHT);
+ m_image = renderPreview(m_page, WIDTH, HEIGHT, true);
emit finished();
}