source: trunk/doc/src/snippets/webkit/webpage/main.cpp@ 244

Last change on this file since 244 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 1.0 KB
Line 
1#include <QtGui>
2#include <QWebPage>
3#include <QWebFrame>
4
5//! [0]
6class Thumbnailer : public QObject
7{
8 Q_OBJECT
9
10public:
11 Thumbnailer(const QUrl &url);
12
13signals:
14 void finished();
15
16private slots:
17 void render();
18
19private:
20 QWebPage page;
21
22};
23//! [0]
24
25int main(int argc, char *argv[])
26{
27 QApplication app(argc, argv);
28
29 Thumbnailer thumbnail(QUrl("http://qtsoftware.com"));
30
31 QObject::connect(&thumbnail, SIGNAL(finished()),
32 &app, SLOT(quit()));
33
34 return app.exec();
35}
36
37//! [1]
38Thumbnailer::Thumbnailer(const QUrl &url)
39{
40 page.mainFrame()->load(url);
41 connect(&page, SIGNAL(loadFinished(bool)),
42 this, SLOT(render()));
43}
44//! [1]
45
46//! [2]
47void Thumbnailer::render()
48{
49 page.setViewportSize(page.mainFrame()->contentsSize());
50 QImage image(page.viewportSize(), QImage::Format_ARGB32);
51 QPainter painter(&image);
52
53 page.mainFrame()->render(&painter);
54 painter.end();
55
56 QImage thumbnail = image.scaled(400, 400);
57 thumbnail.save("thumbnail.png");
58
59 emit finished();
60}
61//! [2]
62#include "main.moc"
Note: See TracBrowser for help on using the repository browser.