16 #include <qpainterpath.h>
18 #include <qpaintengine.h>
20 #include <qsvgrenderer.h>
35 const QPen& pen,
const QBrush& brush )
40 QPainter painter( &graphic );
41 painter.setPen( pen );
42 painter.setBrush( brush );
43 painter.drawPath( path );
52 QSizeF scaledSize =
size;
53 if ( scaledSize.isEmpty() )
59 if ( sz.width() > 0.0 )
60 sx = scaledSize.width() / sz.width();
63 if ( sz.height() > 0.0 )
64 sy = scaledSize.height() / sz.height();
70 const QPointF* points,
int numPoints,
const QwtSymbol& symbol )
76 const QTransform transform = painter->transform();
77 if ( transform.isScaling() )
79 const QRect r( 0, 0,
size.width(),
size.height() );
80 size = transform.mapRect( r ).size();
83 QPixmap pm = symbol.
pixmap();
84 if ( pm.size() !=
size )
85 pm = pm.scaled(
size );
87 QPointF pinPoint( 0.5 *
size.width(), 0.5 *
size.height() );
91 painter->resetTransform();
93 for (
int i = 0; i < numPoints; i++ )
95 const QPointF pos = transform.map( points[i] ) - pinPoint;
98 QRect( pos.toPoint(), pm.size() ), pm );
105 const QPointF* points,
int numPoints,
106 QSvgRenderer* renderer,
const QwtSymbol& symbol )
108 if ( renderer == NULL || !renderer->isValid() )
111 const QRectF viewBox = renderer->viewBoxF();
112 if ( viewBox.isEmpty() )
115 QSizeF sz = symbol.
size();
119 const double sx = sz.width() / viewBox.width();
120 const double sy = sz.height() / viewBox.height();
122 QPointF pinPoint = viewBox.center();
126 const double dx = sx * ( pinPoint.x() - viewBox.left() );
127 const double dy = sy * ( pinPoint.y() - viewBox.top() );
129 for (
int i = 0; i < numPoints; i++ )
131 const double x = points[i].x() - dx;
132 const double y = points[i].y() - dy;
134 renderer->render( painter,
135 QRectF(
x,
y, sz.width(), sz.height() ) );
142 const QPointF* points,
int numPoints,
const QwtGraphic& graphic,
146 if ( pointRect.isEmpty() )
152 const QSize sz = symbol.
size();
155 sx = sz.width() / pointRect.width();
156 sy = sz.height() / pointRect.height();
159 QPointF pinPoint = pointRect.center();
163 const QTransform transform = painter->transform();
165 for (
int i = 0; i < numPoints; i++ )
167 QTransform tr = transform;
168 tr.translate( points[i].
x(), points[i].
y() );
170 tr.translate( -pinPoint.x(), -pinPoint.y() );
172 painter->setTransform( tr );
174 graphic.
render( painter );
177 painter->setTransform( transform );
181 const QPointF* points,
int numPoints,
const QwtSymbol& symbol )
183 painter->setBrush( symbol.
brush() );
184 painter->setPen( symbol.
pen() );
190 const int sw =
size.width();
191 const int sh =
size.height();
192 const int sw2 =
size.width() / 2;
193 const int sh2 =
size.height() / 2;
195 for (
int i = 0; i < numPoints; i++ )
197 const int x = qRound( points[i].
x() );
198 const int y = qRound( points[i].
y() );
200 const QRectF r(
x - sw2,
y - sh2, sw,
sh );
206 const double sw =
size.width();
207 const double sh =
size.height();
208 const double sw2 = 0.5 *
size.width();
209 const double sh2 = 0.5 *
size.height();
211 for (
int i = 0; i < numPoints; i++ )
213 const double x = points[i].x();
214 const double y = points[i].y();
216 const QRectF r(
x - sw2,
y - sh2, sw,
sh );
223 const QPointF* points,
int numPoints,
const QwtSymbol& symbol )
227 QPen pen = symbol.
pen();
228 pen.setJoinStyle( Qt::MiterJoin );
229 painter->setPen( pen );
230 painter->setBrush( symbol.
brush() );
231 painter->setRenderHint( QPainter::Antialiasing,
false );
235 const int sw =
size.width();
236 const int sh =
size.height();
237 const int sw2 =
size.width() / 2;
238 const int sh2 =
size.height() / 2;
240 for (
int i = 0; i < numPoints; i++ )
242 const int x = qRound( points[i].
x() );
243 const int y = qRound( points[i].
y() );
245 const QRect r(
x - sw2,
y - sh2, sw,
sh );
251 const double sw =
size.width();
252 const double sh =
size.height();
253 const double sw2 = 0.5 *
size.width();
254 const double sh2 = 0.5 *
size.height();
256 for (
int i = 0; i < numPoints; i++ )
258 const double x = points[i].x();
259 const double y = points[i].y();
261 const QRectF r(
x - sw2,
y - sh2, sw,
sh );
268 const QPointF* points,
int numPoints,
const QwtSymbol& symbol )
272 QPen pen = symbol.
pen();
273 pen.setJoinStyle( Qt::MiterJoin );
274 painter->setPen( pen );
275 painter->setBrush( symbol.
brush() );
279 for (
int i = 0; i < numPoints; i++ )
281 const int x = qRound( points[i].
x() );
282 const int y = qRound( points[i].
y() );
284 const int x1 =
x -
size.width() / 2;
285 const int y1 =
y -
size.height() / 2;
286 const int x2 = x1 +
size.width();
287 const int y2 = y1 +
size.height();
290 polygon += QPointF(
x, y1 );
291 polygon += QPointF( x1,
y );
292 polygon += QPointF(
x, y2 );
293 polygon += QPointF( x2,
y );
300 for (
int i = 0; i < numPoints; i++ )
302 const QPointF& pos = points[i];
304 const double x1 = pos.x() - 0.5 *
size.width();
305 const double y1 = pos.y() - 0.5 *
size.height();
306 const double x2 = x1 +
size.width();
307 const double y2 = y1 +
size.height();
310 polygon += QPointF( pos.x(), y1 );
311 polygon += QPointF( x2, pos.y() );
312 polygon += QPointF( pos.x(), y2 );
313 polygon += QPointF( x1, pos.y() );
322 const QPointF* points,
int numPoints,
327 QPen pen = symbol.
pen();
328 pen.setJoinStyle( Qt::MiterJoin );
329 painter->setPen( pen );
331 painter->setBrush( symbol.
brush() );
335 double sw2 = 0.5 *
size.width();
336 double sh2 = 0.5 *
size.height();
340 sw2 = std::floor( sw2 );
341 sh2 = std::floor( sh2 );
344 QPolygonF triangle( 3 );
345 QPointF* trianglePoints = triangle.data();
347 for (
int i = 0; i < numPoints; i++ )
349 const QPointF& pos = points[i];
360 const double x1 =
x - sw2;
361 const double x2 = x1 +
size.width();
362 const double y1 =
y - sh2;
363 const double y2 = y1 +
size.height();
369 trianglePoints[0].rx() = x2;
370 trianglePoints[0].ry() = y1;
372 trianglePoints[1].rx() = x1;
373 trianglePoints[1].ry() =
y;
375 trianglePoints[2].rx() = x2;
376 trianglePoints[2].ry() = y2;
382 trianglePoints[0].rx() = x1;
383 trianglePoints[0].ry() = y1;
385 trianglePoints[1].rx() = x2;
386 trianglePoints[1].ry() =
y;
388 trianglePoints[2].rx() = x1;
389 trianglePoints[2].ry() = y2;
395 trianglePoints[0].rx() = x1;
396 trianglePoints[0].ry() = y2;
398 trianglePoints[1].rx() =
x;
399 trianglePoints[1].ry() = y1;
401 trianglePoints[2].rx() = x2;
402 trianglePoints[2].ry() = y2;
408 trianglePoints[0].rx() = x1;
409 trianglePoints[0].ry() = y1;
411 trianglePoints[1].rx() =
x;
412 trianglePoints[1].ry() = y2;
414 trianglePoints[2].rx() = x2;
415 trianglePoints[2].ry() = y1;
425 QPainter* painter,
int orientations,
426 const QPointF* points,
int numPoints,
const QwtSymbol& symbol )
432 QPen pen = symbol.
pen();
433 if ( pen.width() > 1 )
435 pen.setCapStyle( Qt::FlatCap );
439 painter->setPen( pen );
440 painter->setRenderHint( QPainter::Antialiasing,
false );
446 const int sw2 =
size.width() / 2;
447 const int sh2 =
size.height() / 2;
449 for (
int i = 0; i < numPoints; i++ )
451 if ( orientations & Qt::Horizontal )
453 const int x = qRound( points[i].
x() ) - sw2;
454 const int y = qRound( points[i].
y() );
458 if ( orientations & Qt::Vertical )
460 const int x = qRound( points[i].
x() );
461 const int y = qRound( points[i].
y() ) - sh2;
469 const double sw =
size.width();
470 const double sh =
size.height();
471 const double sw2 = 0.5 *
size.width();
472 const double sh2 = 0.5 *
size.height();
474 for (
int i = 0; i < numPoints; i++ )
476 if ( orientations & Qt::Horizontal )
478 const double x = points[i].x() - sw2;
479 const double y = points[i].y();
483 if ( orientations & Qt::Vertical )
485 const double y = points[i].y() - sh2;
486 const double x = points[i].x();
495 const QPointF* points,
int numPoints,
const QwtSymbol& symbol )
500 QPen pen = symbol.
pen();
501 if ( pen.width() > 1 )
503 pen.setCapStyle( Qt::FlatCap );
506 painter->setPen( pen );
511 const int sw =
size.width();
512 const int sh =
size.height();
513 const int sw2 =
size.width() / 2;
514 const int sh2 =
size.height() / 2;
516 for (
int i = 0; i < numPoints; i++ )
518 const QPointF& pos = points[i];
520 const int x = qRound( pos.x() );
521 const int y = qRound( pos.y() );
523 const int x1 =
x - sw2;
524 const int x2 = x1 + sw + off;
525 const int y1 =
y - sh2;
526 const int y2 = y1 +
sh + off;
534 const double sw =
size.width();
535 const double sh =
size.height();
536 const double sw2 = 0.5 *
size.width();
537 const double sh2 = 0.5 *
size.height();
539 for (
int i = 0; i < numPoints; i++ )
541 const QPointF& pos = points[i];
543 const double x1 = pos.x() - sw2;
544 const double x2 = x1 + sw;
545 const double y1 = pos.y() - sh2;
546 const double y2 = y1 +
sh;
555 const QPointF* points,
int numPoints,
const QwtSymbol& symbol )
558 painter->setPen( symbol.
pen() );
562 QRect r( 0, 0,
size.width(),
size.height() );
564 for (
int i = 0; i < numPoints; i++ )
566 r.moveCenter( points[i].toPoint() );
568 const double sqrt1_2 = 0.70710678118654752440;
570 const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 );
573 qRound( r.left() + d1 ), qRound( r.top() + d1 ),
574 qRound( r.right() - d1 ), qRound( r.bottom() - d1 ) );
576 qRound( r.left() + d1 ), qRound( r.bottom() - d1 ),
577 qRound( r.right() - d1), qRound( r.top() + d1 ) );
579 const QPoint c = r.center();
582 c.x(), r.top(), c.x(), r.bottom() );
584 r.left(), c.y(), r.right(), c.y() );
589 QRectF r( 0, 0,
size.width(),
size.height() );
591 for (
int i = 0; i < numPoints; i++ )
593 r.moveCenter( points[i] );
595 const double sqrt1_2 = 0.70710678118654752440;
597 const QPointF c = r.center();
598 const double d1 = r.width() / 2.0 * ( 1.0 - sqrt1_2 );
601 r.left() + d1, r.top() + d1,
602 r.right() - d1, r.bottom() - d1 );
604 r.left() + d1, r.bottom() - d1,
605 r.right() - d1, r.top() + d1 );
617 const QPointF* points,
int numPoints,
const QwtSymbol& symbol )
619 QPen pen = symbol.
pen();
620 if ( pen.width() > 1 )
621 pen.setCapStyle( Qt::FlatCap );
622 pen.setJoinStyle( Qt::MiterJoin );
623 painter->setPen( pen );
625 painter->setBrush( symbol.
brush() );
627 const double cos30 = 0.866025;
629 const double dy = 0.25 * symbol.
size().height();
630 const double dx = 0.5 * symbol.
size().width() * cos30 / 3.0;
632 QPolygonF star( 12 );
633 QPointF* starPoints = star.data();
637 for (
int i = 0; i < numPoints; i++ )
639 double x = points[i].x();
640 double y = points[i].y();
647 double x1 =
x - 3 * dx;
648 double y1 =
y - 2 * dy;
651 x1 = qRound(
x - 3 * dx );
652 y1 = qRound(
y - 2 * dy );
655 const double x2 = x1 + 1 * dx;
656 const double x3 = x1 + 2 * dx;
657 const double x4 = x1 + 3 * dx;
658 const double x5 = x1 + 4 * dx;
659 const double x6 = x1 + 5 * dx;
660 const double x7 = x1 + 6 * dx;
662 const double y2 = y1 + 1 * dy;
663 const double y3 = y1 + 2 * dy;
664 const double y4 = y1 + 3 * dy;
665 const double y5 = y1 + 4 * dy;
667 starPoints[0].rx() = x4;
668 starPoints[0].ry() = y1;
670 starPoints[1].rx() = x5;
671 starPoints[1].ry() = y2;
673 starPoints[2].rx() = x7;
674 starPoints[2].ry() = y2;
676 starPoints[3].rx() = x6;
677 starPoints[3].ry() = y3;
679 starPoints[4].rx() = x7;
680 starPoints[4].ry() = y4;
682 starPoints[5].rx() = x5;
683 starPoints[5].ry() = y4;
685 starPoints[6].rx() = x4;
686 starPoints[6].ry() = y5;
688 starPoints[7].rx() = x3;
689 starPoints[7].ry() = y4;
691 starPoints[8].rx() = x1;
692 starPoints[8].ry() = y4;
694 starPoints[9].rx() = x2;
695 starPoints[9].ry() = y3;
697 starPoints[10].rx() = x1;
698 starPoints[10].ry() = y2;
700 starPoints[11].rx() = x3;
701 starPoints[11].ry() = y2;
708 const QPointF* points,
int numPoints,
const QwtSymbol& symbol )
710 painter->setBrush( symbol.
brush() );
711 painter->setPen( symbol.
pen() );
713 const double cos30 = 0.866025;
714 const double dx = 0.5 * ( symbol.
size().width() - cos30 );
716 const double dy = 0.25 * symbol.
size().height();
718 QPolygonF hexaPolygon( 6 );
719 QPointF* hexaPoints = hexaPolygon.data();
723 for (
int i = 0; i < numPoints; i++ )
725 double x = points[i].x();
726 double y = points[i].y();
734 double y1 =
y - 2 * dy;
737 x1 = std::ceil( x1 );
738 y1 = std::ceil( y1 );
741 const double x2 = x1 + 1 * dx;
742 const double x3 = x1 + 2 * dx;
744 const double y2 = y1 + 1 * dy;
745 const double y3 = y1 + 3 * dy;
746 const double y4 = y1 + 4 * dy;
748 hexaPoints[0].rx() = x2;
749 hexaPoints[0].ry() = y1;
751 hexaPoints[1].rx() = x3;
752 hexaPoints[1].ry() = y2;
754 hexaPoints[2].rx() = x3;
755 hexaPoints[2].ry() = y3;
757 hexaPoints[3].rx() = x2;
758 hexaPoints[3].ry() = y4;
760 hexaPoints[4].rx() = x1;
761 hexaPoints[4].ry() = y3;
763 hexaPoints[5].rx() = x1;
764 hexaPoints[5].ry() = y2;
774 const QPen& pn,
const QSize& sz )
846 QPen( Qt::black, 0 ), QSize() );
859 const QPen& pen,
const QSize&
size )
879 const QBrush& brush,
const QPen& pen )
1069 if ( ( width >= 0 ) && ( height < 0 ) )
1072 setSize( QSize( width, height ) );
1142 qreal width, Qt::PenStyle style )
1308 const QPointF* points,
int numPoints )
const
1310 if ( numPoints <= 0 )
1313 bool useCache =
false;
1319 !painter->transform().isScaling() )
1327 switch( painter->paintEngine()->type() )
1329 case QPaintEngine::OpenGL:
1330 case QPaintEngine::OpenGL2:
1336 case QPaintEngine::OpenVG:
1337 case QPaintEngine::SVG:
1338 case QPaintEngine::Pdf:
1339 case QPaintEngine::Picture:
1345 case QPaintEngine::X11:
1396 p.setRenderHints( painter->renderHints() );
1397 p.translate( -br.topLeft() );
1399 const QPointF pos( 0.0, 0.0 );
1403 const int dx = br.left();
1404 const int dy = br.top();
1406 for (
int i = 0; i < numPoints; i++ )
1408 const int left = qRound( points[i].
x() ) + dx;
1409 const int top = qRound( points[i].
y() ) + dy;
1442 painter, rect, Qt::KeepAspectRatio );
1453 painter, rect, Qt::KeepAspectRatio );
1464 if ( !sz.isEmpty() )
1466 sz.scale( rect.size(), Qt::KeepAspectRatio );
1467 scaledRect.setSize( sz );
1468 scaledRect.moveCenter( rect.center() );
1476 painter, scaledRect );
1486 const double ratio = qMin( rect.width() / br.width(),
1487 rect.height() / br.height() );
1491 painter->translate( rect.center() );
1492 painter->scale( ratio, ratio );
1514 const QPointF* points,
int numPoints )
const
1536 points, numPoints, *
this );
1548 points, numPoints, *
this );
1554 points, numPoints, *
this );
1560 points, numPoints, *
this );
1566 points, numPoints, *
this );
1572 points, numPoints, *
this );
1578 points, numPoints, *
this );
1641 bool pinPointTranslation =
false;
1653 rect.setSize(
m_data->
size + QSizeF( pw, pw ) );
1654 rect.moveCenter( QPointF( 0.0, 0.0 ) );
1672 rect.setSize(
m_data->
size + QSizeF( 2 * pw, 2 * pw ) );
1673 rect.moveCenter( QPointF( 0.0, 0.0 ) );
1686 pinPointTranslation =
true;
1697 pinPointTranslation =
true;
1705 pinPointTranslation =
true;
1715 if (
m_data->
size.isValid() && !rect.isEmpty() )
1717 QSizeF sz = rect.size();
1719 const double sx =
m_data->
size.width() / sz.width();
1720 const double sy =
m_data->
size.height() / sz.height();
1722 QTransform transform;
1723 transform.scale( sx, sy );
1725 rect = transform.mapRect( rect );
1727 pinPointTranslation =
true;
1734 rect.moveCenter( QPointF( 0.0, 0.0 ) );
1738 if ( pinPointTranslation )
1748 r.setLeft(
qwtFloor( rect.left() ) );
1749 r.setTop(
qwtFloor( rect.top() ) );
1750 r.setRight(
qwtCeil( rect.right() ) );
1751 r.setBottom(
qwtCeil( rect.bottom() ) );
1754 r.adjust( -1, -1, 1, 1 );