Beispiel #1
0
void BezierCurve::drawPath(QPainter& painter, Object* object, QTransform transformation, bool simplified, bool showThinLines )
{
    QColor colour = object->getColour(colourNumber).colour;

    BezierCurve myCurve;
    if (isPartlySelected()) { myCurve = (transformed(transformation)); }
    else { myCurve = *this; }

    if ( variableWidth && !simplified && !invisible)
    {
        painter.setPen(QPen(QBrush(colour), 1, Qt::NoPen, Qt::RoundCap,Qt::RoundJoin));
        painter.setBrush(colour);
        painter.drawPath(myCurve.getStrokedPath());
    }
    else
    {
        qreal renderedWidth = width;
        if (simplified)
        {
            renderedWidth = 1.0/painter.matrix().m11();
        }
        painter.setBrush(Qt::NoBrush);
        if ( invisible )
        {
            if (showThinLines)
            {
                if (simplified)
                {
                    // Set simplified lines to black for the fill function to define contours.
                    painter.setPen(QPen(QBrush(Qt::black), renderedWidth, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
                }
                else
                {
                    painter.setPen(QPen(QBrush(colour), 0, Qt::DotLine, Qt::RoundCap,Qt::RoundJoin));
                }
            }
            else
            {
                painter.setPen(Qt::NoPen);
            }
        }
        else
        {
            painter.setPen( QPen( QBrush( colour ), renderedWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
            //painter.setPen( QPen( Qt::darkYellow , 5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
        }
        QPainterPath path = myCurve.getSimplePath();
        painter.drawPath( path );
    }

    if (!simplified)
    {
        // highlight the selected elements
        colour = QColor(100,100,255);  // highlight colour
        painter.setBrush(Qt::NoBrush);
        qreal lineWidth = 1.5/painter.matrix().m11();
        painter.setPen(QPen(QBrush(colour), lineWidth, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
        if (isSelected()) painter.drawPath(myCurve.getSimplePath());


        for(int i=-1; i< vertex.size(); i++)
        {
            if (isSelected(i))
            {
                //painter.fillRect(myCurve.getVertex(i).x()-0.5*squareWidth, myCurve.getVertex(i).y()-0.5*squareWidth, squareWidth, squareWidth, colour);

                //painter.fillRect(QRectF(myCurve.getVertex(i).x()-0.5*squareWidth, myCurve.getVertex(i).y()-0.5*squareWidth, squareWidth, squareWidth), colour);

                /*painter.setFont( QFont("Arial", floor(12.0/painter.matrix().m11()), -1, false) );
                //painter.drawText(myCurve.getVertex(i)+QPointF(4.0,0.0), QString::number(i)+"-"+QString::number(myCurve.getVertex(i).x())+","+QString::number(myCurve.getVertex(i).y()));
                QPointF normale = QPointF(4.0, 0.0);
                if (i>-1) { normale = (myCurve.getVertex(i)-myCurve.getC2(i)); } else { normale = (myCurve.getC1(i+1)-myCurve.getVertex(i)); }
                normale = QPointF(-normale.y(), normale.x());
                normale = 8.0*normale/eLength(normale)/painter.matrix().m11();
                painter.drawLine(myCurve.getVertex(i), myCurve.getVertex(i)+normale);
                painter.drawText(myCurve.getVertex(i)+2*normale, QString::number(i));*/
            }
        }
    }
}
Beispiel #2
0
void BezierCurve::drawPath(QPainter &painter, Object* object, QMatrix transformation, bool simplified, bool showThinLines, qreal opacity) {
	if(!simplified) painter.setOpacity(opacity);
	QColor colour = object->getColour(colourNumber).colour;
	
	//simplified = true;
	//if(selected) { painter.setMatrix(transformation); } else { painter.setMatrix(QMatrix()); }
	//QColor colour = object->getColour(colourNumber).colour;
	if(!simplified) painter.setOpacity(opacity);
	BezierCurve myCurve;
	if(isPartlySelected()) { myCurve = (transformed(transformation)); } else { myCurve = *this; }
	//if(variableWidth && !simplified && width != 0) {
	if( variableWidth && !simplified && !invisible) {
		painter.setPen(QPen(QBrush(colour), 1, Qt::NoPen, Qt::RoundCap,Qt::RoundJoin));	
		painter.setBrush(colour);
		painter.drawPath(myCurve.getStrokedPath());
		/*QPen pen;
		pen.setColor(colour);
		QPointF P1 = origin;
		QPointF P2 = origin;
		for(int i=0; i<vertex.size(); i++) {
			P2 = getVertex(i);
			QPainterPath path;
			path.moveTo(P1);
			path.cubicTo(c1.at(i), c2.at(i), P2);
			pen.setWidthF( 2.0 * width * getPressure(i) );
			pen.setCapStyle( Qt::RoundCap );
			painter.setPen( pen );
			painter.drawPath( path );
			//painter.drawLine( P1, P2 );
			P1 = P2;
		}*/
	} else {
		qreal renderedWidth = width;
		if(simplified) {
			renderedWidth = 1.0/painter.matrix().m11();
		}
		painter.setBrush(Qt::NoBrush);
		//if(width == 0 && !simplified) {
		if( invisible ) {  // invisible && !simplified
			if(showThinLines) {
				if(simplified) {
					painter.setPen(QPen(QBrush(colour), renderedWidth, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
				} else {
					painter.setPen(QPen(QBrush(colour), 0, Qt::DotLine, Qt::RoundCap,Qt::RoundJoin));
				}
			} else {
				painter.setPen(Qt::NoPen);
			}
		} else {
			painter.setPen(QPen(QBrush(colour), renderedWidth, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
		}
		painter.drawPath(myCurve.getSimplePath());
	}
	
	if(!simplified) {
		// highlight the selected elements
		colour = QColor(100,100,255);  // highlight colour
		painter.setBrush(Qt::NoBrush);
		qreal lineWidth = 1.5/painter.matrix().m11();
		painter.setPen(QPen(QBrush(colour), lineWidth, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
		if(isSelected()) painter.drawPath(myCurve.getSimplePath());
		//qreal squareWidth = max(6.0, 1.2*myCurve.getWidth());
		//squareWidth = squareWidth/painter.matrix().m11();
		qreal squareWidth = 5.0/painter.matrix().m11();
		for(int i=-1; i< vertex.size(); i++) {
			if(isSelected(i)) {
				//painter.fillRect(myCurve.getVertex(i).x()-0.5*squareWidth, myCurve.getVertex(i).y()-0.5*squareWidth, squareWidth, squareWidth, colour);
				
				//painter.fillRect(QRectF(myCurve.getVertex(i).x()-0.5*squareWidth, myCurve.getVertex(i).y()-0.5*squareWidth, squareWidth, squareWidth), colour);
				
				/*painter.setFont( QFont("Arial", floor(12.0/painter.matrix().m11()), -1, false) );
				//painter.drawText(myCurve.getVertex(i)+QPointF(4.0,0.0), QString::number(i)+"-"+QString::number(myCurve.getVertex(i).x())+","+QString::number(myCurve.getVertex(i).y()));
				QPointF normale = QPointF(4.0, 0.0);
				if(i>-1) { normale = (myCurve.getVertex(i)-myCurve.getC2(i)); } else { normale = (myCurve.getC1(i+1)-myCurve.getVertex(i)); }
				normale = QPointF(-normale.y(), normale.x());
				normale = 8.0*normale/eLength(normale)/painter.matrix().m11();
				painter.drawLine(myCurve.getVertex(i), myCurve.getVertex(i)+normale);
				painter.drawText(myCurve.getVertex(i)+2*normale, QString::number(i));*/
			}
		}
	}
}