26 if ( props.contains(
"color" ) )
28 if ( props.contains(
"width" ) )
29 width = props[
"width"].toDouble();
30 if ( props.contains(
"penstyle" ) )
35 if ( props.contains(
"offset" ) )
36 l->
setOffset( props[
"offset"].toDouble() );
37 if ( props.contains(
"joinstyle" ) )
39 if ( props.contains(
"capstyle" ) )
42 if ( props.contains(
"use_custom_dash" ) )
46 if ( props.contains(
"customdash" ) )
62 penColor.setAlphaF( context.
alpha() );
63 mPen.setColor( penColor );
65 mPen.setWidthF( scaledWidth );
68 mPen.setStyle( Qt::CustomDashLine );
71 QVector<qreal> scaledVector;
78 mPen.setDashPattern( scaledVector );
108 mPen.setWidthF( scaledWidth );
109 mSelPen.setWidthF( scaledWidth );
115 p->drawPolyline( points );
120 p->drawPolyline( ::
offsetLine( points, scaledOffset ) );
128 map[
"width"] = QString::number(
mWidth );
132 map[
"offset"] = QString::number(
mOffset );
162 if ( p1.x() == p2.x() )
171 mT = float( p2.y() - p1.y() ) / ( p2.x() - p1.x() );
176 double x = ( p2.x() - p1.x() );
177 double y = ( p2.y() - p1.y() );
178 mLength = sqrt( x * x + y * y );
195 return (
mIncreasing ? QPointF( 0, interval ) : QPointF( 0, -interval ) );
197 double alpha = atan(
mT );
198 double dx = cos( alpha ) * interval;
199 double dy = sin( alpha ) * interval;
200 return (
mIncreasing ? QPointF( dx, dy ) : QPointF( -dx, -dy ) );
234 if ( props.contains(
"interval" ) )
235 interval = props[
"interval"].toDouble();
236 if ( props.contains(
"rotate" ) )
237 rotate = ( props[
"rotate"] ==
"1" );
240 if ( props.contains(
"offset" ) )
242 x->
setOffset( props[
"offset"].toDouble() );
245 if ( props.contains(
"placement" ) )
247 if ( props[
"placement"] ==
"vertex" )
249 else if ( props[
"placement"] ==
"lastvertex" )
251 else if ( props[
"placement"] ==
"firstvertex" )
253 else if ( props[
"placement"] ==
"centralpoint" )
318 if ( points.isEmpty() )
321 QPointF lastPt = points[0];
322 double lengthLeft = 0;
330 for (
int i = 1; i < points.count(); ++i )
332 const QPointF& pt = points[i];
343 double c = 1 - lengthLeft / painterUnitInterval;
361 while ( lengthLeft > painterUnitInterval )
365 lengthLeft -= painterUnitInterval;
378 static double _averageAngle(
const QPointF& prevPt,
const QPointF& pt,
const QPointF& nextPt )
383 double unitX = cos( a1 ) + cos( a2 ), unitY = sin( a1 ) + sin( a2 );
385 return atan2( unitY, unitX );
390 if ( points.isEmpty() )
407 i = points.count() - 1;
408 maxCount = points.count();
413 maxCount = points.count();
414 if ( points.first() == points.last() )
418 for ( ; i < maxCount; ++i )
420 const QPointF& pt = points[i];
430 const QPointF& nextPt = points[i+1];
438 const QPointF& prevPt = points[points.count() - 2];
439 const QPointF& nextPt = points[1];
440 if ( prevPt == pt || nextPt == pt )
446 else if ( i == points.count() - 1 )
451 const QPointF& prevPt = points[i-1];
465 const QPointF& prevPt = points[i-1];
466 const QPointF& nextPt = points[i+1];
467 if ( prevPt == pt || nextPt == pt )
486 QPolygonF::const_iterator it = points.constBegin();
488 for ( ++it; it != points.constEnd(); ++it )
490 length += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
491 ( last.y() - it->y() ) * ( last.y() - it->y() ) );
496 it = points.constBegin();
498 qreal last_at = 0, next_at = 0;
501 for ( ++it; it != points.constEnd(); ++it )
504 next_at += sqrt(( last.x() - it->x() ) * ( last.x() - it->x() ) +
505 ( last.y() - it->y() ) * ( last.y() - it->y() ) );
506 if ( next_at >= length / 2 )
515 qreal k = ( length * 0.5 - last_at ) / ( next_at - last_at );
516 QPointF pt = last + ( next - last ) * k;
532 map[
"interval"] = QString::number(
mInterval );
533 map[
"offset"] = QString::number(
mOffset );
535 map[
"placement"] =
"vertex";
537 map[
"placement"] =
"lastvertex";
539 map[
"placement"] =
"firstvertex";
541 map[
"placement"] =
"centralpoint";
543 map[
"placement"] =
"interval";
602 if ( props.contains(
"color" ) )
604 if ( props.contains(
"width" ) )
605 width = props[
"width"].toDouble();
612 return "LineDecoration";
618 penColor.setAlphaF( context.
alpha() );
620 mPen.setColor( penColor );
641 int cnt = points.count();
646 QPointF p2 = points.at( --cnt );
647 QPointF p1 = points.at( --cnt );
648 while ( p2 == p1 && cnt )
649 p1 = points.at( --cnt );
656 double angle = atan2( p2.y() - p1.y(), p2.x() - p1.x() );
658 double angle1 = angle +
M_PI / 6;
659 double angle2 = angle -
M_PI / 6;
661 QPointF p2_1 = p2 - QPointF( size * cos( angle1 ), size * sin( angle1 ) );
662 QPointF p2_2 = p2 - QPointF( size * cos( angle2 ), size * sin( angle2 ) );
665 p->drawLine( p2, p2_1 );
666 p->drawLine( p2, p2_2 );
673 map[
"width"] = QString::number(
mWidth );