本文整理汇总了C++中QPainter::save方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::save方法的具体用法?C++ QPainter::save怎么用?C++ QPainter::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawPoints
/*!
Draws the first \a pointCount points in the buffer \a points
*/
void QPaintEngine::drawPoints(const QPointF *points, int pointCount)
{
QPainter *p = painter();
if (!p)
return;
qreal penWidth = p->pen().widthF();
if (penWidth == 0)
penWidth = 1;
bool ellipses = p->pen().capStyle() == Qt::RoundCap;
p->save();
QTransform transform;
if (p->pen().isCosmetic()) {
transform = p->transform();
p->setTransform(QTransform());
}
p->setBrush(p->pen().brush());
p->setPen(Qt::NoPen);
for (int i=0; i<pointCount; ++i) {
QPointF pos = transform.map(points[i]);
QRectF rect(pos.x() - penWidth / 2, pos.y() - penWidth / 2, penWidth, penWidth);
if (ellipses)
p->drawEllipse(rect);
else
p->drawRect(rect);
}
p->restore();
}
示例2: paintEvent
void Canvas::paintEvent(QPaintEvent *e)
{
QPainter *p = new QPainter(this);
QPen pen(QColor(0,0,0,255));
qreal curangle = 0.0;
if(p->isActive()){
p->setRenderHint(QPainter::Antialiasing);
pen.setWidth(1);
p->setPen(pen);
p->save();
pen.setColor(QColor(255,0,0,255));
p->setPen(pen);
foreach(qreal v, _values){
qreal span = (5760.0 / _valueSum) * v;
cout << "Value: " << v << " (sum="<<_valueSum<<") , span = " << span << "/5760, curangle = " << curangle;
p->drawPie(rect(), curangle, span);
curangle += span;
cout << ", newangle = " << curangle << endl;
}
示例3: drawBoxTextItem
void QPaintEnginePrivate::drawBoxTextItem(const QPointF &p, const QTextItemInt &ti)
{
if (!ti.glyphs.numGlyphs)
return;
// any fixes here should probably also be done in QFontEngineBox::draw
const int size = qRound(ti.fontEngine->ascent());
QVarLengthArray<QFixedPoint> positions;
QVarLengthArray<glyph_t> glyphs;
QTransform matrix = QTransform::fromTranslate(p.x(), p.y() - size);
ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
if (glyphs.size() == 0)
return;
QSize s(size - 3, size - 3);
QPainter *painter = q_func()->state->painter();
painter->save();
painter->setBrush(Qt::NoBrush);
QPen pen = painter->pen();
pen.setWidthF(ti.fontEngine->lineThickness().toReal());
painter->setPen(pen);
for (int k = 0; k < positions.size(); k++)
painter->drawRect(QRectF(positions[k].toPointF(), s));
painter->restore();
}
示例4: PaintHistogram
void QmitkTransferFunctionCanvas::PaintHistogram(QPainter &p)
{
if (m_Histogram)
{
p.save();
p.setPen(Qt::gray);
int displayWidth = contentsRect().width();
int displayHeight = contentsRect().height();
double windowLeft = m_Lower;
double windowRight = m_Upper;
double step = (windowRight - windowLeft) / double(displayWidth);
double pos = windowLeft;
for (int x = 0; x < displayWidth; x++)
{
double left = pos;
double right = pos + step;
float height = m_Histogram->GetRelativeBin(left, right);
if (height >= 0)
p.drawLine(x, displayHeight * (1 - height), x, displayHeight);
pos += step;
}
p.restore();
}
}
示例5: render
void QgsAnnotation::render( QgsRenderContext &context ) const
{
QPainter *painter = context.painter();
if ( !painter )
{
return;
}
painter->save();
drawFrame( context );
if ( mHasFixedMapPosition )
{
drawMarkerSymbol( context );
}
if ( mHasFixedMapPosition )
{
painter->translate( mOffsetFromReferencePoint.x() + context.convertToPainterUnits( mContentsMargins.left(), QgsUnitTypes::RenderMillimeters ),
mOffsetFromReferencePoint.y() + context.convertToPainterUnits( mContentsMargins.top(), QgsUnitTypes::RenderMillimeters ) );
}
else
{
painter->translate( context.convertToPainterUnits( mContentsMargins.left(), QgsUnitTypes::RenderMillimeters ),
context.convertToPainterUnits( mContentsMargins.top(), QgsUnitTypes::RenderMillimeters ) );
}
QSizeF size( mFrameSize.width() - context.convertToPainterUnits( mContentsMargins.left() + mContentsMargins.right(), QgsUnitTypes::RenderMillimeters ),
mFrameSize.height() - context.convertToPainterUnits( mContentsMargins.top() + mContentsMargins.bottom(), QgsUnitTypes::RenderMillimeters ) );
renderAnnotation( context, size );
painter->restore();
}
示例6: QPointF
void QgsFontMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
QPainter* p = context.renderContext().painter();
QColor penColor = context.selected() ? context.selectionColor() : mColor;
penColor.setAlphaF( context.alpha() );
p->setPen( penColor );
p->setFont( mFont );
p->save();
QPointF outputOffset = QPointF( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
if ( mAngle )
outputOffset = _rotatedOffset( outputOffset, mAngle );
p->translate( point + outputOffset );
if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
{
double s = mSize / mOrigSize;
p->scale( s, s );
}
if ( mAngle != 0 )
p->rotate( mAngle );
p->drawText( -mChrOffset, mChr );
p->restore();
}
示例7: drawNodes
/**
* @brief Draw all the nodes generated in the RRT algorithm.
* @param painter
*/
void RenderArea::drawNodes(QPainter &painter)
{
painter.save();
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::black);
painter.setBrush(QBrush(Qt::black));
Vector2f pos;
for(int i = 0; i < (int)rrt->nodes.size(); i++) {
for(int j = 0; j < (int)rrt->nodes[i]->children.size(); j++) {
pos = rrt->nodes[i]->children[j]->position;
painter.drawEllipse(pos.x()-1.5, pos.y()-1.5, 3, 3);
}
pos = rrt->nodes[i]->position;
painter.drawEllipse(pos.x() - NODE_RADIUS, pos.y() - NODE_RADIUS, 2 * NODE_RADIUS, 2 * NODE_RADIUS);
}
painter.setPen(Qt::red);
painter.setBrush(QBrush(Qt::red));
// if a path exists, draw it.
for(int i = 0; i < (int)rrt->path.size() - 1; i++) {
QPointF p1(rrt->path[i]->position.x(), rrt->path[i]->position.y());
QPointF p2(rrt->path[i+1]->position.x(), rrt->path[i+1]->position.y());
painter.drawLine(p1, p2);
}
painter.restore();
}
示例8: renderFromTiledBackingStore
void QWebFramePrivate::renderFromTiledBackingStore(GraphicsContext* context, const QRegion& clip)
{
ASSERT(frame->tiledBackingStore());
if (!frame->view() || !frame->contentRenderer())
return;
QVector<QRect> vector = clip.rects();
if (vector.isEmpty())
return;
QPainter* painter = context->platformContext();
WebCore::FrameView* view = frame->view();
int scrollX = view->scrollX();
int scrollY = view->scrollY();
context->translate(-scrollX, -scrollY);
for (int i = 0; i < vector.size(); ++i) {
const QRect& clipRect = vector.at(i);
painter->save();
QRect rect = clipRect.translated(scrollX, scrollY);
painter->setClipRect(rect, Qt::IntersectClip);
frame->tiledBackingStore()->paint(context, rect);
painter->restore();
}
}
示例9: render
void TextRenderable::render(QPainter &painter, const RenderConfig &config) const
{
painter.save();
bool disable_antialiasing = config.options.testFlag(RenderConfig::Screen) && !(Settings::getInstance().getSettingCached(Settings::MapDisplay_TextAntialiasing).toBool());
if (disable_antialiasing)
{
painter.setRenderHint(QPainter::Antialiasing, false);
painter.setRenderHint(QPainter::TextAntialiasing, false);
}
if (framing_line)
{
QPen pen(painter.pen());
pen.setJoinStyle(Qt::MiterJoin);
pen.setMiterLimit(0.5);
painter.setPen(pen);
}
painter.translate(anchor_x, anchor_y);
if (rotation != 0)
painter.rotate(-rotation * 180 / M_PI);
painter.scale(scale_factor, scale_factor);
painter.drawPath(path);
painter.restore();
}
示例10: draw
void QgsDoubleBoxScaleBarRenderer::draw( QgsRenderContext &context, const QgsScaleBarSettings &settings, const ScaleBarContext &scaleContext ) const
{
if ( !context.painter() )
{
return;
}
QPainter *painter = context.painter();
double barTopPosition = QgsComposerUtils::fontAscentMM( settings.font() ) + settings.labelBarSpace() + settings.boxContentSpace();
double segmentHeight = settings.height() / 2;
painter->save();
if ( context.flags() & QgsRenderContext::Antialiasing )
painter->setRenderHint( QPainter::Antialiasing, true );
painter->setPen( settings.pen() );
bool useColor = true; //alternate brush color/white
double xOffset = firstLabelXOffset( settings );
QList<double> positions = segmentPositions( scaleContext, settings );
QList<double> widths = segmentWidths( scaleContext, settings );
for ( int i = 0; i < positions.size(); ++i )
{
//draw top half
if ( useColor )
{
painter->setBrush( settings.brush() );
}
else //secondary color
{
painter->setBrush( settings.brush2() );
}
QRectF segmentRectTop( positions.at( i ) + xOffset, barTopPosition, widths.at( i ), segmentHeight );
painter->drawRect( segmentRectTop );
//draw bottom half
if ( useColor )
{
//secondary color
painter->setBrush( settings.brush2() );
}
else //primary color
{
painter->setBrush( settings.brush() );
}
QRectF segmentRectBottom( positions.at( i ) + xOffset, barTopPosition + segmentHeight, widths.at( i ), segmentHeight );
painter->drawRect( segmentRectBottom );
useColor = !useColor;
}
painter->restore();
//draw labels using the default method
drawDefaultLabels( context, settings, scaleContext );
}
示例11: drawFocusRect
void Template::drawFocusRect( QPainter& p)
{
p.save();
p.setBrush( QBrush::NoBrush );
p.setPen( QPen( QColor( 100, 100, 100 ), 2, QPen::DotLine ) );
p.drawRect( d->focusRect );
p.restore();
}
示例12: QPaintEvent
void Spectrum1DWidget::saveAsImage()
{
QString file_name = QFileDialog::getSaveFileName(this, "Save File", "", "Raster images *.bmp *.png *.jpg *.gif (*.bmp *.png *.jpg *.gif);;Vector images *.svg (*.svg)");
bool x_visible = x_scrollbar_->isVisible();
bool y_visible = y_scrollbar_->isVisible();
x_scrollbar_->hide();
y_scrollbar_->hide();
if (file_name.contains(".svg", Qt::CaseInsensitive)) // svg vector format
{
QSvgGenerator generator;
generator.setFileName(file_name);
generator.setSize(QSize(this->width(), this->height()));
generator.setViewBox(QRect(0, 0, this->width() - 1, this->height() - 1));
generator.setTitle(file_name);
generator.setDescription("TOPPView generated SVG");
QPainter painter;
painter.begin(&generator);
painter.save();
painter.translate(QPoint(y_axis_->pos()));
y_axis_->paint(&painter, new QPaintEvent(y_axis_->contentsRect()));
painter.restore();
painter.save();
painter.translate(QPoint(canvas_->pos()));
dynamic_cast<Spectrum1DCanvas*>(canvas_)->paint(&painter, new QPaintEvent(canvas_->contentsRect()));
painter.restore();
painter.save();
painter.translate(QPoint(x_axis_->pos()));
x_axis_->paint(&painter, new QPaintEvent(x_axis_->contentsRect()));
painter.restore();
painter.end();
x_scrollbar_->setVisible(x_visible);
y_scrollbar_->setVisible(y_visible);
}
else // raster graphics formats
{
QPixmap pixmap = QPixmap::grabWidget(this);
x_scrollbar_->setVisible(x_visible);
y_scrollbar_->setVisible(y_visible);
pixmap.save(file_name);
}
}
示例13: paint
void KoFormulaShape::paint( QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &)
{
painter.save();
applyConversion( painter, converter ); // apply zooming and coordinate translation
m_formulaRenderer->layoutElement( m_formulaData->formulaElement() );
m_formulaRenderer->paintElement( painter, m_formulaData->formulaElement() ); // paint the formula
painter.restore();
}
示例14: draw
void RectangleMaker::draw(QPainter &painter) const
{
if( m_rectangle ){
painter.save();
m_rectangle->draw(painter);
painter.restore();
}
}
示例15: rotatePixmap
void QgsDecorationNorthArrowDialog::rotatePixmap( int theRotationInt )
{
QPixmap myQPixmap;
QString myFileNameQString = ":/images/north_arrows/default.png";
// QgsDebugMsg(QString("Trying to load %1").arg(myFileNameQString));
if ( myQPixmap.load( myFileNameQString ) )
{
QPixmap myPainterPixmap( myQPixmap.height(), myQPixmap.width() );
myPainterPixmap.fill();
QPainter myQPainter;
myQPainter.begin( &myPainterPixmap );
myQPainter.setRenderHint( QPainter::SmoothPixmapTransform );
double centerXDouble = myQPixmap.width() / 2.0;
double centerYDouble = myQPixmap.height() / 2.0;
//save the current canvas rotation
myQPainter.save();
//myQPainter.translate( (int)centerXDouble, (int)centerYDouble );
//rotate the canvas
myQPainter.rotate( theRotationInt );
//work out how to shift the image so that it appears in the center of the canvas
//(x cos a + y sin a - x, -x sin a + y cos a - y)
const double PI = 3.14159265358979323846;
double myRadiansDouble = ( PI / 180 ) * theRotationInt;
int xShift = static_cast<int>((
( centerXDouble * cos( myRadiansDouble ) ) +
( centerYDouble * sin( myRadiansDouble ) )
) - centerXDouble );
int yShift = static_cast<int>((
( -centerXDouble * sin( myRadiansDouble ) ) +
( centerYDouble * cos( myRadiansDouble ) )
) - centerYDouble );
//draw the pixmap in the proper position
myQPainter.drawPixmap( xShift, yShift, myQPixmap );
//unrotate the canvas again
myQPainter.restore();
myQPainter.end();
pixmapLabel->setPixmap( myPainterPixmap );
}
else
{
QPixmap myPainterPixmap( 200, 200 );
myPainterPixmap.fill();
QPainter myQPainter;
myQPainter.begin( &myPainterPixmap );
QFont myQFont( "time", 12, QFont::Bold );
myQPainter.setFont( myQFont );
myQPainter.setPen( Qt::red );
myQPainter.drawText( 10, 20, tr( "Pixmap not found" ) );
myQPainter.end();
pixmapLabel->setPixmap( myPainterPixmap );
}
}