//! Wrapper for QPainter::fillRect() void QwtPainter::fillRect( QPainter *painter, const QRectF &rect, const QBrush &brush ) { if ( !rect.isValid() ) return; QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); /* Performance of Qt4 is horrible for a non trivial brush. Without clipping expect minutes or hours for repainting large rectangles (might result from zooming) */ if ( deviceClipping ) clipRect &= painter->window(); else clipRect = painter->window(); if ( painter->hasClipping() ) clipRect &= painter->clipRegion().boundingRect(); QRectF r = rect; if ( deviceClipping ) r = r.intersected( clipRect ); if ( r.isValid() ) painter->fillRect( r, brush ); }
//! Wrapper for QPainter::drawPoints() void QwtPainter::drawPoints( QPainter *painter, const QPoint *points, int pointCount ) { QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); if ( deviceClipping ) { const int minX = qCeil( clipRect.left() ); const int maxX = qFloor( clipRect.right() ); const int minY = qCeil( clipRect.top() ); const int maxY = qFloor( clipRect.bottom() ); const QRect r( minX, minY, maxX - minX, maxY - minY ); QPolygon clippedPolygon( pointCount ); QPoint *clippedData = clippedPolygon.data(); int numClippedPoints = 0; for ( int i = 0; i < pointCount; i++ ) { if ( r.contains( points[i] ) ) clippedData[ numClippedPoints++ ] = points[i]; } painter->drawPoints( clippedData, numClippedPoints ); } else { painter->drawPoints( points, pointCount ); } }
//! Wrapper for QPainter::drawRect() void QwtPainter::drawRect( QPainter *painter, const QRectF &rect ) { const QRectF r = rect; QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); if ( deviceClipping ) { if ( !clipRect.intersects( r ) ) return; if ( !clipRect.contains( r ) ) { fillRect( painter, r & clipRect, painter->brush() ); painter->save(); painter->setBrush( Qt::NoBrush ); drawPolyline( painter, QPolygonF( r ) ); painter->restore(); return; } } painter->drawRect( r ); }
//! Wrapper for QPainter::drawPoint() void QwtPainter::drawPoint( QPainter *painter, const QPointF &pos ) { QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); if ( deviceClipping && !clipRect.contains( pos ) ) return; painter->drawPoint( pos ); }
//! Wrapper for QPainter::drawEllipse() void QwtPainter::drawEllipse( QPainter *painter, const QRectF &rect ) { QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); if ( deviceClipping && !clipRect.contains( rect ) ) return; painter->drawEllipse( rect ); }
//! Wrapper for QPainter::drawPolygon() void QwtPainter::drawPolygon( QPainter *painter, const QPolygon &polygon ) { QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); QPolygon cpa = polygon; if ( deviceClipping ) cpa = QwtClipper::clipPolygon( clipRect, polygon ); painter->drawPolygon( cpa ); }
//! Wrapper for QPainter::drawPolyline() void QwtPainter::drawPolyline( QPainter *painter, const QPolygon &polygon ) { QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); QPolygon cpa = polygon; if ( deviceClipping ) cpa = QwtClipper::clipPolygon( clipRect, cpa ); qwtDrawPolyline<QPoint>( painter, cpa.constData(), cpa.size(), d_polylineSplitting ); }
//! Wrapper for QPainter::drawText() void QwtPainter::drawText( QPainter *painter, const QPointF &pos, const QString &text ) { QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); if ( deviceClipping && !clipRect.contains( pos ) ) return; painter->save(); qwtUnscaleFont( painter ); painter->drawText( pos, text ); painter->restore(); }
//! Wrapper for QPainter::drawLine() void QwtPainter::drawLine( QPainter *painter, const QPointF &p1, const QPointF &p2 ) { QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); if ( deviceClipping && !( clipRect.contains( p1 ) && clipRect.contains( p2 ) ) ) { QPolygonF polygon; polygon += p1; polygon += p2; drawPolyline( painter, polygon ); return; } painter->drawLine( p1, p2 ); }
//! Wrapper for QPainter::drawPolyline() void QwtPainter::drawPolyline( QPainter *painter, const QPoint *points, int pointCount ) { QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); if ( deviceClipping ) { QPolygon polygon( pointCount ); ::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) ); polygon = QwtClipper::clipPolygon( clipRect, polygon ); qwtDrawPolyline<QPoint>( painter, polygon.constData(), polygon.size(), d_polylineSplitting ); } else qwtDrawPolyline<QPoint>( painter, points, pointCount, d_polylineSplitting ); }
//! Wrapper for QPainter::drawPoint() void QwtPainter::drawPoint( QPainter *painter, const QPoint &pos ) { QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); if ( deviceClipping ) { const int minX = qCeil( clipRect.left() ); const int maxX = qFloor( clipRect.right() ); const int minY = qCeil( clipRect.top() ); const int maxY = qFloor( clipRect.bottom() ); if ( pos.x() < minX || pos.x() > maxX || pos.y() < minY || pos.y() > maxY ) { return; } } painter->drawPoint( pos ); }
//! Wrapper for QPainter::drawPoints() void QwtPainter::drawPoints( QPainter *painter, const QPointF *points, int pointCount ) { QRectF clipRect; const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); if ( deviceClipping ) { QPolygonF clippedPolygon( pointCount ); QPointF *clippedData = clippedPolygon.data(); int numClippedPoints = 0; for ( int i = 0; i < pointCount; i++ ) { if ( clipRect.contains( points[i] ) ) clippedData[ numClippedPoints++ ] = points[i]; } painter->drawPoints( clippedData, numClippedPoints ); } else { painter->drawPoints( points, pointCount ); } }