Example #1
0
/**
 * Draw the arrow triangle.
 *
 * @param[in] painter Painter that must be used.
 * @param[in] plot Plot where arrow must be plotted.
 */
void Arrow2D::drawArrow(QPainter &painter, Plot2D *plot){
	painter.setPen(m_arrowLinePen);
	painter.setBrush(m_arrowBrush);
	const auto initialPoint = getScaledPosition(m_pivot, plot);
	const auto finalPoint = getScaledPosition(m_finalPoint, plot);
	const double angle = atan2(finalPoint.y() - initialPoint.y(), finalPoint.x() - initialPoint.x());
	const double arrowLength = getScaledDimensionX(m_arrowLength, plot);
	const double arrowWidth = getScaledDimensionX(m_arrowWidth, plot);
	const QPointF p1(-m_arrowLength + finalPoint.x(), -m_arrowWidth * 0.5 + finalPoint.y());
	const QPointF p2(-m_arrowLength + finalPoint.x(), m_arrowWidth * 0.5 + finalPoint.y());
	QPolygonF arrow;
	arrow << finalPoint << p1 << p2;
	QTransform transform;
	transform.rotateRadians(angle);
	const QPolygonF rotatedArrow = transform.map(arrow);
	const auto deltaPosition = arrow.front() -  rotatedArrow.front();
	QTransform translateTransform;
	translateTransform.translate(deltaPosition.x(), deltaPosition.y());
	const QPolygonF rotoTranslatedArros = translateTransform.map(rotatedArrow);
	painter.drawPolygon(rotoTranslatedArros);
}
Example #2
0
void _drawPolygon(QPainter *p, const QPolygonF &polygon)  //画QPolygonF
{
    //temp
    p->drawPolygon(polygon);
    QPointF A=polygon.operator [](polygon.size()-2);
    QPointF B=polygon.operator [](polygon.size()-1);
    _drawArrow(p,A,B);
    //下面是强调起点的标志
    QPen pen(Qt::darkYellow);
    pen.setWidth(4);
    p->setPen(pen);
    p->drawPoint(polygon.front());
}