21 #include <QSvgRenderer>
29 , mMarkerMode( DefaultMarker )
30 , mArrowColor( QColor( 0, 0, 0 ) )
37 , mStartPoint( startPoint )
38 , mStopPoint( stopPoint )
39 , mMarkerMode( DefaultMarker )
40 , mArrowColor( QColor( 0, 0, 0 ) )
54 mPen.setColor( QColor( 0, 0, 0 ) );
58 setPen( QPen( QColor( 255, 255, 255, 0 ) ) );
59 setBrush( QBrush( QColor( 255, 255, 255, 0 ) ) );
64 Q_UNUSED( itemStyle );
75 arrowPen.setCapStyle( Qt::FlatCap );
77 painter->setPen( arrowPen );
101 double startPointXPos = (
mStartPoint.x() - pos().x() ) / rect().width();
102 double startPointYPos = (
mStartPoint.y() - pos().y() ) / rect().height();
103 double stopPointXPos = (
mStopPoint.x() - pos().x() ) / rect().width();
104 double stopPointYPos = (
mStopPoint.y() - pos().y() ) / rect().height();
106 mStartPoint.setX( rectangle.left() + startPointXPos * rectangle.width() );
107 mStartPoint.setY( rectangle.top() + startPointYPos * rectangle.height() );
108 mStopPoint.setX( rectangle.left() + stopPointXPos * rectangle.width() );
109 mStopPoint.setY( rectangle.top() + stopPointYPos * rectangle.height() );
117 QBrush arrowBrush = p->brush();
119 p->setBrush( arrowBrush );
125 Q_UNUSED( markerPath );
128 double arrowHeadHeight;
139 int dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;
142 int imageHeight = arrowHeadHeight / 25.4 * dpi;
147 imageWidth *= qMin( viewScaleFactor, 10.0 );
148 imageHeight *= qMin( viewScaleFactor, 10.0 );
150 QImage markerImage( imageWidth, imageHeight, QImage::Format_ARGB32 );
151 QColor markerBG( 255, 255, 255, 0 );
152 markerImage.fill( markerBG.rgba() );
154 QPointF imageFixPoint;
165 imageFixPoint.setY( 0 );
189 fixPoint.setX( 0 ); fixPoint.setY( arrowHeadHeight / 2.0 );
193 fixPoint.setX( 0 ); fixPoint.setY( -arrowHeadHeight / 2.0 );
195 QPointF rotatedFixPoint;
196 double angleRad = ang / 180 *
M_PI;
197 rotatedFixPoint.setX( fixPoint.x() * cos( angleRad ) + fixPoint.y() * -sin( angleRad ) );
198 rotatedFixPoint.setY( fixPoint.x() * sin( angleRad ) + fixPoint.y() * cos( angleRad ) );
201 QPainter imagePainter( &markerImage );
202 r.render( &imagePainter );
205 p->translate( canvasPoint.x() - rotatedFixPoint.x() , canvasPoint.y() - rotatedFixPoint.y() );
209 p->drawImage( QRectF( 0, 0,
mArrowHeadWidth, arrowHeadHeight ), markerImage, QRectF( 0, 0, imageWidth, imageHeight ) );
218 if ( !r.load( svgPath ) )
226 QRect viewBox = r.viewBox();
234 if ( !r.load( svgPath ) )
242 QRect viewBox = r.viewBox();
249 mPen.setWidthF( width );
273 enlarge =
mPen.widthF() / 2.0;
281 rect.adjust( -enlarge, -enlarge, enlarge, enlarge );
287 QDomElement composerArrowElem = doc.createElement(
"ComposerArrow" );
288 composerArrowElem.setAttribute(
"outlineWidth", QString::number(
outlineWidth() ) );
289 composerArrowElem.setAttribute(
"arrowHeadWidth", QString::number(
mArrowHeadWidth ) );
290 composerArrowElem.setAttribute(
"markerMode",
mMarkerMode );
292 composerArrowElem.setAttribute(
"endMarkerFile",
mEndMarkerFile );
295 QDomElement arrowColorElem = doc.createElement(
"ArrowColor" );
296 arrowColorElem.setAttribute(
"red",
mArrowColor.red() );
297 arrowColorElem.setAttribute(
"green",
mArrowColor.green() );
298 arrowColorElem.setAttribute(
"blue",
mArrowColor.blue() );
299 arrowColorElem.setAttribute(
"alpha",
mArrowColor.alpha() );
300 composerArrowElem.appendChild( arrowColorElem );
303 QDomElement startPointElem = doc.createElement(
"StartPoint" );
304 startPointElem.setAttribute(
"x", QString::number(
mStartPoint.x() ) );
305 startPointElem.setAttribute(
"y", QString::number(
mStartPoint.y() ) );
306 composerArrowElem.appendChild( startPointElem );
309 QDomElement stopPointElem = doc.createElement(
"StopPoint" );
310 stopPointElem.setAttribute(
"x", QString::number(
mStopPoint.x() ) );
311 stopPointElem.setAttribute(
"y", QString::number(
mStopPoint.y() ) );
312 composerArrowElem.appendChild( stopPointElem );
314 elem.appendChild( composerArrowElem );
315 return _writeXML( composerArrowElem, doc );
320 mArrowHeadWidth = itemElem.attribute(
"arrowHeadWidth",
"2.0" ).toDouble();
321 mPen.setWidthF( itemElem.attribute(
"outlineWidth",
"1.0" ).toDouble() );
323 setEndMarker( itemElem.attribute(
"endMarkerFile",
"" ) );
327 QDomNodeList arrowColorList = itemElem.elementsByTagName(
"ArrowColor" );
328 if ( arrowColorList.size() > 0 )
330 QDomElement arrowColorElem = arrowColorList.at( 0 ).toElement();
331 int red = arrowColorElem.attribute(
"red",
"0" ).toInt();
332 int green = arrowColorElem.attribute(
"green",
"0" ).toInt();
333 int blue = arrowColorElem.attribute(
"blue",
"0" ).toInt();
334 int alpha = arrowColorElem.attribute(
"alpha",
"255" ).toInt();
340 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
341 if ( composerItemList.size() > 0 )
343 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
348 QDomNodeList startPointList = itemElem.elementsByTagName(
"StartPoint" );
349 if ( startPointList.size() > 0 )
351 QDomElement startPointElem = startPointList.at( 0 ).toElement();
352 mStartPoint.setX( startPointElem.attribute(
"x",
"0.0" ).toDouble() );
353 mStartPoint.setY( startPointElem.attribute(
"y",
"0.0" ).toDouble() );
357 QDomNodeList stopPointList = itemElem.elementsByTagName(
"StopPoint" );
358 if ( stopPointList.size() > 0 )
360 QDomElement stopPointElem = stopPointList.at( 0 ).toElement();
361 mStopPoint.setX( stopPointElem.attribute(
"x",
"0.0" ).toDouble() );
362 mStopPoint.setY( stopPointElem.attribute(
"y",
"0.0" ).toDouble() );