当前位置: 首页>>代码示例>>C++>>正文


C++ QPainter::translate方法代码示例

本文整理汇总了C++中QPainter::translate方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::translate方法的具体用法?C++ QPainter::translate怎么用?C++ QPainter::translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QPainter的用法示例。


在下文中一共展示了QPainter::translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: drawPicker

void ColorWheel::drawPicker(QPainter &painter) {
    painter.save();
    painter.setBrush(Qt::NoBrush);
    QPen pen;
    // region of the widget
    int w = qMin(width(), height());
    qreal r = w/2-margin_; // radius of outer circle
    qreal ir = r-wheelWidth_; // radius of inner circle
    qreal m = w/2.0-ir/qSqrt(2); // left corner of square
    painter.translate(m-5, m-5);
    qreal SquareWidth = 2*ir/qSqrt(2);
    qreal S = currentColor_.saturationF()*SquareWidth;
    qreal V = currentColor_.valueF()*SquareWidth;

    if (currentColor_.saturation() > 30 || currentColor_.value() < 50)
        pen.setColor(Qt::white);

    pen.setWidth(2);
    pen.setCosmetic(true);
    painter.setPen(pen);
    painter.drawEllipse(S,V,10,10);
    painter.restore();
}
开发者ID:sarbi127,项目名称:inviwo,代码行数:23,代码来源:colorwheel.cpp

示例2: 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() );
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:28,代码来源:tst_qpicture.cpp

示例3: draw

//графика____________________________________________________________________
void RectWgt::draw()
{
    pPix=new QPixmap(230,230);
    QPainter painter;
    painter.begin(pPix);
    painter.setRenderHint(QPainter::Antialiasing,true);
    painter.setPen(QPen(Qt::black,2,Qt::SolidLine));
    double scale=(pHL->text().toDouble()>pWL->text().toDouble())?(200/pHL->text().toDouble()):200/pWL->text().toDouble();
    painter.translate((115.0-scale*(pWL->text().toDouble()/2)),(115.0-scale*(pHL->text().toDouble()/2)));
    painter.setClipRect(0.0,((pHL->text().toDouble()-phL->text().toDouble())*scale),
                        scale*pWL->text().toDouble(),phL->text().toDouble()*scale);
    painter.save();
    painter.setPen(Qt::NoPen);
    QLinearGradient gradient(scale*pWL->text().toDouble()/2,((pHL->text().toDouble()-phL->text().toDouble())*scale),
                             scale*pWL->text().toDouble()/2,scale*pHL->text().toDouble());
    gradient.setColorAt(0,Qt::blue);
    gradient.setColorAt(1,Qt::darkBlue);
    painter.setBrush(gradient);

    painter.drawRect(0,0,scale*pWL->text().toDouble(),scale*pHL->text().toDouble());
    painter.setClipping(false);
    painter.restore();

    QPointF points[4]=
    {
        QPointF(0.0,0.0),
        QPointF(0.0,scale*pHL->text().toDouble()),
        QPointF(scale*pWL->text().toDouble(),scale*pHL->text().toDouble()),
        QPointF(scale*pWL->text().toDouble(),0.0)
    };
    painter.drawPolyline(points,4);
    painter.drawLine(0.0,((pHL->text().toDouble()-phL->text().toDouble())*scale),
                     (scale*pWL->text().toDouble()),((pHL->text().toDouble()-phL->text().toDouble())*scale));
    painter.end();
    pPixLbl->setPixmap(*pPix);

}
开发者ID:Bi-do-mi,项目名称:HydroCalc,代码行数:38,代码来源:rectwgt.cpp

示例4: drawBuffer

//バッファの再描画
//渡される無効エリアの座標はコンテンツ座標系
void SXBSchView::drawBuffer(int x,int y,int clipx,int clipy, int clipw, int cliph )
{
    //    qDebug("SXBSchView::drawBuffer\n");
    QPainter painter;
    QRect rcClip = QRect(clipx,clipy,clipw,cliph);
    QRect rcClipSheet = ContentsToSheet(rcClip);
    SRect srcClipSheet =SRect(rcClipSheet.left(),rcClipSheet.top(),rcClipSheet.width(),rcClipSheet.height());
    //qDebug() << m_viewBuffer.size();
    painter.begin(&m_viewBuffer);
    painter.setRenderHint(QPainter::TextAntialiasing);

    painter.translate(-x,-y);
    painter.eraseRect(clipx,clipy,clipw,cliph);

    //    painter.setClipping(true);
    clipx -= x;
    clipy -= y;
    //    painter.setClipRect(clipx,clipy,clipw,cliph);
    SSize size = m_pDoc->SheetSize();
    g_drawFrame(&painter,size,rcClip,QColor("#7E2020"),m_viewScale,m_viewScaleMul);
    if(m_bDisplayGrid) {
        drawGrid(&painter,rcClipSheet,QColor("#FC4343"));
    }
    drawMainXBSchObj(&painter,DRAW_ON,&srcClipSheet,m_fEditHighLight, m_viewScale,m_viewScaleMul);

    if((m_moveOption == MOVE_OPTION_COMPONENT_NAME)  || (m_moveOption == MOVE_OPTION_COMPONENT_NUM)) {
        int modeOption = 0;
        if(m_moveOption == MOVE_OPTION_COMPONENT_NAME) {
            modeOption = DRAW_INH_PARTNAME;
        } else {
            modeOption = DRAW_INH_PARTNUM;
        }
        drawTempXBSchObj(&painter,DRAW_TEMP|modeOption,&srcClipSheet);
    }

    painter.end();
}
开发者ID:hermixy,项目名称:Qt-BSch3V-Modified,代码行数:39,代码来源:xbschdrawobject.cpp

示例5: timerEvent

void myscroll::timerEvent(QTimerEvent *)
{
    QRegion exposed;
    p1->scroll(-1,0,p1->rect(), &exposed);
    QPainter painter;

    save.setX(save.x()-1);
    now.setY(qrand()%20+300);
    painter.begin(p1);
    painter.setPen(Qt::red);
    painter.drawLine(save,now);
    save = now;
    painter.drawLine(0,400,400,400);
    painter.drawLine(0,200,0,400);
    for(int i=0; i<200; i++)
    {
        if(!(i%10))
        {
            painter.drawLine(0,400-i,3,400-i);
        }
    }
//  painter.drawPoint(299,310);

    if(!(i%50))
    {
        painter.translate(400,400);
        painter.rotate(-15);
        painter.setRenderHint(QPainter::Antialiasing,true);
        painter.setPen(QPen(Qt::red, 2, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin));
        painter.drawLine(0,0,0,5);
        str.setNum(i);
        painter.drawText(QRectF(-10,0,30,50),Qt::AlignCenter,str);
    }
    i++;

    update();
}
开发者ID:fengyikil,项目名称:qt_from0,代码行数:37,代码来源:myscroll.cpp

示例6: createPairIcon

QIcon SCgAlphabet::createPairIcon(const QSize &size, QString type)
{
    QIcon icon;

    SCgPair *pair = new SCgPair;
    pair->setTypeAlias(type);

    QVector<QPointF> points;
    points.push_back(QPointF(-size.width() / 2.f, 0.f));
    points.push_back(QPointF(size.width() / 2.f, 0.f));

    pair->setPoints(points);

    QPixmap pixmap(size);
    QPainter painter;

    pixmap.fill(Qt::transparent);

    painter.begin(&pixmap);
    painter.setRenderHint(QPainter::Antialiasing, true);
    pair->setColor(QColor(0, 0, 0, 255));//(state == QIcon::On) ? 255 : 128));

    painter.translate(size.width() / 2.f, size.height() / 2.f);
    painter.scale(0.9f, 0.9f);

    paintPair(&painter, pair);

    painter.end();

    for (int mode = QIcon::Normal; mode <= QIcon::Selected; mode++)
        for (int state = QIcon::On; state <= QIcon::Off; state++)
            icon.addPixmap(pixmap, (QIcon::Mode)mode, (QIcon::State)state);

    delete pair;

    return icon;
}
开发者ID:AlexKlybik,项目名称:kbe,代码行数:37,代码来源:scgalphabet.cpp

示例7: paintExplodedLabels

void RadialMap::Widget::paintEvent(QPaintEvent*)
{
    QPainter paint;
    paint.begin(this);

    if (!m_map.isNull())
        paint.drawPixmap(m_offset, m_map.pixmap());
    else
    {
        paint.drawText(rect(), 0, i18nc("We messed up, the user needs to initiate a rescan.", "Internal representation is invalid,\nplease rescan."));
        return;
    }

    //exploded labels
    if (!m_map.isNull() && !m_timer.isActive())
    {
        if (Config::antialias) {
            paint.setRenderHint(QPainter::Antialiasing);
            //make lines appear on pixel boundaries
            paint.translate(0.5, 0.5);
        }
        paintExplodedLabels(paint);
    }
}
开发者ID:KDE,项目名称:filelight,代码行数:24,代码来源:widgetEvents.cpp

示例8: drawComplexText

void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const
{
    if (to < 0)
        to = run.length();

    QPainter *p = ctx->platformContext();

    if (ctx->textDrawingMode() & cTextFill) {
        if (ctx->fillGradient()) {
            QBrush brush(*ctx->fillGradient()->platformGradient());
            brush.setTransform(ctx->fillGradient()->gradientSpaceTransform());
            p->setPen(QPen(brush, 0));
        } else if (ctx->fillPattern()) {
            TransformationMatrix affine;
            p->setPen(QPen(QBrush(ctx->fillPattern()->createPlatformPattern(affine)), 0));
        } else
            p->setPen(QColor(ctx->fillColor()));
    }

    if (ctx->textDrawingMode() & cTextStroke) {
        if (ctx->strokeGradient()) {
            QBrush brush(*ctx->strokeGradient()->platformGradient());
            brush.setTransform(ctx->strokeGradient()->gradientSpaceTransform());
            p->setPen(QPen(brush, ctx->strokeThickness()));
        } else if (ctx->strokePattern()) {
            TransformationMatrix affine;
            p->setPen(QPen(QBrush(ctx->strokePattern()->createPlatformPattern(affine)), ctx->strokeThickness()));
        } else
            p->setPen(QPen(QColor(ctx->strokeColor()), ctx->strokeThickness()));
    }

    const QString string = fixSpacing(qstring(run));

    // text shadow
    IntSize shadowSize;
    int shadowBlur;
    Color shadowColor;
    bool hasShadow = ctx->textDrawingMode() == cTextFill && ctx->getShadow(shadowSize, shadowBlur, shadowColor);

    if (from > 0 || to < run.length()) {
        QTextLayout layout(string, font());
        QTextLine line = setupLayout(&layout, run);
        float x1 = line.cursorToX(from);
        float x2 = line.cursorToX(to);
        if (x2 < x1)
            qSwap(x1, x2);

        QFontMetrics fm(font());
        int ascent = fm.ascent();
        QRectF clip(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());

        if (hasShadow) {
            // TODO: when blur support is added, the clip will need to account
            // for the blur radius
            qreal dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
            if (shadowSize.width() > 0)
                dx2 = shadowSize.width();
            else
                dx1 = -shadowSize.width();
            if (shadowSize.height() > 0)
                dy2 = shadowSize.height();
            else
                dy1 = -shadowSize.height();
            // expand the clip rect to include the text shadow as well
            clip.adjust(dx1, dx2, dy1, dy2);
        }
        p->save();
        p->setClipRect(clip.toRect());
        QPointF pt(point.x(), point.y() - ascent);
        if (hasShadow) {
            p->save();
            p->setPen(QColor(shadowColor));
            p->translate(shadowSize.width(), shadowSize.height());
            line.draw(p, pt);
            p->restore();
        }
        line.draw(p, pt);
        p->restore();
        return;
    }

    p->setFont(font());

    QPointF pt(point.x(), point.y());
    int flags = run.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight;
    if (hasShadow) {
        // TODO: text shadow blur support
        p->save();
        p->setPen(QColor(shadowColor));
        p->translate(shadowSize.width(), shadowSize.height());
        p->drawText(pt, string, flags, run.padding());
        p->restore();
    }
    if (ctx->textDrawingMode() & cTextStroke) {
        QPainterPath path;
        path.addText(pt, font(), string);
        p->strokePath(path, p->pen());
    }
    if (ctx->textDrawingMode() & cTextFill)
        p->drawText(pt, string, flags, run.padding());
//.........这里部分代码省略.........
开发者ID:flying-dutchmen,项目名称:3DS_w3Browser,代码行数:101,代码来源:FontQt.cpp

示例9: paintEvent

void LightMaps::paintEvent(QPaintEvent *event)
{
    QPainter p;
    p.begin(this);
    m_normalMap->render(&p, event->rect());
    p.setPen(Qt::black);
    p.drawText(rect(),  Qt::AlignBottom | Qt::TextWordWrap,
                "Map data CCBYSA 2009 OpenStreetMap.org contributors");
    p.end();

    if (zoomed) {
        int dim = qMin(width(), height());
        int magnifierSize = qMin(MAX_MAGNIFIER, dim * 2 / 3);
        int radius = magnifierSize / 2;
        int ring = radius - 15;
        QSize box = QSize(magnifierSize, magnifierSize);

        // reupdate our mask
        if (maskPixmap.size() != box) {
            maskPixmap = QPixmap(box);
            maskPixmap.fill(Qt::transparent);

            QRadialGradient g;
            g.setCenter(radius, radius);
            g.setFocalPoint(radius, radius);
            g.setRadius(radius);
            g.setColorAt(1.0, QColor(255, 255, 255, 0));
            g.setColorAt(0.5, QColor(128, 128, 128, 255));

            QPainter mask(&maskPixmap);
            mask.setRenderHint(QPainter::Antialiasing);
            mask.setCompositionMode(QPainter::CompositionMode_Source);
            mask.setBrush(g);
            mask.setPen(Qt::NoPen);
            mask.drawRect(maskPixmap.rect());
            mask.setBrush(QColor(Qt::transparent));
            mask.drawEllipse(g.center(), ring, ring);
            mask.end();
        }

        QPoint center = dragPos - QPoint(0, radius);
        center = center + QPoint(0, radius / 2);
        QPoint corner = center - QPoint(radius, radius);

        QPoint xy = center * 2 - QPoint(radius, radius);

        // only set the dimension to the magnified portion
        if (zoomPixmap.size() != box) {
            zoomPixmap = QPixmap(box);
            zoomPixmap.fill(Qt::lightGray);
        }
        if (true) {
            QPainter p(&zoomPixmap);
            p.translate(-xy);
            m_largeMap->render(&p, QRect(xy, box));
            p.end();
        }

        QPainterPath clipPath;
        clipPath.addEllipse(center, ring, ring);

        QPainter p(this);
        p.setRenderHint(QPainter::Antialiasing);
        p.setClipPath(clipPath);
        p.drawPixmap(corner, zoomPixmap);
        p.setClipping(false);
        p.drawPixmap(corner, maskPixmap);
        p.setPen(Qt::gray);
        p.drawPath(clipPath);
    }
    if (invert) {
        QPainter p(this);
        p.setCompositionMode(QPainter::CompositionMode_Difference);
        p.fillRect(event->rect(), Qt::white);
        p.end();
    }
}
开发者ID:CodeDJ,项目名称:qt5-hidpi,代码行数:77,代码来源:lightmaps.cpp

示例10: paintEvent

void RCDraw::paintEvent ( QPaintEvent * )
{
	QString s;
	QPainter painter ( this );
	painter.setRenderHint(QPainter::HighQualityAntialiasing);

	if ( qimg != NULL )
	{
		painter.drawImage ( QRectF(0., 0., imageScale*width, imageScale*height), *qimg, QRectF(0, 0, width, height) );
	}

	painter.setWindow (effWin.toRect() );

	if ( DRAW_PERIMETER )
	{
		painter.setPen ( Qt::blue );
		painter.drawRect ( 0,0,width-1,height-1 );
	}
	if ( DRAW_AXIS )
	{
		drawAxis(Qt::blue, 2);
	}

	//Draw lines
	while ( !lineQueue.isEmpty() )
	{
		TLine l = lineQueue.dequeue();
		if (invertedVerticalAxis) l.line = QLineF(l.line.x1()-visibleCenter(0), -l.line.y1()+visibleCenter(1), l.line.x2()-visibleCenter(0), -l.line.y2()+visibleCenter(1));
		else l.line.translate(-visibleCenter(0), -visibleCenter(1));
		painter.setPen ( QPen ( QBrush ( l.color ),l.width ) );
		painter.drawLine ( l.line );
	}

	//Draw gradient
	while ( !gradQueue.isEmpty() )
	{
		TGrad g = gradQueue.dequeue();
		if (invertedVerticalAxis) g.line = QLine(g.line.x1()-visibleCenter(0), -g.line.y1()+visibleCenter(1), g.line.x2()-visibleCenter(0), -g.line.y2()+visibleCenter(1));
		else g.line.translate(-visibleCenter(0), -visibleCenter(1));
		linGrad.setColorAt ( 0, g.color );
		linGrad.setColorAt ( 1, g.color1 );
		painter.setBrush ( linGrad );
		painter.setPen ( QPen ( linGrad, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
		painter.drawLine ( g.line );
	}

	//Draw ellipses
	while ( !ellipseQueue.isEmpty() )
	{
		TEllipse e = ellipseQueue.dequeue();
		if (invertedVerticalAxis) e.center.setY(-(e.center.y()-visibleCenter(1)));
		else e.center = QPointF(e.center.x()-visibleCenter(0), e.center.y()-visibleCenter(1));
		if ( e.fill == true )
			painter.setBrush ( e.color );
		else
			painter.setBrush ( Qt::transparent );
		painter.setPen ( e.color );
		if (fabs(e.ang) > 0.1)
		{
			painter.setPen ( e.color );
			painter.translate( e.center );
			painter.rotate( e.ang );
			painter.drawEllipse ( QPointF(0,0), e.rx, e.ry );
			painter.rotate( -e.ang );
			painter.translate( -e.center );
		}
		else
			painter.drawEllipse( e.center, e.rx, e.ry);
	}

	//Draw squares
	{
		QPen pen = painter.pen();
		int penwidth = pen.width();
		while ( !squareQueue.isEmpty() )
		{
			TRect r = squareQueue.dequeue();
			if (invertedVerticalAxis) r.rect = QRect(r.rect.x()-visibleCenter(0), -r.rect.y()+visibleCenter(1)-r.rect.height(), r.rect.width(), r.rect.height());
			else r.rect.translate(-visibleCenter(0),-visibleCenter(1));
			if ( r.fill == true )
				painter.setBrush ( r.color );
			else
				painter.setBrush ( Qt::transparent );
			pen.setColor(r.color);
			pen.setWidth(r.width);
			painter.setPen(pen);
			if (fabs(r.ang) > 0.01 )
			{
				QPointF center = r.rect.center();
				painter.translate( center );
				painter.rotate( r.ang );
				painter.drawRect ( QRectF( r.rect.topLeft() - center, r.rect.size() ));
				painter.rotate( -r.ang );
				painter.translate( -center );
			}
			else
				painter.drawRect( r.rect );
		}
		pen.setWidth(penwidth);
		painter.setPen(pen);
//.........这里部分代码省略.........
开发者ID:BasilMVarghese,项目名称:robocomp,代码行数:101,代码来源:rcdraw.cpp

示例11: textDocRect

void KDReports::ReportPrivate::paintPage( int pageNumber, QPainter& painter )
{
    ensureLayouted();

    const int pageCount = m_layout->numberOfPages();
    KDReports::Header* header = m_headers.headerForPage( pageNumber + 1, pageCount );
    if ( header ) {
        header->preparePaintingPage( pageNumber + m_firstPageNumber - 1 );
    }
    KDReports::Header* footer = m_footers.headerForPage( pageNumber + 1, pageCount );
    if ( footer ) {
        footer->preparePaintingPage( pageNumber + m_firstPageNumber - 1 );
    }

    const qreal textDocWidth = m_paperSize.width() - mmToPixels( m_marginLeft + m_marginRight );
    const qreal textDocHeight = mainTextDocHeight();

    const int left = qRound( mmToPixels( m_marginLeft ) );
    const int top = qRound( mmToPixels( m_marginTop ) );
    //const int right = qRound( mmToPixels( m_marginRight ) );
    const int bottom = qRound( mmToPixels( m_marginBottom ) );
    const bool skipHeadersFooters = this->skipHeadersFooters();
    const int headerHeightWithSpacing = qRound( ( skipHeadersFooters ? 0 : m_headers.height() ) + mmToPixels( m_headerBodySpacing ) );
    const int footerHeight = skipHeadersFooters ? 0 : qRound( m_footers.height() );
    //const int footerHeightWithspacing = qRound( m_footers.height() + mmToPixels( m_footerBodySpacing ) );
    //const QRect paperRect( 0, 0, qRound( m_paperSize.width() ), qRound( m_paperSize.height() ) );
    //const QRect textDocRect = paperRect.adjusted( left, top + headerHeightWithSpacing,
    //                                              -right, - bottom - footerHeightWithspacing);
    const QRect textDocRect( left, top + headerHeightWithSpacing,
                             textDocWidth, textDocHeight );

    /*qDebug() << "paintPage: in pixels: top=" << top << " headerHeight=" << headerHeightWithSpacing
             << " textDoc size:" << textDocRect.size()
             << " bottom=" << bottom << " footerHeight=" << footerHeight;*/

    if( !m_watermarkText.isEmpty() ) {
        painter.save();
        painter.translate( textDocRect.center() );
        painter.rotate( m_watermarkRotation );
        painter.setFont( m_watermarkFont );
        painter.setPen( m_watermarkColor );
        const QSize textSize( painter.fontMetrics().size( Qt::TextSingleLine, m_watermarkText ) );
        const QRect textRect( -textSize.width() / 2, -textSize.height()/2, textSize.width(), textSize.height() );
        painter.drawText( textRect, Qt::AlignCenter, m_watermarkText );
        painter.restore();
    }

    if( !m_watermarkImage.isNull() ) {
        // We paint it without scaling it, for better quality.
        // But this means the actual size depends on the zoom level or printer resolution...
        //
        // It also means the image could end up being bigger than the page, and we don't want that.
        // So we scale down if necessary. But never up.
        QImage img = m_watermarkImage;
        if ( m_watermarkImage.width() > textDocRect.width() ||
             m_watermarkImage.height() > textDocRect.height() ) {
            // should probably be cached?
            img = m_watermarkImage.scaled( textDocRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
        }
        const QRect imageRect = QStyle::alignedRect( Qt::LeftToRight, Qt::AlignCenter, img.size(), textDocRect );
        //qDebug() << "textDocRect=" << textDocRect << "size=" << img.size() << "-> imageRect=" << imageRect;
        painter.drawImage( imageRect.topLeft(), img );
    }


    painter.save();
    //painter.setClipRect( textDocRect, Qt::IntersectClip ); // triggers a Qt-Windows bug when printing
    painter.setClipRect( textDocRect );
    painter.translate( left, top + headerHeightWithSpacing );
    m_layout->paintPageContent( pageNumber, painter );
    painter.restore();

    QAbstractTextDocumentLayout::PaintContext ctx;
    ctx.palette.setColor(QPalette::Text, Qt::black);
    if ( header && !skipHeadersFooters ) {
        painter.save();
        painter.translate( left, top );
        ctx.clip = painter.clipRegion().boundingRect();
        header->doc().contentDocument().documentLayout()->draw(&painter, ctx);
        painter.restore();
    }
    if ( footer && !skipHeadersFooters ) {
        painter.save();
        painter.translate( left, m_paperSize.height() - bottom - footerHeight );
        ctx.clip = painter.clipRegion().boundingRect();
        footer->doc().contentDocument().documentLayout()->draw(&painter, ctx);
        painter.restore();
    }
}
开发者ID:KDAB,项目名称:KDReports,代码行数:89,代码来源:KDReportsReport.cpp

示例12: paintEvent

void GraphicsWidget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)

	//set up painting with antialiasing etc
	QPainter painter;

	painter.begin(&elements);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setRenderHint(QPainter::HighQualityAntialiasing);
	painter.setRenderHint(QPainter::SmoothPixmapTransform);

	//transform coordinates to fit everything neatly on the screen
	painter.save();
	painter.setWorldTransform(getCurrentTransform());

	if (grid != nullptr)
	{
		//loop through and draw each entry
		for (const auto& cell: grid->getCells())
		{
			GridEntry &entry = grid->getEntry(cell);
			if (entry.modified) {
				entry.modified = false;
				painter.save();

				painter.translate(cell.x(), cell.y());

				QPen pen(Qt::black);
				pen.setWidthF(0);

				painter.setPen(pen);
				if (entry.type == GridEntry::Wall)
					painter.setBrush(Qt::darkBlue);

				else if (entry.type == GridEntry::Start)
					painter.setBrush(Qt::yellow);

				else if (entry.type == GridEntry::End)
					painter.setBrush(Qt::red);

				else if (entry.path)
					painter.setBrush(Qt::white);

				else if (entry.searched)
					painter.setBrush(Qt::cyan);
				
				else
					painter.setBrush(Qt::darkGreen);

                painter.drawConvexPolygon(DISPLAY_HEXAGON);

				painter.restore();
			}
		}
	}

	painter.restore();
	painter.setPen(Qt::white);

	QPainter screenPainter(this);
	screenPainter.fillRect(rect(), QBrush(Qt::black));
	screenPainter.drawImage(0, 0, elements);
}
开发者ID:GHfangxin,项目名称:SearchVisualizer,代码行数:64,代码来源:graphicswidget.cpp

示例13: on_pushButton_clicked

void MainWindow::on_pushButton_clicked()
{

    QFileDialog::Options options;
    options |= QFileDialog::DontUseNativeDialog;
    QString selectedFilter;

    QString fileName = QFileDialog::getSaveFileName(this,
                                                    tr("set the PDF name"),
                                                    "",
                                                    tr("PDF Files (*.pdf)"),
                                                    &selectedFilter,
                                                    options);
    fileName.append(".pdf");
    printer.setOutputFileName(fileName);
    QPainter painter;
    if (! painter.begin(&printer)) { // failed to open file
        qWarning("failed to open file, is it writable?");
        return ;
    }
    painter.save();
    //fist, draw a rounded rect for header & graphic area;
    painter.drawRoundedRect(header_area,15,15);
    painter.drawRoundedRect(curve_area.x(),curve_area.y(),curve_area.width(),table_area.y()+table_area.height(),15,15);
    painter.drawRoundedRect(curve_area,15,15);

    painter.setPen(Qt::SolidLine);

    QPen nom_line_pen(Qt::black, 2, Qt::SolidLine);
    QPen act_line_pen(Qt::blue, 2 ,Qt::SolidLine);

    //move the painter to the left mid position
    painter.translate(curve_area.x(),curve_area.center().y());

    //draw coordinate axis
    QPen axis_pen(Qt::blue,1,Qt::SolidLine);
    painter.setPen(axis_pen);
    painter.drawLine(0,0,curve_area.width(),0);
    painter.drawLine(curve_area.width()/2,curve_area.height()/2,curve_area.width()/2,-curve_area.height()/2);

    //draw nominal und actual curves
    painter.setPen(nom_line_pen);
    painter.drawPath(*nom_path);
    painter.setPen(act_line_pen);
    painter.drawPath(*act_path);
    //painter.drawPoints(nom_points,data->size());

    //draw nominal points as single points
    for(int i=0;i<size;++i)
    {
        painter.drawEllipse(nom_points[i],1.2,1.2);
    }

    //draw data tables
    painter.restore();
    painter.save();
    painter.translate(table_area.x(),table_area.y());
    painter.setFont(QFont("Times New Roman",10));
    for (int i=0;i<14;++i)  //just for test, offical release need auto adjust
    {
        painter.drawText(10+i*60,10,50,150,Qt::AlignCenter,
                         QString("%1\n%2\n%3\n%4")
                            .arg(i+1)
                         .arg(nom_data->at(i).x)
                         .arg(nom_data->at(i).y)
                            .arg( QString::number(act_data->at(i).y,'f',4)));
    }
    painter.translate(0,90);
    for (int i=14;i<28;++i)  //just for test, offical release need auto adjust
    {
        painter.drawText(10+(i-14)*60,10,50,150,Qt::AlignCenter,
                         QString("%1\n%2\n%3\n%4")
                            .arg(i+1)
                         .arg(nom_data->at(i).x)
                         .arg(nom_data->at(i).y)
                         .arg( QString::number(act_data->at(i).y,'f',4)));
    }

    //draw a header and LOGO
    painter.restore();
    painter.drawPixmap(header_area.x()+20,header_area.y()+1,header_area.height()-2,header_area.height()-2,*logo);
    painter.translate(header_area.center().x()-150,header_area.y());        //just for test

    QFont header_font("Blackadder ITC",20);
    painter.setFont(header_font);
    painter.drawText(0,0,300,header_area.height(),Qt::AlignCenter,QString("Just test, Curve Report by Sean"));

}
开发者ID:darksun190,项目名称:print_curve,代码行数:88,代码来源:mainwindow.cpp

示例14: cpointer

void
OCDial::drawShape(QPainter& p)
{
	if (vnew != vcur) {
		vnew = vnew < vmin ? vmin : vnew > vmax ? vmax : vnew;
		writeValue(vnew);
		vcur = vnew;
	}

	QRect br = boundingRect();
	double w = br.width();
	double h = br.height();
	double xc = w / 2;
	double yc = h / 2;
	double rw = w * .45;
	double rh = h * .45;
	double ptr_w = rw * .2;
	double ptr_h = rh * .2;
	double increment = M_PI * 100 / (rw * rh);

	double inc = vmax > vmin ? vmax - vmin : vmin - vmax;
	while (inc > 0 && inc < 100)
		inc *= 10.;
	while (inc >= 1000)
		inc /= 10.;

	p.drawPixmap(br, face);
	p.save();
	p.translate(x(), y());

	QColor ctick1("#99ff99");
	QColor ctick2("#99cc99");
	QColor cpointer("#ffcc33");
	QColor ccontour("#660000");
	QPen pen(QColor("#000000"), 2, SolidLine, RoundCap, BevelJoin);

	double last = -1;
	for (int i = 0; i <= inc; i++) {
		double theta = i * M_PI / (18. * inc / 24.) - M_PI/6.;
		if (theta - last < increment)
			continue;
		last = theta;
		double tick_w = ptr_w;
		double tick_h = ptr_h;
		if (inc >= 10 && (i % int(inc / 10)) == 0) {
			pen.setColor(ctick1);
		} else {
			tick_w /= 2;
			tick_h /= 2;
			pen.setColor(ctick2);
    	}
		p.setPen(pen);
		double s = sin(theta);
		double c = cos(theta);
		p.drawLine(
			int(xc + c*(rw - tick_w)), int(yc - s*(rh - tick_h)),
			int(xc + c*rw), int(yc - s*rh));
	}

	if (vmax == vmin)
		angle = 2.e9;
	else
		angle = (M_PI*7./6.) - (vcur - vmin) * (M_PI*4./3.) / (vmax - vmin);

	double c, s;
	if (fabs(angle) < 1.e9) {
		s = sin(angle);
		c = cos(angle);
	} else {
		c = s = angle = 0;
	}

	p.translate(xc, yc);
	QPointArray points(5);
	points.setPoint(0, int(s*ptr_w/2), int(c*ptr_w/2));
	points.setPoint(1, int(c*rw), int(-s*rh));
	points.setPoint(2, int(-s*ptr_w/2), int(-c*ptr_h/2));
	points.setPoint(3, int(-c*rw/10), int(s*rh/10));
	points.setPoint(4, int(s*ptr_w/2), int(c*ptr_h/2));

	p.setBrush(cpointer);
	p.drawPolygon(points);
	pen.setColor(ccontour);
	p.setPen(pen);
	p.drawPolyline(points);

	p.restore();
}
开发者ID:ivandeex,项目名称:optikus,代码行数:88,代码来源:ocranges.cpp

示例15: plotPathsToPainter

void plotPathsToPainter(QPainter& painter, QPainterPath& path,
			const Numpy1DObj& x, const Numpy1DObj& y,
			const Numpy1DObj* scaling,
			const QRectF* clip,
			const QImage* colorimg,
			bool scaleline)
{
  QRectF cliprect( QPointF(-32767,-32767), QPointF(32767,32767) );
  if( clip != 0 )
    {
      qreal x1, y1, x2, y2;
      clip->getCoords(&x1, &y1, &x2, &y2);
      cliprect.setCoords(x1, y1, x2, y2);
    }
  QRectF pathbox = path.boundingRect();
  cliprect.adjust(pathbox.left(), pathbox.top(),
		  pathbox.bottom(), pathbox.right());

  // keep track of duplicate points
  QPointF lastpt(-1e6, -1e6);
  // keep original transformation for restoration after each iteration
  QTransform origtrans(painter.worldTransform());

  // number of iterations
  int size = min(x.dim, y.dim);

  // if few color points, trim down number of paths
  if( colorimg != 0 )
    size = min(size, colorimg->width());
  // too few scaling points
  if( scaling != 0 )
    size = min(size, scaling->dim);

  // draw each path
  for(int i = 0; i < size; ++i)
    {
      const QPointF pt(x(i), y(i));
      if( cliprect.contains(pt) && ! smallDelta(lastpt, pt) )
	{
	  painter.translate(pt);

	  if( colorimg != 0 )
	    {
	      // get color from pixel and create a new brush
	      QBrush b( QColor::fromRgba(colorimg->pixel(i, 0)) );
	      painter.setBrush(b);
	    }

	  if( scaling == 0 )
	    {
	      painter.drawPath(path);
	    }
	  else
	    {
	      // scale point if requested
	      const qreal s = (*scaling)(i);
	      if( scaleline )
		{
		  painter.scale(s, s);
		  painter.drawPath(path);
		}
	      else
		{
		  QPainterPath scaled;
		  scalePath(path, s, scaled);
		  painter.drawPath(scaled);
		}
	    }

	  painter.setWorldTransform(origtrans);
	  lastpt = pt;
	}
    }
}
开发者ID:amcdawes,项目名称:veusz,代码行数:74,代码来源:qtloops.cpp


注:本文中的QPainter::translate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。