|
19 | 19 | #include "qgscomposition.h"
|
20 | 20 | #include <QPainter>
|
21 | 21 | #include <QSvgRenderer>
|
| 22 | +#include <QVector2D> |
22 | 23 |
|
23 | 24 | #include <cmath>
|
24 | 25 |
|
@@ -76,7 +77,6 @@ void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem
|
76 | 77 |
|
77 | 78 | //draw arrow
|
78 | 79 | QPen arrowPen = mPen;
|
79 |
| - arrowPen.setCapStyle( Qt::FlatCap ); |
80 | 80 | arrowPen.setColor( mArrowColor );
|
81 | 81 | painter->setPen( arrowPen );
|
82 | 82 | painter->setBrush( QBrush( mArrowColor ) );
|
@@ -134,7 +134,9 @@ void QgsComposerArrow::drawHardcodedMarker( QPainter *p, MarkerType type )
|
134 | 134 | QBrush arrowBrush = p->brush();
|
135 | 135 | arrowBrush.setColor( mArrowColor );
|
136 | 136 | p->setBrush( arrowBrush );
|
137 |
| - drawArrowHead( p, mStopPoint.x() - pos().x(), mStopPoint.y() - pos().y(), angle( mStartPoint, mStopPoint ), mArrowHeadWidth ); |
| 137 | + QVector2D dir = QVector2D( mStopPoint - mStartPoint ).normalized(); |
| 138 | + QPointF stop = mStopPoint + ( dir * 0.5 * mArrowHeadWidth ).toPointF(); |
| 139 | + drawArrowHead( p, stop.x() - pos().x(), stop.y() - pos().y(), angle( mStartPoint, stop ), mArrowHeadWidth ); |
138 | 140 | }
|
139 | 141 |
|
140 | 142 | void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QString &markerPath )
|
@@ -199,27 +201,11 @@ void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QStrin
|
199 | 201 | }
|
200 | 202 | }
|
201 | 203 |
|
202 |
| - //rotate image fix point for backtransform |
203 |
| - QPointF fixPoint; |
204 |
| - if ( type == StartMarker ) |
205 |
| - { |
206 |
| - fixPoint.setX( 0 ); fixPoint.setY( arrowHeadHeight / 2.0 ); |
207 |
| - } |
208 |
| - else |
209 |
| - { |
210 |
| - fixPoint.setX( 0 ); fixPoint.setY( -arrowHeadHeight / 2.0 ); |
211 |
| - } |
212 |
| - QPointF rotatedFixPoint; |
213 |
| - double angleRad = ang / 180 * M_PI; |
214 |
| - rotatedFixPoint.setX( fixPoint.x() * cos( angleRad ) + fixPoint.y() * -sin( angleRad ) ); |
215 |
| - rotatedFixPoint.setY( fixPoint.x() * sin( angleRad ) + fixPoint.y() * cos( angleRad ) ); |
216 |
| - |
217 |
| - |
218 | 204 | QPainter imagePainter( &markerImage );
|
219 | 205 | r.render( &imagePainter );
|
220 | 206 |
|
221 | 207 | p->save();
|
222 |
| - p->translate( canvasPoint.x() - rotatedFixPoint.x() , canvasPoint.y() - rotatedFixPoint.y() ); |
| 208 | + p->translate( canvasPoint.x() , canvasPoint.y() ); |
223 | 209 | p->rotate( ang );
|
224 | 210 | p->translate( -mArrowHeadWidth / 2.0, -arrowHeadHeight / 2.0 );
|
225 | 211 |
|
@@ -280,16 +266,18 @@ double QgsComposerArrow::computeMarkerMargin() const
|
280 | 266 | double margin = 0;
|
281 | 267 | if ( mMarkerMode == DefaultMarker )
|
282 | 268 | {
|
283 |
| - margin = mPen.widthF() / 2.0 + mArrowHeadWidth / 2.0; |
| 269 | + margin = mPen.widthF() / std::sqrt( 2.0 ) + mArrowHeadWidth / 2.0; |
284 | 270 | }
|
285 | 271 | else if ( mMarkerMode == NoMarker )
|
286 | 272 | {
|
287 |
| - margin = mPen.widthF() / 2.0; |
| 273 | + margin = mPen.widthF() / std::sqrt( 2.0 ); |
288 | 274 | }
|
289 | 275 | else if ( mMarkerMode == SVGMarker )
|
290 | 276 | {
|
291 |
| - double maxArrowHeight = qMax( mStartArrowHeadHeight, mStopArrowHeadHeight ); |
292 |
| - margin = mPen.widthF() / 2 + qMax( mArrowHeadWidth / 2.0, maxArrowHeight / 2.0 ); |
| 277 | + double startMarkerMargin = std::sqrt( 0.25 * ( mStartArrowHeadHeight * mStartArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) ); |
| 278 | + double stopMarkerMargin = std::sqrt( 0.25 * ( mStopArrowHeadHeight * mStopArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) ); |
| 279 | + double markerMargin = qMax( startMarkerMargin, stopMarkerMargin ); |
| 280 | + margin = qMax( mPen.widthF() / std::sqrt( 2.0 ), markerMargin ); |
293 | 281 | }
|
294 | 282 | return margin;
|
295 | 283 | }
|
|
0 commit comments