本文整理汇总了C++中QPainter::drawPicture方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::drawPicture方法的具体用法?C++ QPainter::drawPicture怎么用?C++ QPainter::drawPicture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::drawPicture方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawSource
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: paintEvent
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: paintPage
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: qDebug
/** 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: CGContextDrawLayerInRect
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: paintTest
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) );
}
示例7: save_restore
/* 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() );
}
示例8: saveData
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;
}
示例9: draw
//.........这里部分代码省略.........
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);
}
示例10: outputOffset
//.........这里部分代码省略.........
{
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();
}
示例11: printProfileDives
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);
}
//.........这里部分代码省略.........
示例12: CGContextDrawLayerAtPoint
void CGContextDrawLayerAtPoint(CGContextRef context, CGPoint point, CGLayerRef layer)
{
QPainter* painter = CGContextGetPainter(context);
painter->drawPicture(QPointF(point.x, point.y), *layer->picture);
}
示例13: pen
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();
}