/*!
  Returns a QPixmap generated from the part of the backing store
  corresponding to \a widget. Returns a null QPixmap if an error
  occurs. The contents of the pixmap are only defined for the regions
  of \a widget that have received paint events since the last resize
  of the backing store.

  If \a rectangle is a null rectangle (the default), the entire widget
  is grabbed. Otherwise, the grabbed area is limited to \a rectangle.

  The default implementation uses QWindowSurface::buffer().

  \sa QPixmap::grabWidget()
*/
QPixmap QWindowSurface::grabWidget(const QWidget *widget, const QRect &rectangle) const
{
    QPixmap result;

    if (widget->window() != window())
        return result;

    const QImage *img = const_cast<QWindowSurface *>(this)->buffer(widget->window());

    if (!img || img->isNull())
        return result;

    QRect rect = rectangle.isEmpty() ? widget->rect() : (widget->rect() & rectangle);

    rect.translate(offset(widget) - offset(widget->window()));
    rect &= QRect(QPoint(), img->size());

    if (rect.isEmpty())
        return result;

    QImage subimg(img->scanLine(rect.y()) + rect.x() * img->depth() / 8,
                  rect.width(), rect.height(),
                  img->bytesPerLine(), img->format());
    subimg.detach(); //### expensive -- maybe we should have a real SubImage that shares reference count

    result = QPixmap::fromImage(subimg);
    return result;
}
Example #2
0
void the_const_problem(ImageDouble& img, const ImageDouble& cimg) {

  mirage::img::Coordinate coord, origin, size;

  //                           //
  //  The problem with images  //
  //                           //

  ImageDouble::pixel_type pix,pix_end;
  ImageDouble::const_pixel_type cpix,cpix_end;
  ImageDouble::value_type *ptr;
  const ImageDouble::value_type *cptr;


  for(pix = img.begin(), pix_end = img.end(), 
        cpix = cimg.const_begin(), cpix_end = cimg.const_end();
      pix != pix_end && cpix != cpix_end;
      ++pix,++cpix) {
    coord = !pix;
    coord = !cpix;
    *pix  = *cpix;
    // *cpix = *pix;  ...is forbidden by the compiler.
  }

  coord(10,10);
  ptr  = &(img(coord));
  cptr = &(img(coord));
  ptr  = &(img[coord]);
  cptr = &(img[coord]);
  // ptr  = &(cimg(coord));  ...is forbidden by the compiler.
  cptr = &(cimg(coord));
  // ptr  = &(cimg[coord]);  ...is forbidden by the compiler.
  cptr = &(cimg[coord]);



  //                               //
  //  The problem with sub images  //
  //                               //



  origin(10,10);
  size(320,240);
  mirage::SubFrame<ImageDouble> subimg(img,origin,size);
  // mirage::SubFrame<ImageDouble> csubimg(cimg,origin,size); ... forbidden by the compiler.
  mirage::ConstSubFrame<ImageDouble> csubimg(cimg,origin,size);

  
  mirage::SubFrame<ImageDouble>::pixel_type spix,spix_end; // const_pixel_type is also available.
  mirage::ConstSubFrame<ImageDouble>::const_pixel_type cspix,cspix_end;

  
  for(spix = subimg.begin(), spix_end = subimg.end(), 
        cspix = csubimg.const_begin(), cspix_end = csubimg.const_end();
      spix != spix_end && cspix != cspix_end;
      ++spix, ++cspix) {
    coord = !spix;
    coord = !cspix;
    *spix  = *cspix;
    // *cspix = *spix;  ...is forbidden by the compiler.
  }

  coord(10,10);
  ptr  = &(subimg(coord));
  cptr = &(subimg(coord));
  ptr  = &(subimg[coord]);
  cptr = &(subimg[coord]);
  // ptr  = &(csubimg(coord));  ...is forbidden by the compiler.
  cptr = &(csubimg(coord));
  // ptr  = &(csubimg[coord]);  ...is forbidden by the compiler.
  cptr = &(csubimg[coord]);



  //                          //
  //  The problem with lines  //
  //                          //

  mirage::img::Line<ImageDouble> line;
  mirage::img::ConstLine<ImageDouble> cline;
  mirage::img::Line<ImageDouble>::pixel_type lpix,lpix_end; // const_pixel_type is also available.
  mirage::img::ConstLine<ImageDouble>::const_pixel_type clpix,clpix_end;

  line << img;
  // line << cimg;  ...is forbidden by the compiler.
  
  cline << img;
  cline << cimg;
  
  line(1,2,3);
  cline(1,2,3);

  for(lpix = line.begin(), lpix_end = line.end(), 
        clpix = cline.const_begin(), clpix_end = cline.const_end();
      lpix != lpix_end && clpix != clpix_end;
      ++lpix, ++clpix) {
    coord = !lpix;
    coord = !clpix;
    *lpix  = *clpix;
    // *clpix = *lpix;  ...is forbidden by the compiler.
  }


  lpix  = line.begin();
  clpix = cline.const_begin();
  ptr  = &(*lpix);
  cptr = &(*lpix);
  // ptr  = &(*clpix);  ...is forbidden by the compiler.
  cptr = &(*clpix);


}