Changeset 12093 in osm for applications/editors/josm/plugins
- Timestamp:
- 2008-11-26T16:25:48+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/webkit-image.cpp
r12009 r12093 10 10 #include <QtCore/QFile> 11 11 #include <QtCore/QString> 12 #include <QtCore/QDebug>13 12 #include <QtWebKit/QWebView> 14 13 … … 31 30 32 31 public slots: 32 void setGeometry(const QRect &r) 33 { 34 view->setGeometry(r); 35 } 33 36 void loaded(bool ok) 34 37 { … … 36 39 { 37 40 QImage im = QPixmap::grabWidget(view).toImage(); 38 QRgb white = QColor(255,255,255).rgb();39 /* sometimes the white is shifted one bit */40 QRgb white2 = QColor(254,254,254).rgb();41 41 42 /* didn't find a way to reduce image directly, so we scan for white background */43 bool iswhite = true;44 int xsize = WIDTH;45 int ysize = WIDTH;46 for(int x = xsize-1; iswhite && x > 0; --x)47 {48 for(int y = 0; iswhite && y < ysize; ++y)49 {50 QRgb p = im.pixel(x, y);51 if(p != white && p != white2 & p)52 iswhite = false;53 }54 if(iswhite)55 xsize = x;56 }57 iswhite = true;58 for(int y = ysize-1; iswhite && y > 0; --y)59 {60 for(int x = 0; iswhite && x < xsize; ++x)61 {62 QRgb p = im.pixel(x, y);63 if(p != white && p != white2 && p)64 iswhite = false;65 }66 if(iswhite)67 ysize = y;68 }69 /* didn't find a way to clip the QImage directly, so we reload it */70 QPixmap p = QPixmap::grabWidget(view, 0,0,xsize,ysize);71 42 QFile f; 72 43 BINARYSTDOUT 73 44 if(f.open(stdout, QIODevice::WriteOnly|QIODevice::Unbuffered)) 74 45 { 75 if(! p.save(&f, "JPEG"))46 if(!im.save(&f, "JPEG")) 76 47 { 77 p.save(&f, "PNG");48 im.save(&f, "PNG"); 78 49 } 79 50 } … … 99 70 QWebView *view = new QWebView(); 100 71 Save *s = new Save(view); 72 view->resize(WIDTH,WIDTH); 101 73 102 74 QObject::connect(view, SIGNAL(loadFinished(bool)), s, SLOT(loaded(bool))); 103 75 QObject::connect(s, SIGNAL(finish(void)), &a, SLOT(quit())); 104 view->resize(WIDTH,WIDTH);76 QObject::connect(view->page(), SIGNAL(geometryChangeRequested(const QRect &)), s, SLOT(setGeometry(const QRect &))); 105 77 view->load(QUrl(url)); 106 78 return a.exec();
Note:
See TracChangeset
for help on using the changeset viewer.