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


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

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


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

示例1: drawRing

void KisColorSelector::drawRing(QPainter& painter, KisColorSelector::ColorRing& ring, const QRect& rect)
{
    painter.setRenderHint(QPainter::Antialiasing, false);
    painter.resetTransform();
    painter.translate(rect.width()/2, rect.height()/2);
    
    if (ring.pieced.size() > 1) {
        painter.rotate(-ring.getShift().degrees());
        painter.scale(rect.width()/2, rect.height()/2);
        painter.setPen(Qt::NoPen);
        
        QBrush brush(Qt::SolidPattern);
        
        for(int i=0; i<ring.pieced.size(); ++i) {
            float hue = float(i) / float(ring.pieced.size()) + ring.getShift().scaled(0.0f, 1.0f);
            hue = (hue >= 1.0f) ? (hue - 1.0f) : hue;
            hue = (hue <  0.0f) ? (hue + 1.0f) : hue;
            
            KisColor color(hue, 1.0f, m_colorSpace);
            color.setS(ring.saturation);
            color.setX(getLight(m_light, hue, m_relativeLight));
            
            brush.setColor(color.getQColor());
            painter.fillPath(ring.pieced[i], brush);
        }
    }
    else {
        KisColor colors[7] = {
            KisColor(Qt::red    , m_colorSpace),
            KisColor(Qt::yellow , m_colorSpace),
            KisColor(Qt::green  , m_colorSpace),
            KisColor(Qt::cyan   , m_colorSpace),
            KisColor(Qt::blue   , m_colorSpace),
            KisColor(Qt::magenta, m_colorSpace),
            KisColor(Qt::red    , m_colorSpace)
        };
        
        QConicalGradient gradient(0, 0, 0);
        
        for(int i=0; i<=6; ++i) {
            qreal hue = float(i) / 6.0f;
            colors[i].setS(ring.saturation);
            colors[i].setX(getLight(m_light, hue, m_relativeLight));
            gradient.setColorAt(hue, colors[i].getQColor());
        }
        
        painter.scale(rect.width()/2, rect.height()/2);
        painter.fillPath(ring.pieced[0], QBrush(gradient));
    }
    
    painter.resetTransform();
}
开发者ID:IGLOU-EU,项目名称:krita,代码行数:52,代码来源:kis_color_selector.cpp

示例2: drawOutline

void KisColorSelector::drawOutline(QPainter& painter, const QRect& rect)
{
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.resetTransform();
    painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2);
    painter.scale(rect.width()/2, rect.height()/2);
    painter.setPen(QPen(QBrush(Qt::gray), 0.005));
    
    if (getNumPieces() > 1) {
        for(int i=0; i<getNumRings(); ++i) {
            painter.resetTransform();
            painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2);
            painter.scale(rect.width()/2, rect.height()/2);
            painter.rotate(-m_colorRings[i].getShift().degrees());
            
            for(int j=0; j<m_colorRings[i].pieced.size(); ++j)
                painter.drawPath(m_colorRings[i].pieced[j]);
        }
        
        if (m_selectedRing >= 0 && m_selectedPiece >= 0) {
            painter.resetTransform();
            painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2);
            painter.rotate(-m_colorRings[m_selectedRing].getShift().degrees());
            painter.scale(rect.width()/2, rect.height()/2);
            
            painter.setPen(QPen(QBrush(Qt::red), 0.01));
            painter.drawPath(m_colorRings[m_selectedRing].pieced[m_selectedPiece]);
        }
    }
    else {
        for(int i=0; i<getNumRings(); ++i) {
            qreal rad = m_colorRings[i].outerRadius;
            painter.drawEllipse(QRectF(-rad, -rad, rad*2.0, rad*2.0));
        }
    }
    
    if (m_selectedRing >= 0) {
        qreal iRad = m_colorRings[m_selectedRing].innerRadius;
        qreal oRad = m_colorRings[m_selectedRing].outerRadius;
        
        painter.setPen(QPen(QBrush(Qt::red), 0.005));
        painter.drawEllipse(QRectF(-iRad, -iRad, iRad*2.0, iRad*2.0));
        painter.drawEllipse(QRectF(-oRad, -oRad, oRad*2.0, oRad*2.0));
        
        if (getNumPieces() <= 1) {
            float c = std::cos(-m_selectedColor.getH() * PI2);
            float s = std::sin(-m_selectedColor.getH() * PI2);
            painter.drawLine(QPointF(c*iRad, s*iRad), QPointF(c*oRad, s*oRad));
        }
    }
}
开发者ID:IGLOU-EU,项目名称:krita,代码行数:51,代码来源:kis_color_selector.cpp

示例3: platformTransformColorSpace

void ImageBufferDataPrivateAccelerated::platformTransformColorSpace(const Vector<int>& lookUpTable)
{
    QPainter* painter = paintDevice()->paintEngine()->painter();

    QImage image = toQImage().convertToFormat(QImage::Format_ARGB32);
    ASSERT(!image.isNull());

    uchar* bits = image.bits();
    const int bytesPerLine = image.bytesPerLine();

    for (int y = 0; y < image.height(); ++y) {
        quint32* scanLine = reinterpret_cast_ptr<quint32*>(bits + y * bytesPerLine);
        for (int x = 0; x < image.width(); ++x) {
            QRgb& pixel = scanLine[x];
            pixel = qRgba(lookUpTable[qRed(pixel)],
                          lookUpTable[qGreen(pixel)],
                          lookUpTable[qBlue(pixel)],
                          qAlpha(pixel));
        }
    }

    painter->save();
    painter->resetTransform();
    painter->setOpacity(1.0);
    painter->setClipping(false);
    painter->setCompositionMode(QPainter::CompositionMode_Source);
    // Should coordinates be flipped?
    painter->drawImage(QPoint(0,0), image);
    painter->restore();
}
开发者ID:Metrological,项目名称:qtwebkit,代码行数:30,代码来源:ImageBufferQt.cpp

示例4: c

		/**
		* Calls virtual drawShape() method to draw the actial shape.
		* Draws bounding rect and control points if the shape is selected.
		*
		* @param painter :: QPainter used for drawing.
		*/
		void Shape2D::draw(QPainter& painter) const
		{
			if (!m_visible) return;
			painter.setPen(m_color);
			this->drawShape(painter);
			if (m_editing || m_selected)
			{
				QColor c(255, 255, 255, 100);
				painter.setPen(c);
				painter.drawRect(m_boundingRect.toQRectF());
				size_t np = NCommonCP;
				double rsize = 2;
				int alpha = 100;
				if (m_editing)
				{
					// if editing show all CP, make them bigger and opaque
					np = getNControlPoints();
					rsize = sizeCP;
					alpha = 255;
				}
				for (size_t i = 0; i < np; ++i)
				{
					QPointF p = painter.transform().map(getControlPoint(i));
					QRectF r(p - QPointF(rsize, rsize), p + QPointF(rsize, rsize));
					painter.save();
					painter.resetTransform();
					QColor c(255, 255, 255, alpha);
					painter.fillRect(r, c);
					r.adjust(-1, -1, 0, 0);
					painter.setPen(QColor(0, 0, 0, alpha));
					painter.drawRect(r);
					painter.restore();
				}
			}
		}
开发者ID:Mantid-Test-Account,项目名称:mantid,代码行数:41,代码来源:Shape2D.cpp

示例5: drawEdge

void MaxFlowVisualizer::drawEdge(const Edge &edge, QPainter &painter) const {
    QPen pen;
    pen.setWidth(3);
    // Ребро, которое считается "допустимым" по алгоритму, выделяем черным.
    if (relabelToFrontAlgo.getVertexHeight(edge.getFirstVertexIndex())
        == relabelToFrontAlgo.getVertexHeight(edge.getSecondVertexIndex()) + 1) {
        pen.setColor(Qt::black);
    }
    else {
        pen.setColor(Qt::gray);
    }
    if (edge.getFlow() != 0) {
        pen.setColor(Qt::darkBlue);
    }
    // Если в последнем действии алгоритма произошло проталкивание по этому ребру,
    // то выделим его красным.
    if (lastAlgoAction.getType() == AlgoAction::ACTION_PUSH && lastAlgoAction.getEdgeInfo() == edge) {
        pen.setColor(Qt::red);
    }
    painter.setPen(pen);
    QPoint pointFrom(verteciesList[edge.getFirstVertexIndex()].getCenterCoordX(),
                     verteciesList[edge.getFirstVertexIndex()].getCenterCoordY());
    QPoint pointTo(verteciesList[edge.getSecondVertexIndex()].getCenterCoordX(),
                   verteciesList[edge.getSecondVertexIndex()].getCenterCoordY());
    double length = sqrt(pow(pointFrom.x() - pointTo.x(), 2)
                         + pow(pointFrom.y() - pointTo.y(), 2));
    long vertexRaduis = verteciesList[edge.getSecondVertexIndex()].getRadius();
    QPoint offsetVector((pointFrom.x() - pointTo.x()) * vertexRaduis / length,
                        (pointFrom.y() - pointTo.y()) * vertexRaduis / length);
    QPoint arrow((pointFrom.x() - pointTo.x()) * 20 / length,
                 (pointFrom.y() - pointTo.y()) * 20 / length);
    // Рисование стрелки (самих маленьких боковых линий).
    // Перенесем систему координат в точку конца ребра (ориенированного).
    // Возьмем маленький отрезок ребра, и нарисуем его, повернув при этом систуму координат
    // на +30 и -30 градусов соответственно относительно исходного ребра.
    // Получилась стрелка ->
    // После этого восстановим систему координат.
    painter.setPen(pen);
    painter.drawLine(pointFrom, pointTo);
    painter.translate(pointTo.x(), pointTo.y());
    // Еще нужно отступить от конца ребра на радиус вершины
    // (т.к. ребро идет от центра к центру).
    painter.translate(offsetVector.x(), offsetVector.y());
    painter.rotate(30);
    painter.drawLine(QPoint(0, 0), arrow);
    painter.rotate(-60);
    painter.drawLine(QPoint(0, 0), arrow);
    painter.resetTransform();
    // Выводим информацию о ребре (flow | capacity) по середине ребра.
    if (state == ALGORITHM_RUN || (state == ALGORITHM_TERM && edge.flow != 0)) {
        QPen penForEdgeInfo;
        penForEdgeInfo.setColor(Qt::darkGreen);
        painter.setPen(penForEdgeInfo);
        std::string edgeInfo = "(" + std::to_string(edge.getFlow()) + " | " + std::to_string(edge.getCapacity()) + ")";
        painter.drawText(pointFrom.x() + (pointTo.x() - pointFrom.x()) / 2,
                         pointFrom.y() + (pointTo.y() - pointFrom.y()) / 2,
                         edgeInfo.c_str());
    }
}
开发者ID:max-dankow,项目名称:Maximum-Flow-Visualization,代码行数:59,代码来源:maxflowvisualizer.cpp

示例6: paintControlHandles

void QSplineEdit::paintControlHandles(QPainter & pnt)
{
	QBrush br(Qt::lightGray);
	QPen pn(Qt::black);
	pnt.setPen(pn);
	pnt.setBrush(br);
	
	QRectF square(-4,-4,8,8);
	pnt.translate(toDrawSpace(0, m_startValue));
	pnt.drawRect(square);
	pnt.resetTransform();
	pnt.translate(toDrawSpace(1, m_endValue));
	pnt.drawRect(square);
	
	pnt.resetTransform();
	pnt.translate(toDrawSpace(m_startCvx, m_startCvy));
	pnt.drawEllipse(square);
	
	pnt.resetTransform();
	pnt.translate(toDrawSpace(m_endCvx, m_endCvy));
	pnt.drawEllipse(square);
}
开发者ID:kkaushalp,项目名称:aphid,代码行数:22,代码来源:QSplineEdit.cpp

示例7: Paint

void OGSprite::Paint(QPainter& p, const QRectF& a_target)
{
    if (!m_visible)
        return;

    p.setOpacity(m_alpha);

    p.resetTransform();

    if (GetAngle() != 0)
        p.rotate(GetAngle());

    m_source->Render(p, a_target, m_clipRect);
}
开发者ID:Mandarancio,项目名称:OpenGOO,代码行数:14,代码来源:og_sprite.cpp

示例8: draw

void PHISurfaceEffect::draw( QPainter *painter )
{
    /*
    QPoint offset;
    QPixmap pixmap;
    if ( sourceIsPixmap() ) {
    // No point in drawing in device coordinates (pixmap will be scaled anyways).
        pixmap=sourcePixmap( Qt::LogicalCoordinates, &offset );
    } else {
    // Draw pixmap in device coordinates to avoid pixmap scaling;
        pixmap=sourcePixmap( Qt::DeviceCoordinates, &offset );
        painter->setWorldTransform( QTransform() );
    }

    QImage img=pixmap.toImage();
    img=PHI::getSurfacedImage( img, _yOff, _size );
    painter->drawImage( offset, img );
*/
    QRectF brect=sourceBoundingRect( Qt::LogicalCoordinates );
    QImage img( static_cast<int>(brect.width()+1), static_cast<int>(brect.height()+_size+_yOff),
        QImage::Format_ARGB32_Premultiplied );
    QPainter pixPainter;
    pixPainter.begin( &img );

    pixPainter.setRenderHints( painter->renderHints() );
    pixPainter.setCompositionMode( QPainter::CompositionMode_Clear );
    pixPainter.fillRect( 0., 0., brect.width()+1., brect.height()+_size+_yOff+1, Qt::transparent );
    pixPainter.setCompositionMode( QPainter::CompositionMode_SourceOver );
    drawSource( &pixPainter );

    QTransform t;
    t.rotate( 180., Qt::XAxis );
    t.translate( 0., (-brect.height()*2.)-_yOff+1. );
    pixPainter.setTransform( t );
    drawSource( &pixPainter );

    pixPainter.resetTransform();
    pixPainter.translate( 0., brect.height()+_yOff );
    QLinearGradient gradient( 0., 0., 0., 1.0 );
    gradient.setColorAt( 0., QColor( 0, 0, 0, 220 ) );
    gradient.setColorAt( 0.78, QColor( 0, 0, 0, 30 ) );
    gradient.setColorAt( 1., Qt::transparent );
    gradient.setCoordinateMode( QGradient::ObjectBoundingMode );

    pixPainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
    pixPainter.fillRect( 0., 0., brect.width()+1, _size, gradient );
    pixPainter.end();
    painter->drawImage( 0, 0, img );
}
开发者ID:TheAppsDude,项目名称:phisketeer,代码行数:49,代码来源:phieffects.cpp

示例9: drawMarker

void Hruler::drawMarker(QPainter& p)
{
	QPolygon cr;
#ifdef OPTION_SMOOTH_MARKERS
	// draw new marker to pixmap
	static const int SCALE = 16;
	static const QColor BACKGROUND(255, 255, 255);
	static QPixmap pix( 4*SCALE, 16*SCALE );
	static bool initpix = true;
	if (initpix) {
		initpix = false;
		QPainter pp( &pix );
		pp.setBrush( BACKGROUND );
		pp.drawRect( 0, 0, 4*SCALE, 16*SCALE );
		
		pp.setPen(Qt::red);
		pp.setBrush(Qt::red);
		cr.setPoints(3, 2*SCALE, 16*SCALE, 4*SCALE, 0, 0, 0);
		pp.drawPolygon(cr);
	}
	// draw pixmap
	p.save();
	p.translate(-m_view->contentsX(), 0);
	p.scale(1.0/SCALE, 1.0/(SCALE+1));
	p.drawPixmap((where-2)*SCALE, 1, pix);
	p.restore();
	// restore marks
	p.setBrush(Qt::black);
	p.setPen(Qt::black);
	p.setFont(font());
	double sc = m_view->getScale();
	double cc = width() / sc;
	double firstMark = ceil(offs / iter) * iter - offs;
	while (firstMark < cc)
	{
		p.drawLine(qRound(firstMark * sc), 10, qRound(firstMark * sc), 16);
		firstMark += iter;
	}
#else
	// draw slim marker
	p.resetTransform();
	p.translate(-m_view->contentsX(), 0);
	p.setPen(Qt::red);
	p.setBrush(Qt::red);
	cr.setPoints(5,  whereToDraw, 5, whereToDraw, 16, whereToDraw, 5, whereToDraw+2, 0, whereToDraw-2, 0);
	p.drawPolygon(cr);
#endif
}
开发者ID:Fahad-Alsaidi,项目名称:scribus-svn,代码行数:48,代码来源:hruler.cpp

示例10: endTransparencyLayer

void GraphicsContext::endTransparencyLayer()
{
    if (paintingDisabled())
        return;

    TransparencyLayer *layer = m_data->layers.pop();
    layer->painter.end();

    QPainter *p = m_data->p();
    p->save();
    p->resetTransform();
    p->setOpacity(layer->opacity);
    p->drawPixmap(layer->offset, layer->pixmap);
    p->restore();

    delete layer;
}
开发者ID:Katarzynasrom,项目名称:patch-hosting-for-android-x86-support,代码行数:17,代码来源:GraphicsContextQt.cpp

示例11: c

void Shape2D::draw(QPainter& painter) const
{
  painter.setPen(m_color);
  this->drawShape(painter);
  if (m_editing)
  {
    QColor c(255,255,255,100);
    painter.setPen(c);
    painter.setCompositionMode(QPainter::CompositionMode_Plus);
    painter.drawRect(m_boundingRect.toQRectF());
    for(size_t i = 0; i < getNControlPoints(); ++i)
    {
      QPointF p = painter.transform().map(getControlPoint(i));
      QRectF r(p - QPointF(sizeCP,sizeCP),p + QPointF(sizeCP,sizeCP));
      painter.save();
      painter.resetTransform();
      painter.fillRect(r,c);
      painter.restore();
    }
  }
}
开发者ID:trnielsen,项目名称:mantid,代码行数:21,代码来源:Shape2D.cpp

示例12: dumpPolySetPNG

///write a polygon on a PNG file, format of the polygon is vector of vector of contours...nested contours are holes
///takes the name of the image in input, the set of polygons, the set of per polygons transformation, 
///the label to be written and the global parameter for drawing style
void  PolyDumper::dumpPolySetPNG(const char * imageName, 
										vector< vector< vector<Point2f> > > &polyVecVec, 
										vector<Similarity2f> &trVec, 
										vector<string> &labelVec, 
										PolyDumperParam &pp)
{
	///SET THE FONT
	assert(polyVecVec.size() == trVec.size());
	int fontSize=ceil(std::max(pp.width,pp.height)/100.0);
	QFont qf("courier",fontSize);

	///SET THE DRAWING SIZE
	QImage img(pp.width,pp.height,QImage::Format_RGB32);
	img.fill(vcg::ColorConverter::ToQColor( pp.backgroundColor).rgb());

	///SETUP OF DRAWING PROCEDURE
	QPainter painter;
	painter.begin(&img);
	QBrush bb;
	if (pp.fill)
		bb.setStyle(Qt::SolidPattern);
	QPen qp;
	qp.setWidthF(0);

	for(size_t i=0;i<polyVecVec.size();++i)
	{
		///SET THE CURRENT TRANSFORMATION
		painter.resetTransform();
		painter.translate(trVec[i].tra[0],trVec[i].tra[1]);
		painter.rotate(math::ToDeg(trVec[i].rotRad));
		painter.scale(trVec[i].sca,trVec[i].sca);
		QPainterPath QPP;

		for(size_t jj=0;jj<polyVecVec[i].size();++jj)
		{
			QVector<QPointF> ppQ;
			for(size_t j=0;j<polyVecVec[i][jj].size();++j)
			{
				Point2f pp=polyVecVec[i][jj][j];
				ppQ.push_back(QPointF(pp[0],pp[1]));
			}
			ppQ.push_back(QPointF(polyVecVec[i][jj][0][0],polyVecVec[i][jj][0][1]));
			QPP.addPolygon(QPolygonF(ppQ));
		}
		///FIND THE BARYCENTER
		int radius;
		Point2f bc;
		bc=GetIncenter(polyVecVec[i],trVec[i],radius,100);

		if (pp.randomColor)
			bb.setColor(vcg::ColorConverter::ToQColor(Color4b::Scatter(polyVecVec.size(),i)));
		else
			bb.setColor(vcg::ColorConverter::ToQColor(pp.FillColor));

		painter.setBrush(bb);
		painter.setPen(qp);
		painter.drawPath(QPP);

		///DRAW THE TEXT
		painter.setFont(qf);
		painter.resetTransform();
		painter.translate(trVec[i].tra[0],trVec[i].tra[1]);

		painter.drawText(bc[0]-radius,bc[1]-radius,radius*2,radius*2,Qt::AlignHCenter|Qt::AlignCenter,QString(labelVec[i].c_str()));
	}
	painter.end();
	img.save(imageName);
}
开发者ID:HaiJiaoXinHeng,项目名称:meshlab,代码行数:71,代码来源:PolyToQImage.cpp

示例13: paintIntensityNumerals

void NaZStackWidget::paintIntensityNumerals(QPainter& painter)
{
    if (cur_z < 0) return;
    if (! zSliceColors) return;
    ZSliceColors::Reader zReader(*zSliceColors);
    if (! zReader.hasReadLock()) return;
    const QImage * displayImage = zReader.getImage();
    if (! displayImage) return;

    if (! volumeData) return;
    NaVolumeData::Reader volumeReader(*volumeData);
    if (! volumeReader.hasReadLock()) return;
    const Image4DProxy<My4DImage>& imgProxy = volumeReader.getOriginalImageProxy();

    // qDebug() << "numerals";
    QPointF v_img_upleft = X_img_view * painter.viewport().topLeft();
    QPointF v_img_downright = X_img_view * painter.viewport().bottomRight();
    // qDebug() << v_img_upleft;
    // qDebug() << v_img_downright;

    // clear transform for text rendering, otherwise font size is harder to manage
    painter.resetTransform();

    QFont font = painter.font();
    float scale = defaultScale * cameraModel.scale();
    font.setPixelSize(scale/4.0);
    font.setStyleStrategy(QFont::NoAntialias); // text rendering can be slow
    painter.setFont(font);

    // qDebug() << "nColumns = " << mipImage->originalData.nColumns();
    // qDebug() << "nRows = " << mipImage->originalData.nRows();

    // Iterate over only the image pixels that are visible
    int nC = imgProxy.sc;
    float lineHeight = scale / (nC + 1.0);
    for (int x = int(v_img_upleft.x() - 0.5); x <= int(v_img_downright.x() + 0.5); ++x) {
        // qDebug() << "x = " << x;
        if (x < 0)
            continue;
        if (x >= displayImage->width())
            continue;
        for (int y = int(v_img_upleft.y() - 0.5); y <= int(v_img_downright.y() + 0.5); ++y) {
            // qDebug() << "y = " << y;
            if (y < 0)
                continue;
            if (y >= displayImage->height())
                continue;
            // Transform image pixel coordinates back to viewport coordinates
            QPointF v = X_view_img * QPointF(x, y);
            // qDebug() << x << ", " << y << "; " << v.x() << ", " << v.y();
            // Print original data intensity, not displayed intensity
            // But choose font color based on displayed intensity.
            unsigned int red = qRed(displayImage->pixel(x, y));
            unsigned int green = qGreen(displayImage->pixel(x, y));
            unsigned int blue = qBlue(displayImage->pixel(x, y));
            // human color perception is important here
            float displayIntensity = 0.30 * red + 0.58 * green + 0.12 * blue;
            if (displayIntensity < 128)
                painter.setPen(Qt::white);
            else
                painter.setPen(Qt::black);

            // Write a neat little column of numbers inside each pixel
            for (int c = 0; c < nC; ++c) {
                double val = imgProxy.value_at(x, y, cur_z, c);
                painter.drawText(QRectF(v.x(), v.y() + (c + 0.5) * lineHeight, scale, lineHeight),
                                 Qt::AlignHCenter | Qt::AlignVCenter,
                                 QString("%1").arg(val));
            }
        }
    }
    // restore coordinate system
    transformPainterToCurrentCamera(painter);
}
开发者ID:Vaa3D,项目名称:v3d_external,代码行数:74,代码来源:NaZStackWidget.cpp

示例14: paintDebugDrawing


//.........这里部分代码省略.........
        painter.setBrush(brush);
      }
      else
        painter.setBrush(noBrush);

      // select pen
      if(element.penStyle != Drawings::ps_null)
      {
        pen.setColor(QColor(element.penColor.r, element.penColor.g, element.penColor.b, element.penColor.a));
        // A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the transformation set on the painter.
        pen.setWidth(element.width);
        switch(element.penStyle)
        {
        case Drawings::ps_dash:
          pen.setStyle(Qt::DashLine);
          break;
        case Drawings::ps_dot:
          pen.setStyle(Qt::DotLine);
          break;
        case Drawings::ps_solid:
        default:
          pen.setStyle(Qt::SolidLine);
        }
        painter.setPen(pen);
      }
      else
        painter.setPen(noPen);

      if(element.rotation != 0.0f)
      {
        QTransform trans(painter.transform());
        QTransform transBack(painter.transform());
        trans.translate(qreal(element.x), qreal(element.y));
        trans.rotateRadians(qreal(element.rotation));
        painter.setTransform(trans);
        painter.drawEllipse(-element.radiusX, -element.radiusY, 2 * element.radiusX, 2 * element.radiusY);
        painter.setTransform(transBack);
      }
      else
      {
        painter.drawEllipse(element.x - element.radiusX, element.y - element.radiusY, 2 * element.radiusX, 2 * element.radiusY);
      }
      break;
    }
    case DebugDrawing::Element::LINE:
    {
      const DebugDrawing::Line& element = *(const DebugDrawing::Line*) e;

      if(element.penStyle != Drawings::ps_null)
      {
        pen.setColor(QColor(element.penColor.r, element.penColor.g, element.penColor.b, element.penColor.a));
        // A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the transformation set on the painter.
        pen.setWidth(element.width);
        switch(element.penStyle)
        {
        case Drawings::ps_dash:
          pen.setStyle(Qt::DashLine);
          break;
        case Drawings::ps_dot:
          pen.setStyle(Qt::DotLine);
          break;
        case Drawings::ps_solid:
        default:
          pen.setStyle(Qt::SolidLine);
        }
        painter.setPen(pen);

        painter.drawLine(element.xStart, element.yStart, element.xEnd, element.yEnd);
      }
      break;
    }
    case DebugDrawing::Element::ORIGIN:
    {
      const DebugDrawing::Origin& element = *(const DebugDrawing::Origin*) e;
      QTransform trans(baseTrans);
      trans.translate(qreal(element.x), qreal(element.y));
      trans.rotateRadians(qreal(element.angle));
      painter.setTransform(trans);
      break;
    }

    case DebugDrawing::Element::TEXT:
    {
      const DebugDrawing::Text& element = *(const DebugDrawing::Text*) e;

      pen.setColor(QColor(element.penColor.r, element.penColor.g, element.penColor.b, element.penColor.a));
      painter.setPen(pen);

      QTransform trans(painter.transform());
      const QPoint& pos(trans.map(QPoint(element.x, element.y)));
      painter.resetTransform();
      painter.drawText(pos, (const char*)(&element + 1));
      painter.setTransform(trans);

      break;
    }
    default:
      break;
    }
}
开发者ID:LukeLu1263,项目名称:WrightOcean2012,代码行数:101,代码来源:PaintMethods.cpp

示例15: dumpPolySetSVG

///write a polygon on a SVG file, format of the polygon is vector of vector of contours...nested contours are holes
///takes the name of the image in input, the set of polygons, the set of per polygons transformation, 
///the label to be written and the global parameter for drawing style
void PolyDumper::dumpPolySetSVG(const char * imageName, 
									   vector< vector< vector<Point2f> > > &polyVecVec, 
									   vector<Similarity2f> &trVec, 
									   vector< vector< string> > &labelVecVec,
									   vector<vector<Point2f> > &labelPosVecVec,
									   vector<vector<float> >&labelRadVecVec,
									   PolyDumperParam &pp)
{
	assert(polyVecVec.size() == trVec.size());


	///SET THE FONT
	int fontSize;
	if(pp.fontSize==0) fontSize=ceil(std::max(pp.width,pp.height)/200.0);
	else fontSize=pp.fontSize;
	QFont qf("courier",fontSize);
	QSvgGenerator svg;
	svg.setFileName(imageName);

	///SET THE DRAWING SIZE
	svg.setSize(QSize(pp.width,pp.height));
	svg.setViewBox(QRect(0, 0, pp.width,pp.height));
	svg.setResolution(int(pp.dpi));//

	///SETUP OF DRAWING PROCEDURE
	QPainter painter;
	painter.begin(&svg);
	QBrush bb;
	if (pp.fill)
		bb.setStyle(Qt::SolidPattern);

	QPen qp;

	///SET THE GLOBAL SCALING FACTOR
	float Scalesvg=1.f/(float)trVec[0].sca;
	qp.setWidthF(Scalesvg);
	for(size_t i=0;i<polyVecVec.size();++i)
	{
		///SET THE CURRENT TRANSFORMATION
		painter.resetTransform();
		painter.translate(trVec[i].tra[0],trVec[i].tra[1]);
		painter.rotate(math::ToDeg(trVec[i].rotRad));
		painter.scale(trVec[i].sca,trVec[i].sca);
		QPainterPath QPP;

		for(size_t jj=0;jj<polyVecVec[i].size();++jj)
		{
			QVector<QPointF> ppQ;
			for(size_t j=0;j<polyVecVec[i][jj].size();++j)
			{
				Point2f pp=polyVecVec[i][jj][j];
				ppQ.push_back(QPointF(pp[0],pp[1]));
			}
			ppQ.push_back(QPointF(polyVecVec[i][jj][0][0],polyVecVec[i][jj][0][1]));
			QPP.addPolygon(QPolygonF(ppQ));
		}
		///FIND THE INCENTER

		if (pp.randomColor)
			bb.setColor(vcg::ColorConverter::ToQColor(Color4b::Scatter(polyVecVec.size(),i)));
		else
			bb.setColor(vcg::ColorConverter::ToQColor(pp.FillColor));

		///DRAW THE POLYGON
		painter.setBrush(bb);
		painter.setPen(qp);
		painter.drawPath(QPP);

		///DRAW THE TEXT
		painter.setFont(qf);
		float radius;
		int radiusInt;
		Point2f bc;
		// if we do not have labelPos use the old method of empty disk.
		if(labelPosVecVec.empty()) bc=GetIncenter(polyVecVec[i],trVec[i],radiusInt);
		radius = radiusInt;
		for(size_t labelInd=0;labelInd<labelVecVec[i].size();++labelInd)
		{
		  if(!labelPosVecVec.empty())
		  {
			bc= labelPosVecVec[i][labelInd];
			bc.Rotate(trVec[i].rotRad);
			bc *= trVec[i].sca;
			radius=labelRadVecVec[i][labelInd];
			radius *= trVec[i].sca;
		  }
		  painter.resetTransform();
		  painter.translate(trVec[i].tra[0],trVec[i].tra[1]);
		  painter.drawText(bc[0]-radius,bc[1]-radius,radius*2,radius*2,Qt::AlignHCenter|Qt::AlignCenter,QString(labelVecVec[i][labelInd].c_str()));
		}
	}
	painter.end();
}
开发者ID:HaiJiaoXinHeng,项目名称:meshlab,代码行数:96,代码来源:PolyToQImage.cpp


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