source: osm/applications/editors/josm/plugins/wmsplugin/webkit-image.cpp@ 12093

Last change on this file since 12093 was 12093, checked in by stoecker, 17 years ago

finally found a way to handle resize events

File size: 1.7 KB
Line 
1/* compile with
2moc webkit-image.cpp >webkit-image.h
3g++ webkit-image.cpp -o webkit-image -lQtCore -lQtWebKit -lQtGui -s -O2
4or under Windows:
5g++ webkit-image.cpp -o webkit-image -lQtCore4 -lQtWebKit4 -lQtGui4 -s O2
6adding the correct directories with -L or -I:
7-I C:\Progra~1\Qt\include -L C:\Progra~1\Qt\lib
8*/
9#include <QtGui/QApplication>
10#include <QtCore/QFile>
11#include <QtCore/QString>
12#include <QtWebKit/QWebView>
13
14/* using mingw to set binary mode */
15#ifdef WIN32
16#include <io.h>
17#include <fcntl.h>
18#define BINARYSTDOUT setmode(fileno(stdout), O_BINARY);
19#else
20#define BINARYSTDOUT
21#endif
22
23#define WIDTH 2000
24
25class Save : public QObject
26{
27Q_OBJECT
28public:
29 Save(QWebView *v) : view(v) {};
30
31public slots:
32 void setGeometry(const QRect &r)
33 {
34 view->setGeometry(r);
35 }
36 void loaded(bool ok)
37 {
38 if(ok)
39 {
40 QImage im = QPixmap::grabWidget(view).toImage();
41
42 QFile f;
43 BINARYSTDOUT
44 if(f.open(stdout, QIODevice::WriteOnly|QIODevice::Unbuffered))
45 {
46 if(!im.save(&f, "JPEG"))
47 {
48 im.save(&f, "PNG");
49 }
50 }
51 }
52 emit finish();
53 }
54signals:
55 void finish(void);
56
57private:
58 QWebView *view;
59};
60
61#include "webkit-image.h"
62
63int main(int argc, char **argv)
64{
65 if(argc != 2)
66 return 20;
67 QString url = QString(argv[1]);
68
69 QApplication a( argc, argv );
70 QWebView *view = new QWebView();
71 Save *s = new Save(view);
72 view->resize(WIDTH,WIDTH);
73
74 QObject::connect(view, SIGNAL(loadFinished(bool)), s, SLOT(loaded(bool)));
75 QObject::connect(s, SIGNAL(finish(void)), &a, SLOT(quit()));
76 QObject::connect(view->page(), SIGNAL(geometryChangeRequested(const QRect &)), s, SLOT(setGeometry(const QRect &)));
77 view->load(QUrl(url));
78 return a.exec();
79}
Note: See TracBrowser for help on using the repository browser.