예제 #1
0
void QgsPaintEffect::drawSource( QPainter &painter )
{
  if ( requiresQPainterDpiFix )
  {
    painter.save();
    fixQPictureDpi( &painter );
    painter.drawPicture( 0, 0, *mPicture );
    painter.restore();
  }
  else
  {
    painter.drawPicture( 0, 0, *mPicture );
  }
}
예제 #2
0
파일: widget.cpp 프로젝트: Rookiee/Qt_Codes
void Widget::paintEvent(QPaintEvent *event)
{
    QPainter painter;
    //绘制image
    QImage image(100, 100, QImage::Format_ARGB32);
    painter.begin(&image);
    painter.setPen(QPen(Qt::green, 3));
    painter.setBrush(Qt::yellow);
    painter.drawRect(10, 10, 60, 60);
    painter.drawText(10, 10, 60, 60, Qt::AlignCenter, tr("QImage"));
    painter.setBrush(QColor(0 , 0, 0, 100));
    painter.drawRect(50, 50, 40, 40);
    painter.end();

    //绘制pixmap
    QPixmap pix(100, 100);
    painter.begin(&pix);
    painter.setPen(QPen(Qt::green, 3));
    painter.setBrush(Qt::yellow);
    painter.drawRect(10, 10, 60, 60);
    painter.drawText(10, 10, 60, 60, Qt::AlignCenter, tr("QPixmap"));
    painter.setBrush(QColor(0 , 0, 0, 100));
    painter.drawRect(50, 50, 40, 40);
    painter.end();

    //绘制bitmap
    QBitmap bit(100, 100);
    painter.begin(&bit);
    painter.setPen(QPen(Qt::green, 3));
    painter.setBrush(Qt::yellow);
    painter.drawRect(10, 10, 60, 60);
    painter.drawText(10, 10, 60, 60, Qt::AlignCenter, tr("QBitmap"));
    painter.setBrush(QColor(0 , 0, 0, 100));
    painter.drawRect(50, 50, 40, 40);
    painter.end();

    //绘制picture
    QPicture picture;
    painter.begin(&picture);
    painter.setPen(QPen(Qt::green, 3));
    painter.setBrush(Qt::yellow);
    painter.drawRect(10, 10, 60, 60);
    painter.drawText(10, 10, 60, 60, Qt::AlignCenter, tr("QPicture"));
    painter.setBrush(QColor(0 , 0, 0, 100));
    painter.drawRect(50, 50, 40, 40);
    painter.end();

    //在widget部件上进行绘制
    painter.begin(this);
    painter.drawImage(50, 20, image);
    painter.drawPixmap(200, 20, pix);
    painter.drawPixmap(50, 170, bit);
    painter.drawPicture(200, 170, picture);
}
예제 #3
0
void NCPreviewPage::paintPage( QPainter &painter )
{
	//QPicture picture;
	//bool loadOK = picture.load("temp/p1.tmp");
	//if ( !ok );           // load picture
		//picture.load("drawing.pic");           // load picture
	
	//QPicture _picture;
	//_picture.load("drawing.pic");           // load picture
	painter.drawPicture(0, 0, *picture);    // draw the picture at (0,0)
}
예제 #4
0
/** No descriptions */
void Plot2D::paintEvent(QPaintEvent*)
{
	qDebug("Plot2D::paintEvent");
  QPainter p;
  p.begin(this);
#if 0
  QRect r=p.window();
  qDebug("Plot2D::paintEvent(): %d %d %d %d",
          r.left(),
          r.top(),
          r.right(),
          r.bottom());
#endif
  p.drawPicture(picture_);
	p.end();
}
예제 #5
0
void CGContextDrawLayerInRect(CGContextRef context, CGRect rect, CGLayerRef layer)
{
	QPainter* painter = CGContextGetPainter(context);
	QTransform tf = painter->worldTransform();
	qreal sx, sy;
	CGSize origSize = CGLayerGetSize(layer);
	
	sx = CGRectGetWidth(rect) / origSize.width;
	sy = CGRectGetHeight(rect) / origSize.height;
	
	painter->scale(sx, sy);
	
	painter->drawPicture(QPointF(rect.origin.x / sx, rect.origin.y / sy), *layer->picture);
	
	painter->setWorldTransform(tf);
}
예제 #6
0
QPixmap KoPictureClipart::generatePixmap(const QSize& size, bool /*smoothScale*/)
{
    // Not sure if it works, but it worked for KoPictureFilePreviewWidget::setClipart
    QPixmap pixmap(size);
    QPainter p;

    p.begin( &pixmap );
    p.setBackgroundColor( Qt::white );
    pixmap.fill( Qt::white );

    QRect br = m_clipart.boundingRect();
    if ( br.width() && br.height() )
        p.scale( (double)pixmap.width() / (double)br.width(), (double)pixmap.height() / (double)br.height() );
    p.drawPicture( m_clipart );
    p.end();
    return pixmap;
}
예제 #7
0
void NCPreviewPage::paintTest( QPainter &painter )
{
	//painter.scale( width()/720.0, width()/720.0);
	
	//painter.translate(50.0, 50.0);
	//painter.setWindow(QRect(0, 0, width(), height()));		
	//painter.translate( 80, 80);
	//painter.scale( width(), height() );
	//painter.setViewport(QRect(0, 0, width(), height()));
	
	QPicture _picture;
	_picture.load("drawing.pic");           // load picture
	painter.drawPicture(0, 0, _picture);    // draw the picture at (0,0)
	
	painter.drawPixmap( 100,100, QPixmap("companylogo.png"));	
	//////////////////
	// tesztννσσνν
	//////////////////
	
	painter.setPen(Qt::blue);
	painter.setFont(QFont("Arial", 24));
	painter.drawText( 0,24, "Qt - test ΥΪΙΑΫφόσυϊιαϋ");
	painter.setFont(QFont("Arial", 10));
	painter.setPen(Qt::black);
	painter.drawText( 0,44, "This is a test for a simple text message - test ΥΪΙΑΫφόσυϊιαϋ");
	painter.drawEllipse( 0,50, 50,50);
	painter.drawEllipse( 0,100, 50,50);
	painter.drawEllipse( 0,150, 50,50);
	painter.setPen(Qt::red);
	painter.drawEllipse( 50,50, 50,50);
	painter.drawEllipse( 50,100, 50,50);
	painter.drawEllipse( 50,150, 50,50);
	painter.setPen(Qt::green);
	painter.drawEllipse( 100,50, 50,50);
	painter.drawEllipse( 100,100, 50,50);
	painter.drawEllipse( 100,150, 50,50);
	painter.setFont(QFont("Adobe Helvetica", 9));
	painter.setPen(Qt::black);
	painter.drawText( 0,200,mmToPixel(100.0),mmToPixel(10.0), Qt::TextWordWrap, 
				"This is another test for a simple text message - test ΥΪΙΑΫφόσυϊιαϋ\n"
				"Uwe he iqwueh ishdk asdk hqwgd kjguqwge uzguzggz ιιa");
	painter.drawRect( mmToPixel(10.0),250,mmToPixel(190.0),mmToPixel(10.0) );
}
예제 #8
0
void KoPictureClipart::drawQPicture(QPicture& clipart, QPainter& painter,
    int x, int y, int width, int height, int sx, int sy, int sw, int sh)
{
    kdDebug(30003) << "Drawing KoPictureClipart " << this << endl;
    kdDebug(30003) << "  x=" << x << " y=" << y << " width=" << width << " height=" << height << endl;
    kdDebug(30003) << "  sx=" << sx << " sy=" << sy << " sw=" << sw << " sh=" << sh << endl;
    painter.save();
    // Thanks to Harri, Qt3 makes it much easier than Qt2 ;)
    QRect br = clipart.boundingRect();
    kdDebug(30003) << "  Bounding rect. " << br << endl;

    painter.translate(x,y); // Translating must be done before scaling!
    if ( br.width() && br.height() )
        painter.scale(double(width)/double(br.width()),double(height)/double(br.height()));
    else
        kdWarning(30003) << "Null bounding rectangle: " << br.width() << " x " << br.height() << endl;
    painter.drawPicture(0,0,clipart);
    painter.restore();
}
예제 #9
0
파일: tst_qpicture.cpp 프로젝트: mpvader/qt
/* See task: 41469
   Problem is that the state is not properly restored if the basestate of
   the painter is different when the picture data was created compared to
   the base state of the painter when it is played back.
 */
void tst_QPicture::save_restore()
{
    QPicture pic;
    QPainter p;
    p.begin(&pic);
    paintStuff(&p);
    p.end();

    QPixmap pix1(300, 300);
    pix1.fill(Qt::white);
    p.begin(&pix1);
    p.drawPicture(50, 50, pic);
    p.end();

    QPixmap pix2(300, 300);
    pix2.fill(Qt::white);
    p.begin(&pix2);
    p.translate(50, 50);
    paintStuff(&p);
    p.end();

    QVERIFY( pix1.toImage() == pix2.toImage() );
}
예제 #10
0
bool KoOdtFrameReportPicture::saveData(KoStore* store, KoXmlWriter* manifestWriter) const
{
    QString name = "Pictures/" + pictureName();
    if (!store->open(name)) {
        return false;
    }
    KoStoreDevice device(store);
    QImage image(m_primitive->size().toSize(), QImage::Format_ARGB32);
    image.fill(0);
    QPainter painter;
    painter.begin(&image);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.drawPicture(0, 0, *(picture()->picture()));
    painter.end();
    //kreportDebug()<<image.format();
    bool ok = image.save(&device, "PNG");
    if (ok) {
        QMimeDatabase db;
        const QString mimetype(db.mimeTypeForFile(name, QMimeDatabase::MatchExtension).name());
        manifestWriter->addManifestEntry(name,  mimetype);
    }
    ok = store->close() && ok;
    return ok;
}
예제 #11
0
파일: projection.cpp 프로젝트: zaic/cavis
void ProjectionRenderer::draw(void *_device)
{
    qDebug() << "[render/proj] start!";

    // preparing data for interpolation
    const int n = config->getDimSizeX();
    const double* data = reinterpret_cast<const double*>(config->getData());

    vector<double> data_x, data_y;
    double max_value = data[0], min_value = data[0];
    const double x_scaled = (n - 1) / 100.0 * parameters->x_scale->value();
    for(int i = 0; i < n; i++) {
        double x = i * (parameters->x_scale->value() / 100.0);
        data_x.push_back(x);
        data_y.push_back(data[i] * parameters->y_scale->value());
        max_value = max(max_value, data[i]);
        min_value = min(min_value, data[i]);
    }

    if(config->getDimSizeX() == 0) {
        buffer->prepare();
        return ;
    }

    // interpolation
    Interpolator inter(data_x, data_y);
    const int nn = int(x_scaled);

    int x_scrool_width = static_cast<int>(n * parameters->x_scale->value() / 100.0 + (1.0 - EPS));
    qDebug() << "[render/proj] xwidth" << x_scrool_width << "buf->width" << buffer->width();
    if(buffer->width() - 50 < x_scrool_width)
        buffer->setXScroll(divup<int>(x_scrool_width - buffer->width() - 50, XSCROLL_SIZE));
    else
        buffer->setXScroll(GraphicBuffer::SCROLL_DISABLE);

    int y_scrool_width = static_cast<int>((min_value + max_value) * parameters->y_scale->value() + (1.0 - EPS));
    if(buffer->height() - FRAME_SIZE < y_scrool_width || true)
        buffer->setYScroll(divup<int>(y_scrool_width - buffer->height() - 50, YSCROLL_SIZE));
    else
        buffer->setYScroll(GraphicBuffer::SCROLL_DISABLE);
    // TODO more nice view
    buffer->prepare();
    QPainter *painter = buffer->getRawPaintDevice();

    /*
     * Draw grid
     */
    const int shift_scrool_x = (parameters->x_scale->value() == parameters->x_scale->maximum() && false
                                ? static_cast<int>(XSCROLL_SIZE * buffer->getXScroll() * 100.0 / parameters->x_scale->value() + .5) // TODO: fix
                                : static_cast<int>(XSCROLL_SIZE * buffer->getXScroll() * 100.0 / parameters->x_scale->value() + .5) );
    const int shift_x = FRAME_SIZE - buffer->getXScroll() * 100;
    const int value_invert = buffer->height() - FRAME_SIZE;

    QPicture digits_picuture;
    QPainter digits_painter(&digits_picuture);

    // y-axis
    digits_painter.fillRect(0, 0, FRAME_SIZE, buffer->height(), Qt::white);
    for(int i = 0; i <= buffer->height() / parameters->y_scale->value(); i++) {
        int x = FRAME_SIZE;
        int y = value_invert - i * parameters->y_scale->value();

        // primary dark grid
        painter->setPen(QColor(0xAA, 0xAA, 0xAA));
        painter->drawLine(x, y, buffer->width(), y);
        digits_painter.setPen(Qt::black);
        digits_painter.drawText(x - FRAME_SIZE * 4 / 5, y, toStdString<int>(i).c_str());

        // secondary light grid
        const int cnt = parameters->y_scale->value() / 25;
        const int secondary_height = parameters->y_scale->value() / cnt;
        painter->setPen(QColor(0xDD, 0xDD, 0xDD));
        digits_painter.setPen(QColor(0x55, 0x55, 0x55));
        for(int j = 1; j < cnt; j++) {
            y -= secondary_height;
            painter->drawLine(x, y, buffer->width(), y);
            digits_painter.drawText(x - FRAME_SIZE * 4 / 5, y, toStdString<double>(i + 1.0 / (cnt + 1) * (j)).substr(0, 4).c_str());
        }
    }

    // x-axis
    // TODO: draw with step 100
    digits_painter.begin(&digits_picuture);
    digits_painter.fillRect(0, buffer->height(), buffer->width(), value_invert, Qt::white);
    for(int i = 0; i <= buffer->width() / parameters->x_scale->value(); i++) {
        int x = FRAME_SIZE + i * parameters->x_scale->value();
        int y = value_invert;

        // primary dark grid
        painter->setPen(QColor(0xAA, 0xAA, 0xAA));
        painter->drawLine(x, y, x, 0);
        digits_painter.setPen(Qt::black);
        digits_painter.drawText(x, y + FRAME_SIZE / 2, toStdString<int>(i * 100 + buffer->getXScroll() * XSCROLL_SIZE * 100.0 / parameters->x_scale->value()).c_str());
    }
    // TODO: draw numbers

    digits_painter.end();

    /*
     *  Draw interpolation values
     */
    if(parameters->chk_interpolation->isChecked()) {
        painter->setPen(QColor(0xCC, 0x00, 0x00));
        int last_value = -1;
        for(int x = 0; x < nn; x++) {
            int value = int(inter.Eval(x) + .5);
            value = value_invert - value;
            if(last_value != -1)
                painter->drawLine(x - 1 + shift_x, last_value, x + shift_x, value);
            else
                painter->drawPoint(x + shift_x, value);
            last_value = value;
        }
    }

    /*
     *  Draw given value
     */
    if(parameters->chk_segments->isChecked()) {
        painter->setPen(QColor(0x00, 0xCC, 0x00));
        int px = data_x[0];
        int py = data_y[0];
        for(int ii = 1; ii < n / 10; ii++) {
            int i = ii * 10;
            painter->drawLine(px + shift_x, value_invert - py, data_x[i] + shift_x, value_invert - data_y[i]);
            px = data_x[i];
            py = data_y[i];
        }
    }

    painter->drawPicture(0, 0, digits_picuture);
}
예제 #12
0
int main()
{
    QWidget myWidget;
    {
        // RECORD
//! [0]
        QPicture picture;
        QPainter painter;
        painter.begin(&picture);           // paint in picture
        painter.drawEllipse(10,20, 80,70); // draw an ellipse
        painter.end();                     // painting done
        picture.save("drawing.pic");       // save picture
//! [0]
    }

    {
        // REPLAY
//! [1]
        QPicture picture;
        picture.load("drawing.pic");           // load picture
        QPainter painter;
        painter.begin(&myImage);               // paint in myImage
        painter.drawPicture(0, 0, picture);    // draw the picture at (0,0)
        painter.end();                         // painting done
//! [1]
    }

    QPicture myPicture;
    {
        // FORMATS
//! [2]
        QStringList list = QPicture::inputFormatList();
        foreach (QString string, list)
            myProcessing(string);
//! [2]
    }

    {
        // OUTPUT
//! [3]
        QStringList list = QPicture::outputFormatList();
        foreach (QString string, list)
            myProcessing(string);
//! [3]
    }

    {
        // PIC READ
//! [4]
        QPictureIO iio;
        QPixmap  pixmap;
        iio.setFileName("vegeburger.pic");
        if (iio.read()) {        // OK
            QPicture picture = iio.picture();
            QPainter painter(&pixmap);
            painter.drawPicture(0, 0, picture);
        }
//! [4]
    }

    {
        QPixmap pixmap;
        // PIC WRITE
//! [5]
        QPictureIO iio;
        QPicture   picture;
        QPainter painter(&picture);
        painter.drawPixmap(0, 0, pixmap);
        iio.setPicture(picture);
        iio.setFileName("vegeburger.pic");
        iio.setFormat("PIC");
        if (iio.write())
            return true; // returned true if written successfully
//! [5]
    }

}
예제 #13
0
void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
  QPainter *p = context.renderContext().painter();
  if ( !p )
    return;

  double size = mSize;
  QgsExpression* sizeExpression = expression( "size" );
  bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression;

  if ( sizeExpression )
  {
    size = sizeExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
  }
  size *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );

  if ( hasDataDefinedSize )
  {
    switch ( mScaleMethod )
    {
      case QgsSymbolV2::ScaleArea:
        size = sqrt( size );
        break;
      case QgsSymbolV2::ScaleDiameter:
        break;
    }
  }

  //don't render symbols with size below one or above 10,000 pixels
  if (( int )size < 1 || 10000.0 < size )
  {
    return;
  }

  p->save();

  //offset
  double offsetX = 0;
  double offsetY = 0;
  markerOffset( context, offsetX, offsetY );
  QPointF outputOffset( offsetX, offsetY );

  double angle = mAngle;
  QgsExpression* angleExpression = expression( "angle" );
  if ( angleExpression )
  {
    angle = angleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
  }
  if ( angle )
    outputOffset = _rotatedOffset( outputOffset, angle );
  p->translate( point + outputOffset );

  bool rotated = !qgsDoubleNear( angle, 0 );
  bool drawOnScreen = qgsDoubleNear( context.renderContext().rasterScaleFactor(), 1.0, 0.1 );
  if ( rotated )
    p->rotate( angle );

  QString path = mPath;
  QgsExpression* nameExpression = expression( "name" );
  if ( nameExpression )
  {
    path = nameExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
  }

  double outlineWidth = mOutlineWidth;
  QgsExpression* outlineWidthExpression = expression( "outline_width" );
  if ( outlineWidthExpression )
  {
    outlineWidth = outlineWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
  }

  QColor fillColor = mFillColor;
  QgsExpression* fillExpression = expression( "fill" );
  if ( fillExpression )
  {
    fillColor = QgsSymbolLayerV2Utils::decodeColor( fillExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
  }

  QColor outlineColor = mOutlineColor;
  QgsExpression* outlineExpression = expression( "outline" );
  if ( outlineExpression )
  {
    outlineColor = QgsSymbolLayerV2Utils::decodeColor( outlineExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
  }


  bool fitsInCache = true;
  bool usePict = true;
  double hwRatio = 1.0;
  if ( drawOnScreen && !rotated )
  {
    usePict = false;
    const QImage& img = QgsSvgCache::instance()->svgAsImage( path, size, fillColor, outlineColor, outlineWidth,
                        context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor(), fitsInCache );
    if ( fitsInCache && img.width() > 1 )
    {
      //consider transparency
      if ( !qgsDoubleNear( context.alpha(), 1.0 ) )
      {
        QImage transparentImage = img.copy();
        QgsSymbolLayerV2Utils::multiplyImageOpacity( &transparentImage, context.alpha() );
        p->drawImage( -transparentImage.width() / 2.0, -transparentImage.height() / 2.0, transparentImage );
        hwRatio = ( double )transparentImage.height() / ( double )transparentImage.width();
      }
      else
      {
        p->drawImage( -img.width() / 2.0, -img.height() / 2.0, img );
        hwRatio = ( double )img.height() / ( double )img.width();
      }
    }
  }

  if ( usePict || !fitsInCache )
  {
    p->setOpacity( context.alpha() );
    const QPicture& pct = QgsSvgCache::instance()->svgAsPicture( path, size, fillColor, outlineColor, outlineWidth,
                          context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor(), context.renderContext().forceVectorOutput() );

    if ( pct.width() > 1 )
    {
      p->drawPicture( 0, 0, pct );
      hwRatio = ( double )pct.height() / ( double )pct.width();
    }
  }

  if ( context.selected() )
  {
    QPen pen( context.renderContext().selectionColor() );
    double penWidth = QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), QgsSymbolV2::MM );
    if ( penWidth > size / 20 )
    {
      // keep the pen width from covering symbol
      penWidth = size / 20;
    }
    double penOffset = penWidth / 2;
    pen.setWidth( penWidth );
    p->setPen( pen );
    p->setBrush( Qt::NoBrush );
    double wSize = size + penOffset;
    double hSize = size * hwRatio + penOffset;
    p->drawRect( QRectF( -wSize / 2.0, -hSize / 2.0, wSize, hSize ) );
  }

  p->restore();
}
예제 #14
0
void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
{
	int i, row = 0, col = 0, printed = 0, total = estimateTotalDives();
	int animationOriginal = prefs.animation_speed;

	struct dive *dive;
	if (!total)
		return;

	// disable animations on the profile:
	prefs.animation_speed = 0;

	// setup a painter
	QPainter painter;
	painter.begin(printer);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setRenderHint(QPainter::SmoothPixmapTransform);

	// setup the profile widget
	QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
	const int profileFrameStyle = profile->frameStyle();
	profile->setFrameStyle(QFrame::NoFrame);
	profile->setPrintMode(true, !printOptions->color_selected);
	profile->setFontPrintScale(divesPerRow * divesPerColumn > 3 ? 0.6 : 1.0);
	QSize originalSize = profile->size();
	// swap rows/col for landscape
	if (printer->orientation() == QPrinter::Landscape) {
		int swap = divesPerColumn;
		divesPerColumn = divesPerRow;
		divesPerRow = swap;
	}

	// padding in pixels between two dives. no padding if only one dive per page.
	const int padDef = 20;
	const int padW = (divesPerColumn < 2) ? 0 : padDef;
	const int padH = (divesPerRow < 2) ? 0 : padDef;
	// estimate dimensions for a single dive
	const int scaledW = ESTIMATE_DIVE_DIM(pageW, divesPerColumn, padW);
	const int scaledH = ESTIMATE_DIVE_DIM(pageH, divesPerRow, padH);
	// padding in pixels between profile and table
	const int padPT = 5;
	// create a model and table
	ProfilePrintModel model;
	model.setFontsize(7); // if this is changed we also need to change 'const int sr' in the constructor
	// if there is only one dive per page row we pass fitNotesToHeight to be almost half the page height
	QPointer<QTableView> table(createProfileTable(&model, scaledW, (divesPerRow == 1) ? scaledH * 0.45 : 0.0));
	// profilePrintTableMaxH updates after the table is created
	const int tableH = profilePrintTableMaxH;
	// resize the profile widget
	profile->resize(scaledW, scaledH - tableH - padPT);
	// offset table or profile on top
	int yOffsetProfile = 0, yOffsetTable = 0;
	if (printOptions->notes_up)
		yOffsetProfile = tableH + padPT;
	else
		yOffsetTable = scaledH - tableH;

	// plot the dives at specific rows and columns on the page
	for_each_dive (i, dive) {
		if (!dive->selected && printOptions->print_selected)
			continue;
		if (col == divesPerColumn) {
			col = 0;
			row++;
			if (row == divesPerRow) {
				row = 0;
				printer->newPage();
			}
		}
		// draw a profile
		QTransform origTransform = painter.transform();
		painter.translate((scaledW + padW) * col, (scaledH + padH) * row + yOffsetProfile);
		profile->plotDive(dive, true); // make sure the profile is actually redrawn
#ifdef Q_OS_LINUX // on Linux there is a vector line bug (big lines in PDF), which forces us to render to QImage
		QImage image(scaledW, scaledH - tableH - padPT, QImage::Format_ARGB32);
		QPainter imgPainter(&image);
		imgPainter.setRenderHint(QPainter::Antialiasing);
		imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
		profile->render(&imgPainter, QRect(0, 0, scaledW, scaledH - tableH - padPT));
		imgPainter.end();
		painter.drawImage(image.rect(),image);
#else // for other OS we can try rendering the profile as vector
		profile->render(&painter, QRect(0, 0, scaledW, scaledH - tableH - padPT));
#endif
		painter.setTransform(origTransform);

		// draw a table
		QPicture pic;
		QPainter picPainter;
		painter.translate((scaledW + padW) * col, (scaledH + padH) * row + yOffsetTable);
		model.setDive(dive);
		picPainter.begin(&pic);
		table->render(&picPainter);
		picPainter.end();
		painter.drawPicture(QPoint(0,0), pic);
		painter.setTransform(origTransform);
		col++;
		printed++;
		emit signalProgress((printed * 100) / total);
	}
	// cleanup
	painter.end();
	profile->setFrameStyle(profileFrameStyle);
	profile->setPrintMode(false);
	profile->resize(originalSize);
	// we need to force a redraw of the profile so it switches back from print mode
	profile->plotDive(0, true);
	// re-enable animations
	prefs.animation_speed = animationOriginal;
}
예제 #15
0
void CGContextDrawLayerAtPoint(CGContextRef context, CGPoint point, CGLayerRef layer)
{
	QPainter* painter = CGContextGetPainter(context);
	painter->drawPicture(QPointF(point.x, point.y), *layer->picture);
}
void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
  QPainter* p = context.renderContext().painter();
  if ( !p )
  {
    return;
  }

  double size = context.outputLineWidth( mSize );
  //don't render symbols with size below one or above 10,000 pixels
  if (( int )size < 1 || 10000.0 < size )
  {
    return;
  }

  p->save();
  QPointF outputOffset = QPointF( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
  if ( mAngle )
    outputOffset = _rotatedOffset( outputOffset, mAngle );
  p->translate( point + outputOffset );

  bool rotated = !doubleNear( mAngle, 0 );
  bool drawOnScreen = doubleNear( context.renderContext().rasterScaleFactor(), 1.0, 0.1 );
  if ( rotated )
    p->rotate( mAngle );

  bool fitsInCache = true;
  bool usePict = true;
  double hwRatio = 1.0;
  if ( drawOnScreen && !rotated )
  {
    usePict = false;
    const QImage& img = QgsSvgCache::instance()->svgAsImage( mPath, size, mFillColor, mOutlineColor, mOutlineWidth,
                        context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor(), fitsInCache );
    if ( fitsInCache && img.width() > 1 )
    {
      //consider transparency
      if ( !doubleNear( context.alpha(), 1.0 ) )
      {
        QImage transparentImage = img.copy();
        QgsSymbolLayerV2Utils::multiplyImageOpacity( &transparentImage, context.alpha() );
        p->drawImage( -transparentImage.width() / 2.0, -transparentImage.height() / 2.0, transparentImage );
        hwRatio = ( double )transparentImage.height() / ( double )transparentImage.width();
      }
      else
      {
        p->drawImage( -img.width() / 2.0, -img.height() / 2.0, img );
        hwRatio = ( double )img.height() / ( double )img.width();
      }
    }
  }

  if ( usePict || !fitsInCache )
  {
    p->setOpacity( context.alpha() );
    const QPicture& pct = QgsSvgCache::instance()->svgAsPicture( mPath, size, mFillColor, mOutlineColor, mOutlineWidth,
                          context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor() );

    if ( pct.width() > 1 )
    {
      p->drawPicture( 0, 0, pct );
      hwRatio = ( double )pct.height() / ( double )pct.width();
    }
  }

  if ( context.selected() )
  {
    QPen pen( context.selectionColor() );
    double penWidth = context.outputLineWidth( 1.0 );
    if ( penWidth > size / 20 )
    {
      // keep the pen width from covering symbol
      penWidth = size / 20;
    }
    double penOffset = penWidth / 2;
    pen.setWidth( penWidth );
    p->setPen( pen );
    p->setBrush( Qt::NoBrush );
    double wSize = size + penOffset;
    double hSize = size * hwRatio + penOffset;
    p->drawRect( QRectF( -wSize / 2.0, -hSize / 2.0, wSize, hSize ) );
  }

  p->restore();
}