Changeset 12093 in osm for applications/editors


Ignore:
Timestamp:
2008-11-26T16:25:48+01:00 (16 years ago)
Author:
stoecker
Message:

finally found a way to handle resize events

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/webkit-image.cpp

    r12009 r12093  
    1010#include <QtCore/QFile>
    1111#include <QtCore/QString>
    12 #include <QtCore/QDebug>
    1312#include <QtWebKit/QWebView>
    1413
     
    3130
    3231public slots:
     32  void setGeometry(const QRect &r)
     33  {
     34    view->setGeometry(r);
     35  }
    3336  void loaded(bool ok)
    3437  {
     
    3639    {
    3740      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();
    4141
    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);
    7142      QFile f;
    7243      BINARYSTDOUT
    7344      if(f.open(stdout, QIODevice::WriteOnly|QIODevice::Unbuffered))
    7445      {
    75         if(!p.save(&f, "JPEG"))
     46        if(!im.save(&f, "JPEG"))
    7647        {
    77           p.save(&f, "PNG");
     48          im.save(&f, "PNG");
    7849        }
    7950      }
     
    9970  QWebView *view = new QWebView();
    10071  Save *s = new Save(view);
     72  view->resize(WIDTH,WIDTH);
    10173
    10274  QObject::connect(view, SIGNAL(loadFinished(bool)), s, SLOT(loaded(bool)));
    10375  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 &)));
    10577  view->load(QUrl(url));
    10678  return a.exec();
Note: See TracChangeset for help on using the changeset viewer.