400
449
const QPointF *points, int pointCount )
403
const bool deviceClipping = isClippingNeeded( painter, clipRect );
452
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
405
454
if ( deviceClipping )
407
456
QPolygonF polygon( pointCount );
408
qMemCopy( polygon.data(), points, pointCount * sizeof( QPointF ) );
457
::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
410
459
polygon = QwtClipper::clipPolygonF( clipRect, polygon );
411
::drawPolyline( painter,
412
polygon.constData(), polygon.size(), d_polylineSplitting );
415
::drawPolyline( painter, points, pointCount, d_polylineSplitting );
460
qwtDrawPolyline<QPointF>( painter,
461
polygon.constData(), polygon.size(), d_polylineSplitting );
465
qwtDrawPolyline<QPointF>( painter, points, pointCount, d_polylineSplitting );
469
//! Wrapper for QPainter::drawPolygon()
470
void QwtPainter::drawPolygon( QPainter *painter, const QPolygon &polygon )
473
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
475
QPolygon cpa = polygon;
476
if ( deviceClipping )
477
cpa = QwtClipper::clipPolygon( clipRect, polygon );
479
painter->drawPolygon( cpa );
482
//! Wrapper for QPainter::drawPolyline()
483
void QwtPainter::drawPolyline( QPainter *painter, const QPolygon &polygon )
486
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
488
QPolygon cpa = polygon;
489
if ( deviceClipping )
490
cpa = QwtClipper::clipPolygon( clipRect, cpa );
492
qwtDrawPolyline<QPoint>( painter,
493
cpa.constData(), cpa.size(), d_polylineSplitting );
496
//! Wrapper for QPainter::drawPolyline()
497
void QwtPainter::drawPolyline( QPainter *painter,
498
const QPoint *points, int pointCount )
501
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
503
if ( deviceClipping )
505
QPolygon polygon( pointCount );
506
::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) );
508
polygon = QwtClipper::clipPolygon( clipRect, polygon );
509
qwtDrawPolyline<QPoint>( painter,
510
polygon.constData(), polygon.size(), d_polylineSplitting );
513
qwtDrawPolyline<QPoint>( painter, points, pointCount, d_polylineSplitting );
418
516
//! Wrapper for QPainter::drawPoint()
419
517
void QwtPainter::drawPoint( QPainter *painter, const QPointF &pos )
422
const bool deviceClipping = isClippingNeeded( painter, clipRect );
520
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
424
522
if ( deviceClipping && !clipRect.contains( pos ) )
427
525
painter->drawPoint( pos );
528
//! Wrapper for QPainter::drawPoint()
529
void QwtPainter::drawPoint( QPainter *painter, const QPoint &pos )
532
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
534
if ( deviceClipping )
536
const int minX = qCeil( clipRect.left() );
537
const int maxX = qFloor( clipRect.right() );
538
const int minY = qCeil( clipRect.top() );
539
const int maxY = qFloor( clipRect.bottom() );
541
if ( pos.x() < minX || pos.x() > maxX
542
|| pos.y() < minY || pos.y() > maxY )
548
painter->drawPoint( pos );
551
//! Wrapper for QPainter::drawPoints()
552
void QwtPainter::drawPoints( QPainter *painter,
553
const QPoint *points, int pointCount )
556
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
558
if ( deviceClipping )
560
const int minX = qCeil( clipRect.left() );
561
const int maxX = qFloor( clipRect.right() );
562
const int minY = qCeil( clipRect.top() );
563
const int maxY = qFloor( clipRect.bottom() );
565
const QRect r( minX, minY, maxX - minX, maxY - minY );
567
QPolygon clippedPolygon( pointCount );
568
QPoint *clippedData = clippedPolygon.data();
570
int numClippedPoints = 0;
571
for ( int i = 0; i < pointCount; i++ )
573
if ( r.contains( points[i] ) )
574
clippedData[ numClippedPoints++ ] = points[i];
576
painter->drawPoints( clippedData, numClippedPoints );
580
painter->drawPoints( points, pointCount );
584
//! Wrapper for QPainter::drawPoints()
585
void QwtPainter::drawPoints( QPainter *painter,
586
const QPointF *points, int pointCount )
589
const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
591
if ( deviceClipping )
593
QPolygonF clippedPolygon( pointCount );
594
QPointF *clippedData = clippedPolygon.data();
596
int numClippedPoints = 0;
597
for ( int i = 0; i < pointCount; i++ )
599
if ( clipRect.contains( points[i] ) )
600
clippedData[ numClippedPoints++ ] = points[i];
602
painter->drawPoints( clippedData, numClippedPoints );
606
painter->drawPoints( points, pointCount );
430
610
//! Wrapper for QPainter::drawImage()
431
611
void QwtPainter::drawImage( QPainter *painter,
432
612
const QRectF &rect, const QImage &image )
492
Draw a frame with rounded borders
674
\param painter Painter
675
\param rect Frame rectangle
676
\param palette QPalette::WindowText is used for plain borders
677
QPalette::Dark and QPalette::Light for raised
679
\param lineWidth Line width
680
\param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
682
void QwtPainter::drawRoundFrame( QPainter *painter,
683
const QRectF &rect, const QPalette &palette,
684
int lineWidth, int frameStyle )
694
if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
696
else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
699
const double lw2 = 0.5 * lineWidth;
700
QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
704
if ( style != Plain )
706
QColor c1 = palette.color( QPalette::Light );
707
QColor c2 = palette.color( QPalette::Dark );
709
if ( style == Sunken )
712
QLinearGradient gradient( r.topLeft(), r.bottomRight() );
713
gradient.setColorAt( 0.0, c1 );
715
gradient.setColorAt( 0.3, c1 );
716
gradient.setColorAt( 0.7, c2 );
718
gradient.setColorAt( 1.0, c2 );
720
brush = QBrush( gradient );
724
brush = palette.brush( QPalette::WindowText );
729
painter->setPen( QPen( brush, lineWidth ) );
730
painter->setBrush( Qt::NoBrush );
732
painter->drawEllipse( r );
738
Draw a rectangular frame
740
\param painter Painter
741
\param rect Frame rectangle
742
\param palette Palette
743
\param foregroundRole Foreground role used for QFrame::Plain
744
\param frameWidth Frame width
745
\param midLineWidth Used for QFrame::Box
746
\param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
748
void QwtPainter::drawFrame( QPainter *painter, const QRectF &rect,
749
const QPalette &palette, QPalette::ColorRole foregroundRole,
750
int frameWidth, int midLineWidth, int frameStyle )
752
if ( frameWidth <= 0 || rect.isEmpty() )
755
const int shadow = frameStyle & QFrame::Shadow_Mask;
759
if ( shadow == QFrame::Plain )
761
const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
762
const QRectF innerRect = outerRect.adjusted(
763
frameWidth, frameWidth, -frameWidth, -frameWidth );
766
path.addRect( outerRect );
767
path.addRect( innerRect );
769
painter->setPen( Qt::NoPen );
770
painter->setBrush( palette.color( foregroundRole ) );
772
painter->drawPath( path );
776
const int shape = frameStyle & QFrame::Shape_Mask;
778
if ( shape == QFrame::Box )
780
const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
781
const QRectF midRect1 = outerRect.adjusted(
782
frameWidth, frameWidth, -frameWidth, -frameWidth );
783
const QRectF midRect2 = midRect1.adjusted(
784
midLineWidth, midLineWidth, -midLineWidth, -midLineWidth );
786
const QRectF innerRect = midRect2.adjusted(
787
frameWidth, frameWidth, -frameWidth, -frameWidth );
790
path1.moveTo( outerRect.bottomLeft() );
791
path1.lineTo( outerRect.topLeft() );
792
path1.lineTo( outerRect.topRight() );
793
path1.lineTo( midRect1.topRight() );
794
path1.lineTo( midRect1.topLeft() );
795
path1.lineTo( midRect1.bottomLeft() );
798
path2.moveTo( outerRect.bottomLeft() );
799
path2.lineTo( outerRect.bottomRight() );
800
path2.lineTo( outerRect.topRight() );
801
path2.lineTo( midRect1.topRight() );
802
path2.lineTo( midRect1.bottomRight() );
803
path2.lineTo( midRect1.bottomLeft() );
806
path3.moveTo( midRect2.bottomLeft() );
807
path3.lineTo( midRect2.topLeft() );
808
path3.lineTo( midRect2.topRight() );
809
path3.lineTo( innerRect.topRight() );
810
path3.lineTo( innerRect.topLeft() );
811
path3.lineTo( innerRect.bottomLeft() );
814
path4.moveTo( midRect2.bottomLeft() );
815
path4.lineTo( midRect2.bottomRight() );
816
path4.lineTo( midRect2.topRight() );
817
path4.lineTo( innerRect.topRight() );
818
path4.lineTo( innerRect.bottomRight() );
819
path4.lineTo( innerRect.bottomLeft() );
822
path5.addRect( midRect1 );
823
path5.addRect( midRect2 );
825
painter->setPen( Qt::NoPen );
827
QBrush brush1 = palette.dark().color();
828
QBrush brush2 = palette.light().color();
830
if ( shadow == QFrame::Raised )
831
qSwap( brush1, brush2 );
833
painter->setBrush( brush1 );
834
painter->drawPath( path1 );
835
painter->drawPath( path4 );
837
painter->setBrush( brush2 );
838
painter->drawPath( path2 );
839
painter->drawPath( path3 );
841
painter->setBrush( palette.mid() );
842
painter->drawPath( path5 );
845
// qDrawWinPanel doesn't result in something nice
846
// on a scalable document like PDF. Better draw a
849
else if ( shape == QFrame::WinPanel )
851
painter->setRenderHint( QPainter::NonCosmeticDefaultPen, true );
852
qDrawWinPanel ( painter, rect.toRect(), palette,
853
frameStyle & QFrame::Sunken );
855
else if ( shape == QFrame::StyledPanel )
861
const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
862
const QRectF innerRect = outerRect.adjusted(
863
frameWidth - 1.0, frameWidth - 1.0,
864
-( frameWidth - 1.0 ), -( frameWidth - 1.0 ) );
867
path1.moveTo( outerRect.bottomLeft() );
868
path1.lineTo( outerRect.topLeft() );
869
path1.lineTo( outerRect.topRight() );
870
path1.lineTo( innerRect.topRight() );
871
path1.lineTo( innerRect.topLeft() );
872
path1.lineTo( innerRect.bottomLeft() );
876
path2.moveTo( outerRect.bottomLeft() );
877
path2.lineTo( outerRect.bottomRight() );
878
path2.lineTo( outerRect.topRight() );
879
path2.lineTo( innerRect.topRight() );
880
path2.lineTo( innerRect.bottomRight() );
881
path2.lineTo( innerRect.bottomLeft() );
883
painter->setPen( Qt::NoPen );
885
QBrush brush1 = palette.dark().color();
886
QBrush brush2 = palette.light().color();
888
if ( shadow == QFrame::Raised )
889
qSwap( brush1, brush2 );
891
painter->setBrush( brush1 );
892
painter->drawPath( path1 );
894
painter->setBrush( brush2 );
895
painter->drawPath( path2 );
904
Draw a rectangular frame with rounded borders
494
906
\param painter Painter
495
907
\param rect Frame rectangle
703
1117
drawPixmap( painter, rect, pixmap );
1120
static inline void qwtFillRect( const QWidget *widget, QPainter *painter,
1121
const QRect &rect, const QBrush &brush)
1123
if ( brush.style() == Qt::TexturePattern )
1127
painter->setClipRect( rect );
1128
painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
1132
else if ( brush.gradient() )
1136
painter->setClipRect( rect );
1137
painter->fillRect(0, 0, widget->width(),
1138
widget->height(), brush);
1144
painter->fillRect(rect, brush);
1149
Fill a pixmap with the content of a widget
1151
In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy
1152
for backgrounds with gradients. Thus fillPixmap() offers
1153
an alternative implementation.
1155
\param widget Widget
1156
\param pixmap Pixmap to be filled
1157
\param offset Offset
1161
void QwtPainter::fillPixmap( const QWidget *widget,
1162
QPixmap &pixmap, const QPoint &offset )
1164
const QRect rect( offset, pixmap.size() );
1166
QPainter painter( &pixmap );
1167
painter.translate( -offset );
1169
const QBrush autoFillBrush =
1170
widget->palette().brush( widget->backgroundRole() );
1172
if ( !( widget->autoFillBackground() && autoFillBrush.isOpaque() ) )
1174
const QBrush bg = widget->palette().brush( QPalette::Window );
1175
qwtFillRect( widget, &painter, rect, bg);
1178
if ( widget->autoFillBackground() )
1179
qwtFillRect( widget, &painter, rect, autoFillBrush);
1181
if ( widget->testAttribute(Qt::WA_StyledBackground) )
1183
painter.setClipRegion( rect );
1186
opt.initFrom( widget );
1187
widget->style()->drawPrimitive( QStyle::PE_Widget,
1188
&opt, &painter, widget );
1193
Fill rect with the background of a widget
1195
\param painter Painter
1196
\param rect Rectangle to be filled
1197
\param widget Widget
1199
\sa QStyle::PE_Widget, QWidget::backgroundRole()
1201
void QwtPainter::drawBackgound( QPainter *painter,
1202
const QRectF &rect, const QWidget *widget )
1204
if ( widget->testAttribute( Qt::WA_StyledBackground ) )
1207
opt.initFrom( widget );
1208
opt.rect = rect.toAlignedRect();
1210
widget->style()->drawPrimitive(
1211
QStyle::PE_Widget, &opt, painter, widget);
1215
const QBrush brush =
1216
widget->palette().brush( widget->backgroundRole() );
1218
painter->fillRect( rect, brush );
1223
\return A pixmap that can be used as backing store
1225
\param widget Widget, for which the backinstore is intended
1226
\param size Size of the pixmap
1228
QPixmap QwtPainter::backingStore( QWidget *widget, const QSize &size )
1232
#define QWT_HIGH_DPI 1
1234
#if QT_VERSION >= 0x050000 && QWT_HIGH_DPI
1235
qreal pixelRatio = 1.0;
1237
if ( widget && widget->windowHandle() )
1239
pixelRatio = widget->windowHandle()->devicePixelRatio();
1244
pixelRatio = qApp->devicePixelRatio();
1247
pm = QPixmap( size * pixelRatio );
1248
pm.setDevicePixelRatio( pixelRatio );
1251
pm = QPixmap( size );
1254
#if QT_VERSION < 0x050000
1256
if ( widget && isX11GraphicsSystem() )
1258
if ( pm.x11Info().screen() != widget->x11Info().screen() )
1259
pm.x11SetScreen( widget->x11Info().screen() );