@@ -105,43 +105,15 @@ void QgsComposerArrow::setSceneRect( const QRectF& rectangle )
105
105
106
106
void QgsComposerArrow::drawHardcodedMarker ( QPainter* p, MarkerType type )
107
107
{
108
- double angle = arrowAngle ();
109
- // qWarning(QString::number(angle).toLocal8Bit().data());
110
- double angleRad = angle / 180.0 * M_PI;
111
- QPointF middlePoint = QPointF ( mStopPoint .x () - transform ().dx (), mStopPoint .y () - transform ().dy () );
112
-
113
- // rotate both arrow points
114
- QPointF p1 = QPointF ( -mArrowHeadWidth / 2.0 , mArrowHeadWidth );
115
- QPointF p2 = QPointF ( mArrowHeadWidth / 2.0 , mArrowHeadWidth );
116
-
117
- QPointF p1Rotated, p2Rotated;
118
- p1Rotated.setX ( p1.x () * cos ( angleRad ) + p1.y () * -sin ( angleRad ) );
119
- p1Rotated.setY ( p1.x () * sin ( angleRad ) + p1.y () * cos ( angleRad ) );
120
- p2Rotated.setX ( p2.x () * cos ( angleRad ) + p2.y () * -sin ( angleRad ) );
121
- p2Rotated.setY ( p2.x () * sin ( angleRad ) + p2.y () * cos ( angleRad ) );
122
-
123
- QPolygonF arrowHeadPoly;
124
- arrowHeadPoly << middlePoint;
125
- arrowHeadPoly << QPointF ( middlePoint.x () + p1Rotated.x (), middlePoint.y () + p1Rotated.y () );
126
- arrowHeadPoly << QPointF ( middlePoint.x () + p2Rotated.x (), middlePoint.y () + p2Rotated.y () );
127
-
128
- p->save ();
129
-
130
- QPen arrowPen = p->pen ();
131
- arrowPen.setJoinStyle ( Qt::RoundJoin );
132
108
QBrush arrowBrush = p->brush ();
133
109
arrowBrush.setColor ( mArrowColor );
134
- arrowBrush.setStyle ( Qt::SolidPattern );
135
- p->setPen ( arrowPen );
136
110
p->setBrush ( arrowBrush );
137
- p->drawPolygon ( arrowHeadPoly );
138
-
139
- p->restore ();
111
+ drawArrowHead ( p, mStopPoint .x () - transform ().dx (), mStopPoint .y () - transform ().dy (), angle ( mStartPoint , mStopPoint ), mArrowHeadWidth );
140
112
}
141
113
142
114
void QgsComposerArrow::drawSVGMarker ( QPainter* p, MarkerType type, const QString& markerPath )
143
115
{
144
- double angle = arrowAngle ( );
116
+ double ang = angle ( mStartPoint , mStopPoint );
145
117
146
118
double arrowHeadHeight;
147
119
if ( type == StartMarker )
@@ -211,7 +183,7 @@ void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QStrin
211
183
fixPoint.setX ( 0 ); fixPoint.setY ( -arrowHeadHeight / 2.0 );
212
184
}
213
185
QPointF rotatedFixPoint;
214
- double angleRad = angle / 180 * M_PI;
186
+ double angleRad = ang / 180 * M_PI;
215
187
rotatedFixPoint.setX ( fixPoint.x () * cos ( angleRad ) + fixPoint.y () * -sin ( angleRad ) );
216
188
rotatedFixPoint.setY ( fixPoint.x () * sin ( angleRad ) + fixPoint.y () * cos ( angleRad ) );
217
189
@@ -221,7 +193,7 @@ void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QStrin
221
193
222
194
p->save ();
223
195
p->translate ( canvasPoint.x () - rotatedFixPoint.x () , canvasPoint.y () - rotatedFixPoint.y () );
224
- p->rotate ( angle );
196
+ p->rotate ( ang );
225
197
p->translate ( -mArrowHeadWidth / 2.0 , -arrowHeadHeight / 2.0 );
226
198
227
199
p->drawImage ( QRectF ( 0 , 0 , mArrowHeadWidth , arrowHeadHeight ), markerImage, QRectF ( 0 , 0 , imageWidth, imageHeight ) );
@@ -230,20 +202,6 @@ void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QStrin
230
202
return ;
231
203
}
232
204
233
- double QgsComposerArrow::arrowAngle () const
234
- {
235
- double xDiff = mStopPoint .x () - mStartPoint .x ();
236
- double yDiff = mStopPoint .y () - mStartPoint .y ();
237
- double length = sqrt ( xDiff * xDiff + yDiff * yDiff );
238
-
239
- double angle = acos (( -yDiff * length ) / ( length * length ) ) * 180 / M_PI;
240
- if ( xDiff < 0 )
241
- {
242
- return ( 360 - angle );
243
- }
244
- return angle;
245
- }
246
-
247
205
void QgsComposerArrow::setStartMarker ( const QString& svgPath )
248
206
{
249
207
QSvgRenderer r;
0 commit comments