10 #include "qwt_painter.h" 
   12 #include "qwt_clipper.h" 
   13 #include "qwt_color_map.h" 
   14 #include "qwt_scale_map.h" 
   21 #include <qpaintdevice.h> 
   22 #include <qpainterpath.h> 
   25 #include <qtextdocument.h> 
   26 #include <qabstracttextdocumentlayout.h> 
   27 #include <qstyleoption.h> 
   28 #include <qpaintengine.h> 
   29 #include <qapplication.h> 
   31 #if QT_VERSION >= 0x060000 
   34 #include <qdesktopwidget.h> 
   37 #if QT_VERSION < 0x050000 
   40 #include <qx11info_x11.h> 
   47 bool QwtPainter::m_polylineSplitting = 
true;
 
   48 bool QwtPainter::m_roundingAlignment = 
true;
 
   50 static inline bool qwtIsRasterPaintEngineBuggy()
 
   53     static int isBuggy = -1;
 
   59         QImage image( 2, 3, QImage::Format_ARGB32 );
 
   68         QPainter painter( &image );
 
   69         painter.drawPolyline( p );
 
   72         isBuggy = ( image.pixel( 1, 1 ) == 0 ) ? 1 : 0;
 
   78 #if QT_VERSION < 0x050000 
   80 #elif QT_VERSION < 0x050100 
   82 #elif QT_VERSION < 0x050400 
   89 static inline bool qwtIsClippingNeeded(
 
   90     const QPainter* painter, QRectF& clipRect )
 
   92     bool doClipping = 
false;
 
   93     const QPaintEngine* pe = painter->paintEngine();
 
   94     if ( pe && pe->type() == QPaintEngine::SVG )
 
   98         if ( painter->hasClipping() )
 
  101             clipRect = painter->clipRegion().boundingRect();
 
  109 static inline void qwtDrawPolyline( QPainter* painter,
 
  110     const T* points, 
int pointCount, 
bool polylineSplitting )
 
  112     bool doSplit = 
false;
 
  113     if ( polylineSplitting && pointCount > 3 )
 
  115         const QPaintEngine* pe = painter->paintEngine();
 
  116         if ( pe && pe->type() == QPaintEngine::Raster )
 
  118             if ( painter->pen().width() <= 1 )
 
  123                 doSplit = qwtIsRasterPaintEngineBuggy();
 
  139         QPen pen = painter->pen();
 
  141         const int splitSize = 6;
 
  143         if ( pen.width() <= 1 && pen.isSolid() && qwtIsRasterPaintEngineBuggy()
 
  144             && !( painter->renderHints() & QPainter::Antialiasing ) )
 
  148             for ( 
int i = k + 1; i < pointCount; i++ )
 
  150                 const QPointF& p1 = points[i - 1];
 
  151                 const QPointF& p2 = points[i];
 
  153                 const bool isBad = ( qAbs( p2.y() - p1.y() ) <= 1 )
 
  154                     && qAbs( p2.x() - p1.x() ) <= 1;
 
  156                 if ( isBad || ( i - k >= splitSize ) )
 
  158                     painter->drawPolyline( points + k, i - k + 1 );
 
  163             painter->drawPolyline( points + k, pointCount - k );
 
  167             for ( 
int i = 0; i < pointCount; i += splitSize )
 
  169                 const int n = qMin( splitSize + 1, pointCount - i );
 
  170                 painter->drawPolyline( points + i, n );
 
  176         painter->drawPolyline( points, pointCount );
 
  180 static inline QSize qwtScreenResolution()
 
  182     static QSize screenResolution;
 
  183     if ( !screenResolution.isValid() )
 
  188 #if QT_VERSION >= 0x060000 
  189         QScreen* screen = QGuiApplication::primaryScreen();
 
  192             screenResolution.setWidth( screen->logicalDotsPerInchX() );
 
  193             screenResolution.setHeight( screen->logicalDotsPerInchY() );
 
  196         QDesktopWidget* desktop = QApplication::desktop();
 
  199             screenResolution.setWidth( desktop->logicalDpiX() );
 
  200             screenResolution.setHeight( desktop->logicalDpiY() );
 
  205     return screenResolution;
 
  208 static inline void qwtUnscaleFont( QPainter* painter )
 
  210     if ( painter->font().pixelSize() >= 0 )
 
  213     const QSize screenResolution = qwtScreenResolution();
 
  215     const QPaintDevice* pd = painter->device();
 
  216     if ( pd->logicalDpiX() != screenResolution.width() ||
 
  217         pd->logicalDpiY() != screenResolution.height() )
 
  220         pixelFont.setPixelSize( QFontInfo( pixelFont ).pixelSize() );
 
  222         painter->setFont( pixelFont );
 
  241     static int onX11 = -1;
 
  245         QPainter painter( &pm );
 
  247         onX11 = ( painter.paintEngine()->type() == QPaintEngine::X11 ) ? 1 : 0;
 
  269     if ( painter && painter->isActive() )
 
  271         const QPaintEngine::Type type =
 
  272             painter->paintEngine()->type();
 
  274         if ( type >= QPaintEngine::User )
 
  282             case QPaintEngine::Pdf:
 
  283             case QPaintEngine::SVG:
 
  285             case QPaintEngine::MacPrinter:
 
  293         const QTransform& tr = painter->transform();
 
  294         if ( tr.isRotating() || tr.isScaling() )
 
  317     m_roundingAlignment = enable;
 
  337     m_polylineSplitting = enable;
 
  343     painter->drawPath( path );
 
  349     drawRect( painter, QRectF( x, y, w, h ) );
 
  355     const QRectF r = rect;
 
  358     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  360     if ( deviceClipping )
 
  362         if ( !clipRect.intersects( r ) )
 
  365         if ( !clipRect.contains( r ) )
 
  367             fillRect( painter, r & clipRect, painter->brush() );
 
  370             painter->setBrush( Qt::NoBrush );
 
  378     painter->drawRect( r );
 
  383     const QRectF& rect, 
const QBrush& brush )
 
  385     if ( !rect.isValid() )
 
  389     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  397     if ( deviceClipping )
 
  398         clipRect &= painter->window();
 
  400         clipRect = painter->window();
 
  402     if ( painter->hasClipping() )
 
  403         clipRect &= painter->clipRegion().boundingRect();
 
  406     if ( deviceClipping )
 
  407         r = r.intersected( clipRect );
 
  410         painter->fillRect( r, brush );
 
  418     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  419     if ( deviceClipping && !clipRect.contains( rect ) )
 
  422     painter->drawPie( rect, a, alen );
 
  429     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  431     if ( deviceClipping && !clipRect.contains( rect ) )
 
  434     painter->drawEllipse( rect );
 
  439     qreal x, qreal y, 
const QString& text )
 
  441     drawText( painter, QPointF( x, y ), text );
 
  446     const QString& text )
 
  449     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  451     if ( deviceClipping && !clipRect.contains( pos ) )
 
  456     qwtUnscaleFont( painter );
 
  457     painter->drawText( pos, text );
 
  463     qreal x, qreal y, qreal w, qreal h,
 
  464     int flags, 
const QString& text )
 
  466     drawText( painter, QRectF( x, y, w, h ), flags, text );
 
  471     int flags, 
const QString& text )
 
  474     qwtUnscaleFont( painter );
 
  475     painter->drawText( rect, flags, text );
 
  479 #ifndef QT_NO_RICHTEXT 
  490     int flags, 
const QTextDocument& text )
 
  492     QTextDocument* txt = text.clone();
 
  496     QRectF unscaledRect = rect;
 
  498     if ( painter->font().pixelSize() < 0 )
 
  500         const QSize res = qwtScreenResolution();
 
  502         const QPaintDevice* pd = painter->device();
 
  503         if ( pd->logicalDpiX() != res.width() ||
 
  504             pd->logicalDpiY() != res.height() )
 
  506             QTransform transform;
 
  507             transform.scale( res.width() / qreal( pd->logicalDpiX() ),
 
  508                 res.height() / qreal( pd->logicalDpiY() ) );
 
  510             painter->setWorldTransform( transform, 
true );
 
  511             unscaledRect = transform.inverted().mapRect(rect);
 
  515     txt->setDefaultFont( painter->font() );
 
  516     txt->setPageSize( QSizeF( unscaledRect.width(), QWIDGETSIZE_MAX ) );
 
  518     QAbstractTextDocumentLayout* layout = txt->documentLayout();
 
  520     const qreal height = layout->documentSize().height();
 
  521     qreal y = unscaledRect.y();
 
  522     if ( flags & Qt::AlignBottom )
 
  523         y += ( unscaledRect.height() - height );
 
  524     else if ( flags & Qt::AlignVCenter )
 
  525         y += ( unscaledRect.height() - height ) / 2;
 
  527     QAbstractTextDocumentLayout::PaintContext context;
 
  528     context.palette.setColor( QPalette::Text, painter->pen().color() );
 
  530     painter->translate( unscaledRect.x(), y );
 
  531     layout->draw( painter, context );
 
  542     const QPointF& p1, 
const QPointF& p2 )
 
  545     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  547     if ( deviceClipping &&
 
  548         !( clipRect.contains( p1 ) && clipRect.contains( p2 ) ) )
 
  557     painter->drawLine( p1, p2 );
 
  564     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  566     if ( deviceClipping )
 
  568         painter->drawPolygon(
 
  573         painter->drawPolygon( polygon );
 
  581     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  583     if ( deviceClipping )
 
  587         qwtDrawPolyline< QPointF >( painter,
 
  588             cpa.constData(), cpa.size(), m_polylineSplitting );
 
  592         qwtDrawPolyline< QPointF >( painter,
 
  593             polygon.constData(), polygon.size(), m_polylineSplitting );
 
  599     const QPointF* points, 
int pointCount )
 
  602     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  604     if ( deviceClipping )
 
  606         QPolygonF polygon( pointCount );
 
  607         std::memcpy( polygon.data(), points, pointCount * 
sizeof( QPointF ) );
 
  610         qwtDrawPolyline< QPointF >( painter,
 
  611             polygon.constData(), polygon.size(), m_polylineSplitting );
 
  615         qwtDrawPolyline< QPointF >( painter, points, pointCount, m_polylineSplitting );
 
  623     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  625     if ( deviceClipping )
 
  627         painter->drawPolygon(
 
  632         painter->drawPolygon( polygon );
 
  640     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  642     if ( deviceClipping )
 
  646         qwtDrawPolyline< QPoint >( painter,
 
  647             cpa.constData(), cpa.size(), m_polylineSplitting );
 
  651         qwtDrawPolyline< QPoint >( painter,
 
  652             polygon.constData(), polygon.size(), m_polylineSplitting );
 
  658     const QPoint* points, 
int pointCount )
 
  661     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  663     if ( deviceClipping )
 
  665         QPolygon polygon( pointCount );
 
  666         std::memcpy( polygon.data(), points, pointCount * 
sizeof( QPoint ) );
 
  669         qwtDrawPolyline< QPoint >( painter,
 
  670             polygon.constData(), polygon.size(), m_polylineSplitting );
 
  674         qwtDrawPolyline< QPoint >( painter, points, pointCount, m_polylineSplitting );
 
  682     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  684     if ( deviceClipping && !clipRect.contains( pos ) )
 
  687     painter->drawPoint( pos );
 
  694     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  696     if ( deviceClipping )
 
  698         const int minX = qwtCeil( clipRect.left() );
 
  699         const int maxX = qwtFloor( clipRect.right() );
 
  700         const int minY = qwtCeil( clipRect.top() );
 
  701         const int maxY = qwtFloor( clipRect.bottom() );
 
  703         if ( pos.x() < minX || pos.x() > maxX
 
  704             || pos.y() < minY || pos.y() > maxY )
 
  710     painter->drawPoint( pos );
 
  715     const QPoint* points, 
int pointCount )
 
  718     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  720     if ( deviceClipping )
 
  722         const int minX = qwtCeil( clipRect.left() );
 
  723         const int maxX = qwtFloor( clipRect.right() );
 
  724         const int minY = qwtCeil( clipRect.top() );
 
  725         const int maxY = qwtFloor( clipRect.bottom() );
 
  727         const QRect r( minX, minY, maxX - minX, maxY - minY );
 
  729         QPolygon clippedPolygon( pointCount );
 
  730         QPoint* clippedData = clippedPolygon.data();
 
  732         int numClippedPoints = 0;
 
  733         for ( 
int i = 0; i < pointCount; i++ )
 
  735             if ( r.contains( points[i] ) )
 
  736                 clippedData[ numClippedPoints++ ] = points[i];
 
  738         painter->drawPoints( clippedData, numClippedPoints );
 
  742         painter->drawPoints( points, pointCount );
 
  748     const QPointF* points, 
int pointCount )
 
  751     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
  753     if ( deviceClipping )
 
  755         QPolygonF clippedPolygon( pointCount );
 
  756         QPointF* clippedData = clippedPolygon.data();
 
  758         int numClippedPoints = 0;
 
  759         for ( 
int i = 0; i < pointCount; i++ )
 
  761             if ( clipRect.contains( points[i] ) )
 
  762                 clippedData[ numClippedPoints++ ] = points[i];
 
  764         painter->drawPoints( clippedData, numClippedPoints );
 
  768         painter->drawPoints( points, pointCount );
 
  774     const QRectF& rect, 
const QImage& image )
 
  776     const QRect alignedRect = rect.toAlignedRect();
 
  778     if ( alignedRect != rect )
 
  780         const QRectF clipRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
 
  783         painter->setClipRect( clipRect, Qt::IntersectClip );
 
  784         painter->drawImage( alignedRect, image );
 
  789         painter->drawImage( alignedRect, image );
 
  795     const QRectF& rect, 
const QPixmap& pixmap )
 
  797     const QRect alignedRect = rect.toAlignedRect();
 
  799     if ( alignedRect != rect )
 
  801         const QRectF clipRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
 
  804         painter->setClipRect( clipRect, Qt::IntersectClip );
 
  805         painter->drawPixmap( alignedRect, pixmap );
 
  810         painter->drawPixmap( alignedRect, pixmap );
 
  824     QStyleOptionFocusRect opt;
 
  825     opt.initFrom( widget );
 
  827     opt.state |= QStyle::State_HasFocus;
 
  828     opt.backgroundColor = widget->palette().color( widget->backgroundRole() );
 
  830     widget->style()->drawPrimitive(
 
  831         QStyle::PE_FrameFocusRect, &opt, painter, widget );
 
  846     const QRectF& rect, 
const QPalette& palette,
 
  847     int lineWidth, 
int frameStyle )
 
  857     if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken )
 
  859     else if ( (frameStyle& QFrame::Raised) == QFrame::Raised )
 
  862     const qreal lw2 = 0.5 * lineWidth;
 
  863     QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
 
  867     if ( style != Plain )
 
  869         QColor c1 = palette.color( QPalette::Light );
 
  870         QColor c2 = palette.color( QPalette::Dark );
 
  872         if ( style == Sunken )
 
  875         QLinearGradient gradient( r.topLeft(), r.bottomRight() );
 
  876         gradient.setColorAt( 0.0, c1 );
 
  878         gradient.setColorAt( 0.3, c1 );
 
  879         gradient.setColorAt( 0.7, c2 );
 
  881         gradient.setColorAt( 1.0, c2 );
 
  883         brush = QBrush( gradient );
 
  887         brush = palette.brush( QPalette::WindowText );
 
  892     painter->setPen( QPen( brush, lineWidth ) );
 
  893     painter->setBrush( Qt::NoBrush );
 
  895     painter->drawEllipse( r );
 
  912     const QPalette& palette, QPalette::ColorRole foregroundRole,
 
  913     int frameWidth, 
int midLineWidth, 
int frameStyle )
 
  915     if ( frameWidth <= 0 || rect.isEmpty() )
 
  918     const int shadow = frameStyle & QFrame::Shadow_Mask;
 
  922     if ( shadow == QFrame::Plain )
 
  924         const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
 
  925         const QRectF innerRect = outerRect.adjusted(
 
  926             frameWidth, frameWidth, -frameWidth, -frameWidth );
 
  929         path.addRect( outerRect );
 
  930         path.addRect( innerRect );
 
  932         painter->setPen( Qt::NoPen );
 
  933         painter->setBrush( palette.color( foregroundRole ) );
 
  935         painter->drawPath( path );
 
  939         const int shape = frameStyle & QFrame::Shape_Mask;
 
  941         if ( shape == QFrame::Box )
 
  943             const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
 
  944             const QRectF midRect1 = outerRect.adjusted(
 
  945                 frameWidth, frameWidth, -frameWidth, -frameWidth );
 
  946             const QRectF midRect2 = midRect1.adjusted(
 
  947                 midLineWidth, midLineWidth, -midLineWidth, -midLineWidth );
 
  949             const QRectF innerRect = midRect2.adjusted(
 
  950                 frameWidth, frameWidth, -frameWidth, -frameWidth );
 
  953             path1.moveTo( outerRect.bottomLeft() );
 
  954             path1.lineTo( outerRect.topLeft() );
 
  955             path1.lineTo( outerRect.topRight() );
 
  956             path1.lineTo( midRect1.topRight() );
 
  957             path1.lineTo( midRect1.topLeft() );
 
  958             path1.lineTo( midRect1.bottomLeft() );
 
  961             path2.moveTo( outerRect.bottomLeft() );
 
  962             path2.lineTo( outerRect.bottomRight() );
 
  963             path2.lineTo( outerRect.topRight() );
 
  964             path2.lineTo( midRect1.topRight() );
 
  965             path2.lineTo( midRect1.bottomRight() );
 
  966             path2.lineTo( midRect1.bottomLeft() );
 
  969             path3.moveTo( midRect2.bottomLeft() );
 
  970             path3.lineTo( midRect2.topLeft() );
 
  971             path3.lineTo( midRect2.topRight() );
 
  972             path3.lineTo( innerRect.topRight() );
 
  973             path3.lineTo( innerRect.topLeft() );
 
  974             path3.lineTo( innerRect.bottomLeft() );
 
  977             path4.moveTo( midRect2.bottomLeft() );
 
  978             path4.lineTo( midRect2.bottomRight() );
 
  979             path4.lineTo( midRect2.topRight() );
 
  980             path4.lineTo( innerRect.topRight() );
 
  981             path4.lineTo( innerRect.bottomRight() );
 
  982             path4.lineTo( innerRect.bottomLeft() );
 
  985             path5.addRect( midRect1 );
 
  986             path5.addRect( midRect2 );
 
  988             painter->setPen( Qt::NoPen );
 
  990             QBrush brush1 = palette.dark().color();
 
  991             QBrush brush2 = palette.light().color();
 
  993             if ( shadow == QFrame::Raised )
 
  994                 qSwap( brush1, brush2 );
 
  996             painter->setBrush( brush1 );
 
  997             painter->drawPath( path1 );
 
  998             painter->drawPath( path4 );
 
 1000             painter->setBrush( brush2 );
 
 1001             painter->drawPath( path2 );
 
 1002             painter->drawPath( path3 );
 
 1004             painter->setBrush( palette.mid() );
 
 1005             painter->drawPath( path5 );
 
 1009             const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
 
 1010             const QRectF innerRect = outerRect.adjusted(
 
 1011                 frameWidth - 1.0, frameWidth - 1.0,
 
 1012                 -( frameWidth - 1.0 ), -( frameWidth - 1.0 ) );
 
 1015             path1.moveTo( outerRect.bottomLeft() );
 
 1016             path1.lineTo( outerRect.topLeft() );
 
 1017             path1.lineTo( outerRect.topRight() );
 
 1018             path1.lineTo( innerRect.topRight() );
 
 1019             path1.lineTo( innerRect.topLeft() );
 
 1020             path1.lineTo( innerRect.bottomLeft() );
 
 1024             path2.moveTo( outerRect.bottomLeft() );
 
 1025             path2.lineTo( outerRect.bottomRight() );
 
 1026             path2.lineTo( outerRect.topRight() );
 
 1027             path2.lineTo( innerRect.topRight() );
 
 1028             path2.lineTo( innerRect.bottomRight() );
 
 1029             path2.lineTo( innerRect.bottomLeft() );
 
 1031             painter->setPen( Qt::NoPen );
 
 1033             QBrush brush1 = palette.dark().color();
 
 1034             QBrush brush2 = palette.light().color();
 
 1036             if ( shadow == QFrame::Raised )
 
 1037                 qSwap( brush1, brush2 );
 
 1039             painter->setBrush( brush1 );
 
 1040             painter->drawPath( path1 );
 
 1042             painter->setBrush( brush2 );
 
 1043             painter->drawPath( path2 );
 
 1066     const QRectF& rect, qreal xRadius, qreal yRadius,
 
 1067     const QPalette& palette, 
int lineWidth, 
int frameStyle )
 
 1070     painter->setRenderHint( QPainter::Antialiasing, 
true );
 
 1071     painter->setBrush( Qt::NoBrush );
 
 1073     qreal lw2 = lineWidth * 0.5;
 
 1074     QRectF innerRect = rect.adjusted( lw2, lw2, -lw2, -lw2 );
 
 1077     path.addRoundedRect( innerRect, xRadius, yRadius );
 
 1086     Style style = Plain;
 
 1087     if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken )
 
 1089     else if ( (frameStyle& QFrame::Raised) == QFrame::Raised )
 
 1092     if ( style != Plain && path.elementCount() == 17 )
 
 1095         QPainterPath pathList[8];
 
 1097         for ( 
int i = 0; i < 4; i++ )
 
 1099             const int j = i * 4 + 1;
 
 1101             pathList[ 2 * i ].moveTo(
 
 1102                 path.elementAt(j - 1).x, path.elementAt( j - 1 ).y
 
 1105             pathList[ 2 * i ].cubicTo(
 
 1106                 path.elementAt(j + 0).x, path.elementAt(j + 0).y,
 
 1107                 path.elementAt(j + 1).x, path.elementAt(j + 1).y,
 
 1108                 path.elementAt(j + 2).x, path.elementAt(j + 2).y );
 
 1110             pathList[ 2 * i + 1 ].moveTo(
 
 1111                 path.elementAt(j + 2).x, path.elementAt(j + 2).y
 
 1113             pathList[ 2 * i + 1 ].lineTo(
 
 1114                 path.elementAt(j + 3).x, path.elementAt(j + 3).y
 
 1118         QColor c1( palette.color( QPalette::Dark ) );
 
 1119         QColor c2( palette.color( QPalette::Light ) );
 
 1121         if ( style == Raised )
 
 1124         for ( 
int i = 0; i < 4; i++ )
 
 1126             const QRectF r = pathList[2 * i].controlPointRect();
 
 1129             arcPen.setCapStyle( Qt::FlatCap );
 
 1130             arcPen.setWidth( lineWidth );
 
 1133             linePen.setCapStyle( Qt::FlatCap );
 
 1134             linePen.setWidth( lineWidth );
 
 1140                     arcPen.setColor( c1 );
 
 1141                     linePen.setColor( c1 );
 
 1146                     QLinearGradient gradient;
 
 1147                     gradient.setStart( r.topLeft() );
 
 1148                     gradient.setFinalStop( r.bottomRight() );
 
 1149                     gradient.setColorAt( 0.0, c1 );
 
 1150                     gradient.setColorAt( 1.0, c2 );
 
 1152                     arcPen.setBrush( gradient );
 
 1153                     linePen.setColor( c2 );
 
 1158                     arcPen.setColor( c2 );
 
 1159                     linePen.setColor( c2 );
 
 1164                     QLinearGradient gradient;
 
 1166                     gradient.setStart( r.bottomRight() );
 
 1167                     gradient.setFinalStop( r.topLeft() );
 
 1168                     gradient.setColorAt( 0.0, c2 );
 
 1169                     gradient.setColorAt( 1.0, c1 );
 
 1171                     arcPen.setBrush( gradient );
 
 1172                     linePen.setColor( c1 );
 
 1178             painter->setPen( arcPen );
 
 1179             painter->drawPath( pathList[ 2 * i] );
 
 1181             painter->setPen( linePen );
 
 1182             painter->drawPath( pathList[ 2 * i + 1] );
 
 1187         QPen pen( palette.color( QPalette::WindowText ), lineWidth );
 
 1188         painter->setPen( pen );
 
 1189         painter->drawPath( path );
 
 1207     const QwtScaleMap& scaleMap, Qt::Orientation orientation,
 
 1208     const QRectF& rect )
 
 1216     const QRect devRect = rect.toAlignedRect();
 
 1223     QPixmap pixmap( devRect.size() );
 
 1224     pixmap.fill( Qt::transparent );
 
 1226     QPainter pmPainter( &pixmap );
 
 1227     pmPainter.translate( -devRect.x(), -devRect.y() );
 
 1229     if ( orientation == Qt::Horizontal )
 
 1234         for ( 
int x = devRect.left(); x <= devRect.right(); x++ )
 
 1239                 c.setRgba( colorMap.
rgb( interval, value ) );
 
 1241                 c = colorTable[colorMap.
colorIndex( 256, interval, value )];
 
 1243             pmPainter.setPen( c );
 
 1244             pmPainter.drawLine( x, devRect.top(), x, devRect.bottom() );
 
 1252         for ( 
int y = devRect.top(); y <= devRect.bottom(); y++ )
 
 1257                 c.setRgba( colorMap.
rgb( interval, value ) );
 
 1259                 c = colorTable[colorMap.
colorIndex( 256, interval, value )];
 
 1261             pmPainter.setPen( c );
 
 1262             pmPainter.drawLine( devRect.left(), y, devRect.right(), y );
 
 1270 static inline void qwtFillRect( 
const QWidget* widget, QPainter* painter,
 
 1271     const QRect& rect, 
const QBrush& brush)
 
 1273     if ( brush.style() == Qt::TexturePattern )
 
 1277         painter->setClipRect( rect );
 
 1278         painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft() );
 
 1282     else if ( brush.gradient() )
 
 1286         painter->setClipRect( rect );
 
 1287         painter->fillRect(0, 0, widget->width(),
 
 1288             widget->height(), brush);
 
 1294         painter->fillRect(rect, brush);
 
 1312     QPixmap& pixmap, 
const QPoint& offset )
 
 1314     const QRect rect( offset, pixmap.size() );
 
 1316     QPainter painter( &pixmap );
 
 1317     painter.translate( -offset );
 
 1319     const QBrush autoFillBrush =
 
 1320         widget->palette().brush( widget->backgroundRole() );
 
 1322     if ( !( widget->autoFillBackground() && autoFillBrush.isOpaque() ) )
 
 1324         const QBrush bg = widget->palette().brush( QPalette::Window );
 
 1325         qwtFillRect( widget, &painter, rect, bg);
 
 1328     if ( widget->autoFillBackground() )
 
 1329         qwtFillRect( widget, &painter, rect, autoFillBrush);
 
 1331     if ( widget->testAttribute(Qt::WA_StyledBackground) )
 
 1333         painter.setClipRegion( rect );
 
 1336         opt.initFrom( widget );
 
 1337         widget->style()->drawPrimitive( QStyle::PE_Widget,
 
 1338             &opt, &painter, widget );
 
 1352     const QRectF& rect, 
const QWidget* widget )
 
 1354     if ( widget->testAttribute( Qt::WA_StyledBackground ) )
 
 1357         opt.initFrom( widget );
 
 1358         opt.rect = rect.toAlignedRect();
 
 1360         widget->style()->drawPrimitive(
 
 1361             QStyle::PE_Widget, &opt, painter, widget);
 
 1365         const QBrush brush =
 
 1366             widget->palette().brush( widget->backgroundRole() );
 
 1368         painter->fillRect( rect, brush );
 
 1380     const QFontMetrics& fontMetrics, 
const QString& text )
 
 1382 #if QT_VERSION >= 0x050b00 
 1383     return fontMetrics.horizontalAdvance( text );
 
 1385     return fontMetrics.width( text );
 
 1398     const QFontMetricsF& fontMetrics, 
const QString& text )
 
 1400 #if QT_VERSION >= 0x050b00 
 1401     return fontMetrics.horizontalAdvance( text );
 
 1403     return fontMetrics.width( text );
 
 1415     const QFontMetrics& fontMetrics, QChar ch )
 
 1417 #if QT_VERSION >= 0x050b00 
 1418     return fontMetrics.horizontalAdvance( ch );
 
 1420     return fontMetrics.width( ch );
 
 1432     const QFontMetricsF& fontMetrics, QChar ch )
 
 1434 #if QT_VERSION >= 0x050b00 
 1435     return fontMetrics.horizontalAdvance( ch );
 
 1437     return fontMetrics.width( ch );
 
 1452     if ( paintDevice == 
nullptr )
 
 1454 #if QT_VERSION < 0x060000 
 1455         paintDevice = QApplication::desktop();
 
 1457         class PaintDevice : 
public QPaintDevice
 
 1459             virtual QPaintEngine* paintEngine() 
const QWT_OVERRIDE
 
 1464             virtual int metric( PaintDeviceMetric metric ) 
const QWT_OVERRIDE
 
 1466                 if ( metric == PdmDpiY )
 
 1468                     QScreen* screen = QGuiApplication::primaryScreen();
 
 1471                         return screen->logicalDotsPerInchY();
 
 1475                 return QPaintDevice::metric( metric );
 
 1479         static PaintDevice dummyPaintDevice;
 
 1480         paintDevice = &dummyPaintDevice;
 
 1484     return QFont( font, 
const_cast< QPaintDevice* 
>( paintDevice ) );
 
 1493     qreal pixelRatio = 0.0;
 
 1495 #if QT_VERSION >= 0x050100 
 1498 #if QT_VERSION >= 0x050600 
 1499         pixelRatio = paintDevice->devicePixelRatioF();
 
 1501         pixelRatio = paintDevice->devicePixelRatio();
 
 1505     Q_UNUSED( paintDevice )
 
 1508 #if QT_VERSION >= 0x050000 
 1509     if ( pixelRatio == 0.0 && qApp )
 
 1510         pixelRatio = qApp->devicePixelRatio();
 
 1513     if ( pixelRatio == 0.0 )
 
 1529 #if QT_VERSION >= 0x050000 
 1532     pm = QPixmap( size * pixelRatio );
 
 1533     pm.setDevicePixelRatio( pixelRatio );
 
 1535     pm = QPixmap( size );
 
 1541         if ( pm.x11Info().screen() != widget->x11Info().screen() )
 
 1542             pm.x11SetScreen( widget->x11Info().screen() );
 
QwtColorMap is used to map values into colors.
virtual uint colorIndex(int numColors, const QwtInterval &interval, double value) const
Map a value of a given interval into a color index.
@ RGB
The map is intended to map into RGB values.
virtual QVector< QRgb > colorTable256() const
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
A class representing an interval.
static void drawEllipse(QPainter *, const QRectF &)
Wrapper for QPainter::drawEllipse()
static void drawPoints(QPainter *, const QPolygon &)
Wrapper for QPainter::drawPoints()
static void setPolylineSplitting(bool)
En/Disable line splitting for the raster paint engine.
static void drawSimpleRichText(QPainter *, const QRectF &, int flags, const QTextDocument &)
static void drawPath(QPainter *, const QPainterPath &)
Wrapper for QPainter::drawPath()
static void drawImage(QPainter *, const QRectF &, const QImage &)
Wrapper for QPainter::drawImage()
static void drawPolygon(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolygon()
static void drawRoundFrame(QPainter *, const QRectF &, const QPalette &, int lineWidth, int frameStyle)
static void setRoundingAlignment(bool)
static void drawPolyline(QPainter *, const QPolygonF &)
Wrapper for QPainter::drawPolyline()
static void drawText(QPainter *, qreal x, qreal y, const QString &)
Wrapper for QPainter::drawText()
static bool isAligning(const QPainter *)
static void fillRect(QPainter *, const QRectF &, const QBrush &)
Wrapper for QPainter::fillRect()
static void drawRoundedFrame(QPainter *, const QRectF &, qreal xRadius, qreal yRadius, const QPalette &, int lineWidth, int frameStyle)
static void drawBackgound(QPainter *, const QRectF &, const QWidget *)
static void drawFocusRect(QPainter *, const QWidget *)
Draw a focus rectangle on a widget using its style.
static void drawPoint(QPainter *, const QPoint &)
Wrapper for QPainter::drawPoint()
static void fillPixmap(const QWidget *, QPixmap &, const QPoint &offset=QPoint())
static void drawRect(QPainter *, qreal x, qreal y, qreal w, qreal h)
Wrapper for QPainter::drawRect()
static qreal devicePixelRatio(const QPaintDevice *)
static void drawFrame(QPainter *, const QRectF &rect, const QPalette &palette, QPalette::ColorRole foregroundRole, int lineWidth, int midLineWidth, int frameStyle)
static QPixmap backingStore(QWidget *, const QSize &)
static void drawColorBar(QPainter *, const QwtColorMap &, const QwtInterval &, const QwtScaleMap &, Qt::Orientation, const QRectF &)
static QFont scaledFont(const QFont &, const QPaintDevice *=nullptr)
static void drawPixmap(QPainter *, const QRectF &, const QPixmap &)
Wrapper for QPainter::drawPixmap()
static bool isX11GraphicsSystem()
static void drawPie(QPainter *, const QRectF &r, int a, int alen)
Wrapper for QPainter::drawPie()
static int horizontalAdvance(const QFontMetrics &, const QString &)
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
double invTransform(double p) const
QWT_EXPORT void clipPolygon(const QRect &, QPolygon &, bool closePolygon=false)
QWT_EXPORT QPolygonF clippedPolygonF(const QRectF &, const QPolygonF &, bool closePolygon=false)
QWT_EXPORT void clipPolygonF(const QRectF &, QPolygonF &, bool closePolygon=false)
QWT_EXPORT QPolygon clippedPolygon(const QRect &, const QPolygon &, bool closePolygon=false)