1 /* 2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 20 #include <QtGui> 21 #include <QWebPage> 22 #include <QWebFrame> 23 24 //! [0] 25 class Thumbnailer : public QObject 26 { 27 Q_OBJECT 28 29 public: 30 Thumbnailer(const QUrl &url); 31 32 signals: 33 void finished(); 34 35 private slots: 36 void render(); 37 38 private: 39 QWebPage page; 40 41 }; 42 //! [0] 43 44 int main(int argc, char *argv[]) 45 { 46 QApplication app(argc, argv); 47 48 Thumbnailer thumbnail(QUrl("http://qt.nokia.com")); 49 50 QObject::connect(&thumbnail, SIGNAL(finished()), 51 &app, SLOT(quit())); 52 53 return app.exec(); 54 } 55 56 //! [1] 57 Thumbnailer::Thumbnailer(const QUrl &url) 58 { 59 page.mainFrame()->load(url); 60 connect(&page, SIGNAL(loadFinished(bool)), 61 this, SLOT(render())); 62 } 63 //! [1] 64 65 //! [2] 66 void Thumbnailer::render() 67 { 68 page.setViewportSize(page.mainFrame()->contentsSize()); 69 QImage image(page.viewportSize(), QImage::Format_ARGB32); 70 QPainter painter(&image); 71 72 page.mainFrame()->render(&painter); 73 painter.end(); 74 75 QImage thumbnail = image.scaled(400, 400); 76 thumbnail.save("thumbnail.png"); 77 78 emit finished(); 79 } 80 //! [2] 81 #include "main.moc" 82