Esempio n. 1
0
    void paint(GraphicsContext* ctxt, const IntRect& r)
    {
        if (ctxt->paintingDisabled())
            return;

        if (!m_isVisible)
            return;

        if (!m_poster || (!m_poster->getPixels() && !m_poster->pixelRef()))
            return;

        // We paint with the following rules in mind:
        // - only downscale the poster, never upscale
        // - maintain the natural aspect ratio of the poster
        // - the poster should be centered in the target rect
        float originalRatio = static_cast<float>(m_poster->width()) / static_cast<float>(m_poster->height());
        int posterWidth = r.width() > m_poster->width() ? m_poster->width() : r.width();
        int posterHeight = posterWidth / originalRatio;
        int posterX = ((r.width() - posterWidth) / 2) + r.x();
        int posterY = ((r.height() - posterHeight) / 2) + r.y();
        IntRect targetRect(posterX, posterY, posterWidth, posterHeight);
        ctxt->platformContext()->drawBitmapRect(*m_poster, 0, targetRect);
    }
Esempio n. 2
0
void CannonField::moveShot()
{
    QRegion r( shotRect() );
    timerCount++;

    QRect shotR = shotRect();

    if (mode==cheat_mode && timerCount>20) // when the mode equal cheat_mode , then we determine the timerCount bigger than 10
    {
    	autoShootTimer->stop();
    }
    else if ( shotR.intersects( targetRect() ) ) {
        autoShootTimer->stop();
        emit hit();
    } else if ( shotR.x() > width() || shotR.y() > height() ) {
        autoShootTimer->stop();
        emit missed();
    } else {
        r = r.unite( QRegion( shotR ) );
    }

    repaint( r );
}
Esempio n. 3
0
// Draws an pattern that can be optimized by alpha folding outer savelayer alpha value to
// inner draw. A variant where the draw is not uniform color.
static void draw_save_layer_draw_bitmap_restore_sequence(SkCanvas* canvas, SkColor shapeColor,
                                                         InstallDetectorFunc installDetector) {
    SkBitmap bitmap;
    bitmap.allocN32Pixels(kTestRectSize, kTestRectSize);
    bitmap.eraseColor(shapeColor);
    {
        // Make the bitmap non-uniform color, so that it can not be optimized as uniform drawRect.
        SkCanvas canvas(bitmap);
        SkPaint p;
        p.setColor(SK_ColorWHITE);
        SkASSERT(shapeColor != SK_ColorWHITE);
        canvas.drawRect(SkRect::MakeWH(SkIntToScalar(7), SkIntToScalar(7)), p);
    }

    SkRect targetRect(SkRect::MakeWH(SkIntToScalar(kTestRectSize), SkIntToScalar(kTestRectSize)));
    SkPaint layerPaint;
    layerPaint.setColor(SkColorSetARGB(129, 0, 0, 0));
    canvas->saveLayer(&targetRect, &layerPaint);
        SkPaint drawPaint;
        installDetector(&drawPaint);
        canvas->drawBitmap(bitmap, SkIntToScalar(0), SkIntToScalar(0), &drawPaint);
    canvas->restore();
}
void CannonField::moveShot()
{
	QRegion region = shotRect();
	++timerCount;

	QRect shotR = shotRect();

	if (shotR.intersects(targetRect()))
	{
		autoShootTimer -> stop();
		emit hit();
	}
	else if (shotR.x() > width() || shotR.y() > height())
	{
		autoShootTimer -> stop ();
		emit missed();
	}
	else
	{
		region = region.unite(shotR);
	}
	update(region);
}
Esempio n. 5
0
void QMozGrabResult::captureImage(const QRect &rect)
{
    Q_D(QMozGrabResult);
    int w = d->textureSize.width();
    int h = d->textureSize.height();

    if (d->orientation == Qt::LandscapeOrientation || d->orientation == Qt::InvertedLandscapeOrientation) {
        qSwap<int>(w, h);
    }

    int x = d->orientation == Qt::LandscapeOrientation ? rect.width() - w : 0;
    int y = (d->orientation == Qt::PortraitOrientation || d->orientation == Qt::LandscapeOrientation) ? rect.height() - h : 0;

    QRect targetRect(x, y, w, h);
    QImage image = gl_read_framebuffer(targetRect);
    if (d->orientation != Qt::PortraitOrientation && d->orientation != Qt::PrimaryOrientation) {
        QMatrix rotationMatrix;
        switch (d->orientation) {
        case Qt::LandscapeOrientation:
            rotationMatrix.rotate(270);
            break;
        case Qt::InvertedLandscapeOrientation:
            rotationMatrix.rotate(90);
            break;
        case Qt::InvertedPortraitOrientation:
            rotationMatrix.rotate(180);
        default:
            break;
        }
        image = image.transformed(rotationMatrix);
    }

    d->image = image;
    disconnect(d->webPage.data(), &QOpenGLWebPage::afterRendering, this, &QMozGrabResult::captureImage);
    QCoreApplication::postEvent(this, new QEvent(Event_WebPageGrab_Completed));
}
Esempio n. 6
0
void CannonField::paintTarget(QPainter &painter)
{
	painter.setPen(Qt::black);
	painter.setBrush(Qt::red);
	painter.drawRect(targetRect());
}
Esempio n. 7
0
void CannonField::paintTarget( QPainter *p )
{
    p->setBrush( red );
    p->setPen( black );
    p->drawRect( targetRect() );
}
Esempio n. 8
0
    void GraphPathRenderer::copyToWindow(QPainter *d,
            int x, int y, int w, int h)
    {
        if (NULL == d || m_data->tiles == 0) {
            return;
        }
        //qDebug() << x << "," << y << "," << w << "," << h;
        QTime time;
        time.start();

        GraphLib::TileManager *tm = m_data->tiles;

        QTransform t;
        t.translate(-1 * x, -1 * y);

        QPainter &painter = *d;
        painter.setTransform(t);

        int i, j;
        for (i = y; i < (y + h); i += (TILE_HEIGHT - (i % TILE_HEIGHT)))  {
            for (j = x; j < (x + w); j += (TILE_WIDTH - (j % TILE_WIDTH))) {
                GraphLib::Tile *t = tm->get_tile(j, i, true, false);
                if (t == NULL)
                    continue;
                Tile::release(t, false);

                if (1 == needRedraw(QRectF(j, i, 1, 1))) {
                    t = tm->get_tile(j, i, true, true);

                    int tile_x, tile_y;
                    tm->get_tile_coordinates(t, &tile_x, &tile_y);
                    QImage image(t->data, t->ewidth, t->eheight, 
                            QImage::Format_ARGB32_Premultiplied);

                    memset(t->data, 0, t->size);
                    QTransform t1;
                    QRectF extent = calculate_extent(m_data->bbox);

                    t1.translate(-1*extent.center().x(), -1*extent.center().y());
                    t1.translate(tm->width/2, tm->height/2);
                    t1.translate(-1 * tile_x, -1 * tile_y);
                    render(&image, QRectF(), t1);
                    Tile::release(t, true);

                    int index = tm->get_tile_num(tile_x, tile_y);
                    m_data->redrawFlags[index] = 0;
                    //qDebug() << "copy to window : " << index;
                }

                t = tm->get_tile(j, i, true, false);
                int tile_x, tile_y;
                tm->get_tile_coordinates(t, &tile_x, &tile_y);

                QImage image(t->data, t->ewidth, t->eheight, 
                        QImage::Format_ARGB32_Premultiplied);

                int w = t->ewidth;
                int h = t->eheight;

                QRectF targetRect(tile_x, tile_y, w, h);
                QRectF sourceRect(0, 0, w, h);

                painter.drawImage(targetRect, image, sourceRect);
                Tile::release(t, false);


#ifdef TILE_PROFILING
                // 显示tile
                painter.setPen(Qt::red);
                int index = tm->get_tile_num(tile_x, tile_y);
                //image.save(QString("%1.png").arg(index));
                //qDebug() << "++++" << index;
                painter.drawText(QRectF(tile_x, tile_y, w, h),
                        Qt::AlignCenter, QString("%1").arg(index));
                painter.drawRect(QRectF(tile_x, tile_y, w, h));
#endif
            } // j循环
        } // i循环
        //qDebug() << "Time elapsed: " << time.elapsed() << " md.";
    }
Esempio n. 9
0
QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount)
{
    if (from.isNull() && to.isNull()) {
        return from;
    }

    if (qFuzzyCompare(amount + 1, qreal(1.0))) {
        return from;
    }

    QRect startRect(from.rect());
    QRect targetRect(to.rect());
    QSize pixmapSize = startRect.size().expandedTo(targetRect.size());
    QRect toRect = QRect(QPoint(0,0), pixmapSize);
    targetRect.moveCenter(toRect.center());
    startRect.moveCenter(toRect.center());

    //paint to in the center of from
    QColor color;
    color.setAlphaF(amount);

    // If the native paint engine supports Porter/Duff compositing and CompositionMode_Plus
    QPaintEngine *paintEngine = from.paintEngine();
    if (paintEngine && 
        paintEngine->hasFeature(QPaintEngine::PorterDuff) &&
        paintEngine->hasFeature(QPaintEngine::BlendModes)) {
        QPixmap startPixmap(pixmapSize);
        startPixmap.fill(Qt::transparent);

        QPixmap targetPixmap(pixmapSize);
        targetPixmap.fill(Qt::transparent);

        QPainter p;
        p.begin(&targetPixmap);
        p.drawPixmap(targetRect, to);
        p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        p.fillRect(targetRect, color);
        p.end();

        p.begin(&startPixmap);
        p.drawPixmap(startRect, from);
        p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
        p.fillRect(startRect, color);
        p.setCompositionMode(QPainter::CompositionMode_Plus);
        p.drawPixmap(targetRect, targetPixmap);
        p.end();

        return startPixmap;
    }
#if defined(Q_WS_X11) && defined(HAVE_XRENDER)
    // We have Xrender support
    else if (paintEngine && paintEngine->hasFeature(QPaintEngine::PorterDuff)) {
        // QX11PaintEngine doesn't implement CompositionMode_Plus in Qt 4.3,
        // which we need to be able to do a transition from one pixmap to
        // another.
        //
        // In order to avoid the overhead of converting the pixmaps to images
        // and doing the operation entirely in software, this function has a
        // specialized path for X11 that uses Xrender directly to do the
        // transition. This operation can be fully accelerated in HW.
        //
        // This specialization can be removed when QX11PaintEngine supports
        // CompositionMode_Plus.
        QPixmap source(targetPixmap), destination(startPixmap);

        source.detach();
        destination.detach();

        Display *dpy = QX11Info::display();

        XRenderPictFormat *format = XRenderFindStandardFormat(dpy, PictStandardA8);
        XRenderPictureAttributes pa;
        pa.repeat = 1; // RepeatNormal

        // Create a 1x1 8 bit repeating alpha picture
        Pixmap pixmap = XCreatePixmap(dpy, destination.handle(), 1, 1, 8);
        Picture alpha = XRenderCreatePicture(dpy, pixmap, format, CPRepeat, &pa);
        XFreePixmap(dpy, pixmap);

        // Fill the alpha picture with the opacity value
        XRenderColor xcolor;
        xcolor.alpha = quint16(0xffff * amount);
        XRenderFillRectangle(dpy, PictOpSrc, alpha, &xcolor, 0, 0, 1, 1);

        // Reduce the alpha of the destination with 1 - opacity
        XRenderComposite(dpy, PictOpOutReverse, alpha, None, destination.x11PictureHandle(),
                         0, 0, 0, 0, 0, 0, destination.width(), destination.height());

        // Add source * opacity to the destination
        XRenderComposite(dpy, PictOpAdd, source.x11PictureHandle(), alpha,
                         destination.x11PictureHandle(),
                         toRect.x(), toRect.y(), 0, 0, 0, 0, destination.width(), destination.height());

        XRenderFreePicture(dpy, alpha);
        return destination;
    }
#endif
    else {
        // Fall back to using QRasterPaintEngine to do the transition.
        QImage under(pixmapSize, QImage::Format_ARGB32_Premultiplied);
        under.fill(Qt::transparent);
        QImage over(pixmapSize, QImage::Format_ARGB32_Premultiplied);
        over.fill(Qt::transparent);

        QPainter p;
        p.begin(&over);
        p.drawPixmap(targetRect, to);
        p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        p.fillRect(over.rect(), color);
        p.end();

        p.begin(&under);
        p.drawPixmap(startRect, from);
        p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
        p.fillRect(startRect, color);
        p.setCompositionMode(QPainter::CompositionMode_Plus);
        p.drawImage(toRect.topLeft(), over);
        p.end();

        return QPixmap::fromImage(under);
    }
}
Esempio n. 10
0
void QgsRasterCalculator::readRasterPart( double* targetGeotransform, int xOffset, int yOffset, int nCols, int nRows, double* sourceTransform, GDALRasterBandH sourceBand, float* rasterBuffer )
{
  //If dataset transform is the same as the requested transform, do a normal GDAL raster io
  if ( transformationsEqual( targetGeotransform, sourceTransform ) )
  {
    GDALRasterIO( sourceBand, GF_Read, xOffset, yOffset, nCols, nRows, rasterBuffer, nCols, nRows, GDT_Float32, 0, 0 );
    return;
  }

  //pixel calculation needed because of different raster position / resolution
  int nodataSuccess;
  double nodataValue = GDALGetRasterNoDataValue( sourceBand, &nodataSuccess );
  QgsRectangle targetRect( targetGeotransform[0] + targetGeotransform[1] * xOffset, targetGeotransform[3] + yOffset * targetGeotransform[5] + nRows * targetGeotransform[5]
                           , targetGeotransform[0] + targetGeotransform[1] * xOffset + targetGeotransform[1] * nCols, targetGeotransform[3] + yOffset * targetGeotransform[5] );
  QgsRectangle sourceRect( sourceTransform[0], sourceTransform[3] + GDALGetRasterBandYSize( sourceBand ) * sourceTransform[5],
                           sourceTransform[0] +  GDALGetRasterBandXSize( sourceBand )* sourceTransform[1], sourceTransform[3] );
  QgsRectangle intersection = targetRect.intersect( &sourceRect );

  //no intersection, fill all the pixels with nodata values
  if ( intersection.isEmpty() )
  {
    int nPixels = nCols * nRows;
    for ( int i = 0; i < nPixels; ++i )
    {
      rasterBuffer[i] = nodataValue;
    }
    return;
  }

  //do raster io in source resolution
  int sourcePixelOffsetXMin = floor(( intersection.xMinimum() - sourceTransform[0] ) / sourceTransform[1] );
  int sourcePixelOffsetXMax = ceil(( intersection.xMaximum() - sourceTransform[0] ) / sourceTransform[1] );
  int nSourcePixelsX = sourcePixelOffsetXMax - sourcePixelOffsetXMin;
  int sourcePixelOffsetYMax = floor(( intersection.yMaximum() - sourceTransform[3] ) / sourceTransform[5] );
  int sourcePixelOffsetYMin = ceil(( intersection.yMinimum() - sourceTransform[3] ) / sourceTransform[5] );
  int nSourcePixelsY = sourcePixelOffsetYMin - sourcePixelOffsetYMax;
  float* sourceRaster = ( float * ) CPLMalloc( sizeof( float ) * nSourcePixelsX * nSourcePixelsY );
  double sourceRasterXMin = sourceRect.xMinimum() + sourcePixelOffsetXMin * sourceTransform[1];
  double sourceRasterYMax = sourceRect.yMaximum() + sourcePixelOffsetYMax * sourceTransform[5];
  GDALRasterIO( sourceBand, GF_Read, sourcePixelOffsetXMin, sourcePixelOffsetYMax, nSourcePixelsX, nSourcePixelsY,
                sourceRaster, nSourcePixelsX, nSourcePixelsY, GDT_Float32, 0, 0 );


  double targetPixelX;
  double targetPixelXMin = targetGeotransform[0] + targetGeotransform[1] * xOffset + targetGeotransform[1] / 2.0;
  double targetPixelY = targetGeotransform[3] + targetGeotransform[5] * yOffset + targetGeotransform[5] / 2.0; //coordinates of current target pixel
  int sourceIndexX, sourceIndexY; //current raster index in  source pixels
  double sx, sy;
  for ( int i = 0; i < nRows; ++i )
  {
    targetPixelX = targetPixelXMin;
    for ( int j = 0; j < nCols; ++j )
    {
      sx = ( targetPixelX - sourceRasterXMin ) / sourceTransform[1];
      sourceIndexX = sx > 0 ? sx : floor( sx );
      sy = ( targetPixelY - sourceRasterYMax ) / sourceTransform[5];
      sourceIndexY = sy > 0 ? sy : floor( sy );
      if ( sourceIndexX >= 0 && sourceIndexX < nSourcePixelsX
           && sourceIndexY >= 0 && sourceIndexY < nSourcePixelsY )
      {
        rasterBuffer[j + i*nRows] = sourceRaster[ sourceIndexX  + nSourcePixelsX * sourceIndexY ];
      }
      else
      {
        rasterBuffer[j + i*j] = nodataValue;
      }
      targetPixelX += targetGeotransform[1];
    }
    targetPixelY += targetGeotransform[5];
  }

  CPLFree( sourceRaster );
  return;
}
Esempio n. 11
0
void ProgressBar::render(const Rect& finalRect, const Rect& finalClip)
{
	Renderer& r = m_system.getRenderer();

	// rendering caption
	float left = 0;
	float right = 0;
	float height = 0;
	
	Size imgSize;
	Rect targetRect(finalClip);
	if(m_signed)
	{
		float offset = targetRect.getWidth() / 2.f;
		targetRect.setWidth(offset);
		if(m_progress > 0.f)
			targetRect.offset(point(offset, 0.f));
	}
	Rect clip(targetRect);

	if(fabs(m_progress) > 1.f)
	{
		m_progress > 0.f ? m_progress = 1.f : m_progress = -1.f;
	}

	float clipsize = clip.getWidth() * fabs(m_progress);
	clip.setWidth(clipsize);
	
	if(m_progress < 0.f)
	{
		clip.m_left = targetRect.m_right - clipsize;
		clip.m_right = targetRect.m_right;
	}	

	Rect componentRect(targetRect);

	if (m_leftImg)
    {
        // calculate final destination area
		imgSize = m_leftImg->size();
		componentRect.m_right = componentRect.m_left + imgSize.width;
		componentRect.m_bottom = componentRect.m_top + imgSize.height;
		left  = imgSize.width;
		height = imgSize.height;

        // draw this element.
		r.draw(*m_leftImg, componentRect, 1.f, clip, m_backColor, ImageOps::Stretch, ImageOps::Stretch);
    }
	componentRect = targetRect;
	// right image
    if (m_rightImg)
    {
		imgSize = m_rightImg->size();
        componentRect.m_left = componentRect.m_right - imgSize.width;
        componentRect.m_bottom = componentRect.m_top + imgSize.height;

		right = imgSize.width;

        // draw this element.
		r.draw(*m_rightImg, componentRect, 1.f, clip, m_backColor, ImageOps::Stretch, ImageOps::Stretch);
    }
	componentRect = targetRect;
	// center image
    if (m_backImg)
    {
		componentRect.m_left += left;
		componentRect.m_right -= right;
		componentRect.m_bottom = componentRect.m_top + height;
        
		// draw this element.
		r.draw(*m_backImg, componentRect, 1.f, clip, m_backColor, ImageOps::Tile, ImageOps::Stretch);
    }

	Progress::render(finalRect, finalClip);
}
Esempio n. 12
0
	const FRect HudItemDesc::rect() const {
		return targetRect();
	}
Esempio n. 13
0
void WVuMeter::paintEvent(QPaintEvent * /*unused*/) {
    ScopedTimer t("WVuMeter::paintEvent");

    QStyleOption option;
    option.initFrom(this);
    QStylePainter p(this);
    p.drawPrimitive(QStyle::PE_Widget, option);

    if (!m_pPixmapBack.isNull() && !m_pPixmapBack->isNull()) {
        // Draw background. DrawMode takes care of whether to stretch or not.
        m_pPixmapBack->draw(rect(), &p);
    }

    if (!m_pPixmapVu.isNull() && !m_pPixmapVu->isNull()) {
        const double widgetWidth = width();
        const double widgetHeight = height();
        const double pixmapWidth = m_pPixmapVu->width();
        const double pixmapHeight = m_pPixmapVu->height();

        // Draw (part of) vu
        if (m_bHorizontal) {
            const double widgetPosition = math_clamp(widgetWidth * m_dParameter,
                                                     0.0, widgetWidth);
            QRectF targetRect(0, 0, widgetPosition, widgetHeight);

            const double pixmapPosition = math_clamp(pixmapWidth * m_dParameter,
                                                     0.0, pixmapWidth);
            QRectF sourceRect(0, 0, pixmapPosition,  m_pPixmapVu->height());
            m_pPixmapVu->draw(targetRect, &p, sourceRect);

            if (m_iPeakHoldSize > 0 && m_dPeakParameter > 0.0) {
                const double widgetPeakPosition = math_clamp(
                        widgetWidth * m_dPeakParameter, 0.0, widgetWidth);
                const double widgetPeakHoldSize = widgetWidth *
                        static_cast<double>(m_iPeakHoldSize) / pixmapWidth;

                const double pixmapPeakPosition = math_clamp(
                        pixmapWidth * m_dPeakParameter, 0.0, pixmapWidth);
                const double pixmapPeakHoldSize = m_iPeakHoldSize;

                targetRect = QRectF(widgetPeakPosition - widgetPeakHoldSize, 0,
                                    widgetPeakHoldSize, widgetHeight);
                sourceRect = QRectF(pixmapPeakPosition - pixmapPeakHoldSize, 0,
                                    pixmapPeakHoldSize, pixmapHeight);
                m_pPixmapVu->draw(targetRect, &p, sourceRect);
            }
        } else {
            const double widgetPosition = math_clamp(widgetHeight * m_dParameter,
                                                     0.0, widgetHeight);
            QRectF targetRect(0, widgetHeight - widgetPosition,
                              widgetWidth, widgetPosition);

            const double pixmapPosition = math_clamp(pixmapHeight * m_dParameter,
                                                     0.0, pixmapHeight);
            QRectF sourceRect(0, pixmapHeight - pixmapPosition,
                              pixmapWidth, pixmapPosition);
            m_pPixmapVu->draw(targetRect, &p, sourceRect);

            if (m_iPeakHoldSize > 0 && m_dPeakParameter > 0.0) {
                const double widgetPeakPosition = math_clamp(
                        widgetHeight * m_dPeakParameter, 0.0, widgetHeight);
                const double widgetPeakHoldSize = widgetHeight *
                        static_cast<double>(m_iPeakHoldSize) / pixmapHeight;

                const double pixmapPeakPosition = math_clamp(
                        pixmapHeight * m_dPeakParameter, 0.0, pixmapHeight);
                const double pixmapPeakHoldSize = m_iPeakHoldSize;

                targetRect = QRectF(0, widgetHeight - widgetPeakPosition,
                                    widgetWidth, widgetPeakHoldSize);
                sourceRect = QRectF(0, pixmapHeight - pixmapPeakPosition,
                                    pixmapWidth, pixmapPeakHoldSize);
                m_pPixmapVu->draw(targetRect, &p, sourceRect);
            }
        }
    }
    m_dLastParameter = m_dParameter;
    m_dLastPeakParameter = m_dPeakParameter;
}
Esempio n. 14
0
void MainWindow::documentExport(void)
{
    Canvas *currCanvas = canvas();
    QString currFilename = currCanvas->filename();
    currFilename.chop(4);
    if (currFilename.isEmpty())
    {
        // Determine the working directory.
        QSettings settings;
        QString workingDir(QDir::homePath());
        QVariant workingDirSetting =
                settings.value("workingDirectory");
        if (workingDirSetting.isValid())
        {
            workingDir = workingDirSetting.toString();
        }

        currFilename = workingDir + "/untitled";
    }
    QString filename = QFileDialog::getSaveFileName(this, tr("Export Diagram"),
            currFilename, tr("SVG (*.svg);;PDF (*.pdf);;Postscript (*.ps)"));
    if (filename.isEmpty())
    {
        return;
    }

    QRectF pageRect = currCanvas->pageRect();
    if (pageRect.size().isEmpty())
    {
        // There is no page set, so use a page equal to diagram bounds
        double padding = 10;
        pageRect = expandRect(diagramBoundingRect(currCanvas->items()), padding);
    }

    QFileInfo file(filename);
    if (file.suffix() == "svg")
    {
        QSvgGenerator generator;
        generator.setFileName(filename);

        QRectF targetRect(QPointF(0, 0), currCanvas->sceneRect().size());

        QPointF topLeft = pageRect.topLeft() -
                currCanvas->sceneRect().topLeft();
        QRectF viewbox(topLeft, pageRect.size());

        generator.setSize(viewbox.size().toSize());
        generator.setViewBox(viewbox);

        generator.setTitle(QFileInfo(filename).fileName());
        generator.setDescription(tr("This file was exported from Dunnart.  "
                                    "http://www.dunnart.org/"));

        QPainter painter;
        if (painter.begin(&generator))
        {
            painter.setRenderHint(QPainter::Antialiasing);
            currCanvas->setRenderingForPrinting(true);
            currCanvas->render(&painter, targetRect,
                    currCanvas->sceneRect(),
                    Qt::IgnoreAspectRatio);
            currCanvas->setRenderingForPrinting(false);

            painter.end();
        }
        else
        {
            qDebug("Export SVG painter failed to begin.");
        }
    }
    else
    {
        // Use QPrinter for PDF and PS.
        QPrinter printer;
        printer.setOutputFileName(filename);
        printer.setPaperSize(pageRect.size(),
                QPrinter::Millimeter);
        QPainter painter;
        if (painter.begin(&printer))
        {
            painter.setRenderHint(QPainter::Antialiasing);
            currCanvas->setRenderingForPrinting(true);
            currCanvas->render(&painter, QRectF(),
                    expandRect(pageRect, -3),
                    Qt::IgnoreAspectRatio);
            currCanvas->setRenderingForPrinting(false);
        }
        else
        {
            qDebug("Export PDF/PS painter failed to begin.");
        }
    }
}
QSGNode* MDeclarativeStatusBar::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*)
{
    QSGGeometryNode* node = static_cast<QSGGeometryNode*>(oldNode);
    if (!node) {
        node = new QSGGeometryNode;
        node->setFlags(QSGNode::OwnsGeometry | QSGNode::OwnsMaterial | QSGNode::OwnsOpaqueMaterial);
        node->setGeometry(new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4));
    }

    if (!sharedPixmapHandle) {
        node->setMaterial(new QSGFlatColorMaterial);
        node->setOpaqueMaterial(new QSGFlatColorMaterial);
        node->markDirty(QSGNode::DirtyMaterial);
        return node;
    }

    if (!sharedTexture || updateSharedTexture) {
        node->setMaterial(new QSGTextureMaterial);
        node->setOpaqueMaterial(new QSGTextureMaterial);

#if defined(HAVE_XLIB)
        MDeclarativeScreen* screen = MDeclarativeScreen::instance();

#if defined(QT_OPENGL_ES_2)
        static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
        static PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR");
        static PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR");
        static PFNEGLQUERYIMAGENOKPROC eglQueryImageNOK = (PFNEGLQUERYIMAGENOKPROC) eglGetProcAddress("eglQueryImageNOK");

        const EGLint attribs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE };

        EGLDisplay eglDpy = eglGetDisplay((EGLNativeDisplayType)screen->display());
        EGLImageKHR img = eglCreateImageKHR(eglDpy, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)sharedPixmapHandle, attribs);

        GLuint textureId;
        glGenTextures(1, &textureId);
        glBindTexture(GL_TEXTURE_2D, textureId);
        glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES)img);

        GLint width = 0;
        GLint height = 0;
        eglQueryImageNOK(eglDpy, img, EGL_WIDTH, &width);
        eglQueryImageNOK(eglDpy, img, EGL_HEIGHT, &height);

        sharedTexture.reset(canvas()->createTextureFromId(textureId, QSize(width, height), QQuickCanvas::TextureOwnsGLTexture));

        eglDestroyImageKHR(eglDpy, img);
#else
        Display* dpy = screen->display();
        Window dummy1;
        int x, y;
        unsigned int width, height, borderwidth, depth;
        XGetGeometry(dpy, sharedPixmapHandle, &dummy1, &x, &y, &width, &height, &borderwidth, &depth);
        XImage* xi = XGetImage(dpy, sharedPixmapHandle, 0, 0, width, height, ULONG_MAX, ZPixmap);
        QImage img = MX11Wrapper::qimageFromXImage(xi);
        XDestroyImage(xi);
        sharedTexture.reset(canvas()->createTextureFromImage(img));
#endif
#endif // HAVE_XLIB

        static_cast<QSGTextureMaterial*>(node->material())->setTexture(sharedTexture.data());
        static_cast<QSGOpaqueTextureMaterial*>(node->opaqueMaterial())->setTexture(sharedTexture.data());
        node->markDirty(QSGNode::DirtyMaterial);
        updateSharedTexture = false;
    }

    QRectF sourceRect;
    sourceRect = QRectF(0, 0, width(), height());
    if (mOrientation == MDeclarativeScreen::Portrait || mOrientation == MDeclarativeScreen::PortraitInverted)
        sourceRect.moveTop(height());
    sourceRect = sharedTexture.data()->convertToNormalizedSourceRect(sourceRect);

    QRect targetRect(x(), y(), width(), height());

    QSGGeometry::updateTexturedRectGeometry(node->geometry(), targetRect, sourceRect);
    node->markDirty(QSGNode::DirtyGeometry);

    return node;
}