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>
47bool QwtPainter::m_polylineSplitting =
true;
48bool QwtPainter::m_roundingAlignment =
true;
50static 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
89static 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();
109static inline void qwtDrawPolyline( QPainter* painter,
110 const T* points,
int pointCount,
bool polylineSplitting )
112 bool doSplit =
false;
113 if ( polylineSplitting )
115 const QPaintEngine* pe = painter->paintEngine();
116 if ( pe && pe->type() == QPaintEngine::Raster )
129 QPen pen = painter->pen();
131 const int splitSize = 6;
133 if ( pen.width() <= 1 && pen.isSolid() && qwtIsRasterPaintEngineBuggy()
134 && !( painter->renderHints() & QPainter::Antialiasing ) )
138 for (
int i = k + 1; i < pointCount; i++ )
140 const QPointF& p1 = points[i - 1];
141 const QPointF& p2 = points[i];
143 const bool isBad = ( qAbs( p2.y() - p1.y() ) <= 1 )
144 && qAbs( p2.x() - p1.x() ) <= 1;
146 if ( isBad || ( i - k >= splitSize ) )
148 painter->drawPolyline( points + k, i - k + 1 );
153 painter->drawPolyline( points + k, pointCount - k );
157 for (
int i = 0; i < pointCount; i += splitSize )
159 const int n = qMin( splitSize + 1, pointCount - i );
160 painter->drawPolyline( points + i, n );
166 painter->drawPolyline( points, pointCount );
170static inline QSize qwtScreenResolution()
172 static QSize screenResolution;
173 if ( !screenResolution.isValid() )
178#if QT_VERSION >= 0x060000
179 QScreen* screen = QGuiApplication::primaryScreen();
182 screenResolution.setWidth( screen->logicalDotsPerInchX() );
183 screenResolution.setHeight( screen->logicalDotsPerInchY() );
186 QDesktopWidget* desktop = QApplication::desktop();
189 screenResolution.setWidth( desktop->logicalDpiX() );
190 screenResolution.setHeight( desktop->logicalDpiY() );
195 return screenResolution;
198static inline void qwtUnscaleFont( QPainter* painter )
200 if ( painter->font().pixelSize() >= 0 )
203 const QSize screenResolution = qwtScreenResolution();
205 const QPaintDevice* pd = painter->device();
206 if ( pd->logicalDpiX() != screenResolution.width() ||
207 pd->logicalDpiY() != screenResolution.height() )
210 pixelFont.setPixelSize( QFontInfo( pixelFont ).pixelSize() );
212 painter->setFont( pixelFont );
231 static int onX11 = -1;
235 QPainter painter( &pm );
237 onX11 = ( painter.paintEngine()->type() == QPaintEngine::X11 ) ? 1 : 0;
259 if ( painter && painter->isActive() )
261 const QPaintEngine::Type type =
262 painter->paintEngine()->type();
264 if ( type >= QPaintEngine::User )
272 case QPaintEngine::Pdf:
273 case QPaintEngine::SVG:
275 case QPaintEngine::MacPrinter:
283 const QTransform& tr = painter->transform();
284 if ( tr.isRotating() || tr.isScaling() )
307 m_roundingAlignment = enable;
327 m_polylineSplitting = enable;
333 painter->drawPath( path );
339 drawRect( painter, QRectF( x, y, w, h ) );
345 const QRectF r = rect;
348 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
350 if ( deviceClipping )
352 if ( !clipRect.intersects( r ) )
355 if ( !clipRect.contains( r ) )
357 fillRect( painter, r & clipRect, painter->brush() );
360 painter->setBrush( Qt::NoBrush );
368 painter->drawRect( r );
373 const QRectF& rect,
const QBrush& brush )
375 if ( !rect.isValid() )
379 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
387 if ( deviceClipping )
388 clipRect &= painter->window();
390 clipRect = painter->window();
392 if ( painter->hasClipping() )
393 clipRect &= painter->clipRegion().boundingRect();
396 if ( deviceClipping )
397 r = r.intersected( clipRect );
400 painter->fillRect( r, brush );
408 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
409 if ( deviceClipping && !clipRect.contains( rect ) )
412 painter->drawPie( rect, a, alen );
419 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
421 if ( deviceClipping && !clipRect.contains( rect ) )
424 painter->drawEllipse( rect );
429 qreal x, qreal y,
const QString& text )
431 drawText( painter, QPointF( x, y ), text );
436 const QString& text )
439 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
441 if ( deviceClipping && !clipRect.contains( pos ) )
446 qwtUnscaleFont( painter );
447 painter->drawText( pos, text );
453 qreal x, qreal y, qreal w, qreal h,
454 int flags,
const QString& text )
456 drawText( painter, QRectF( x, y, w, h ), flags, text );
461 int flags,
const QString& text )
464 qwtUnscaleFont( painter );
465 painter->drawText( rect, flags, text );
469#ifndef QT_NO_RICHTEXT
480 int flags,
const QTextDocument& text )
482 QTextDocument* txt = text.clone();
486 QRectF unscaledRect = rect;
488 if ( painter->font().pixelSize() < 0 )
490 const QSize res = qwtScreenResolution();
492 const QPaintDevice* pd = painter->device();
493 if ( pd->logicalDpiX() != res.width() ||
494 pd->logicalDpiY() != res.height() )
496 QTransform transform;
497 transform.scale( res.width() / qreal( pd->logicalDpiX() ),
498 res.height() / qreal( pd->logicalDpiY() ) );
500 painter->setWorldTransform( transform,
true );
501 unscaledRect = transform.inverted().mapRect(rect);
505 txt->setDefaultFont( painter->font() );
506 txt->setPageSize( QSizeF( unscaledRect.width(), QWIDGETSIZE_MAX ) );
508 QAbstractTextDocumentLayout* layout = txt->documentLayout();
510 const qreal height = layout->documentSize().height();
511 qreal y = unscaledRect.y();
512 if ( flags & Qt::AlignBottom )
513 y += ( unscaledRect.height() - height );
514 else if ( flags & Qt::AlignVCenter )
515 y += ( unscaledRect.height() - height ) / 2;
517 QAbstractTextDocumentLayout::PaintContext context;
518 context.palette.setColor( QPalette::Text, painter->pen().color() );
520 painter->translate( unscaledRect.x(), y );
521 layout->draw( painter, context );
532 const QPointF& p1,
const QPointF& p2 )
535 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
537 if ( deviceClipping &&
538 !( clipRect.contains( p1 ) && clipRect.contains( p2 ) ) )
547 painter->drawLine( p1, p2 );
554 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
556 if ( deviceClipping )
558 painter->drawPolygon(
563 painter->drawPolygon( polygon );
571 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
573 if ( deviceClipping )
577 qwtDrawPolyline< QPointF >( painter,
578 cpa.constData(), cpa.size(), m_polylineSplitting );
582 qwtDrawPolyline< QPointF >( painter,
583 polygon.constData(), polygon.size(), m_polylineSplitting );
589 const QPointF* points,
int pointCount )
592 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
594 if ( deviceClipping )
596 QPolygonF polygon( pointCount );
597 std::memcpy( polygon.data(), points, pointCount *
sizeof( QPointF ) );
600 qwtDrawPolyline< QPointF >( painter,
601 polygon.constData(), polygon.size(), m_polylineSplitting );
605 qwtDrawPolyline< QPointF >( painter, points, pointCount, m_polylineSplitting );
613 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
615 if ( deviceClipping )
617 painter->drawPolygon(
622 painter->drawPolygon( polygon );
630 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
632 if ( deviceClipping )
636 qwtDrawPolyline< QPoint >( painter,
637 cpa.constData(), cpa.size(), m_polylineSplitting );
641 qwtDrawPolyline< QPoint >( painter,
642 polygon.constData(), polygon.size(), m_polylineSplitting );
648 const QPoint* points,
int pointCount )
651 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
653 if ( deviceClipping )
655 QPolygon polygon( pointCount );
656 std::memcpy( polygon.data(), points, pointCount *
sizeof( QPoint ) );
659 qwtDrawPolyline< QPoint >( painter,
660 polygon.constData(), polygon.size(), m_polylineSplitting );
664 qwtDrawPolyline< QPoint >( painter, points, pointCount, m_polylineSplitting );
672 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
674 if ( deviceClipping && !clipRect.contains( pos ) )
677 painter->drawPoint( pos );
684 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
686 if ( deviceClipping )
688 const int minX = qwtCeil( clipRect.left() );
689 const int maxX = qwtFloor( clipRect.right() );
690 const int minY = qwtCeil( clipRect.top() );
691 const int maxY = qwtFloor( clipRect.bottom() );
693 if ( pos.x() < minX || pos.x() > maxX
694 || pos.y() < minY || pos.y() > maxY )
700 painter->drawPoint( pos );
705 const QPoint* points,
int pointCount )
708 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
710 if ( deviceClipping )
712 const int minX = qwtCeil( clipRect.left() );
713 const int maxX = qwtFloor( clipRect.right() );
714 const int minY = qwtCeil( clipRect.top() );
715 const int maxY = qwtFloor( clipRect.bottom() );
717 const QRect r( minX, minY, maxX - minX, maxY - minY );
719 QPolygon clippedPolygon( pointCount );
720 QPoint* clippedData = clippedPolygon.data();
722 int numClippedPoints = 0;
723 for (
int i = 0; i < pointCount; i++ )
725 if ( r.contains( points[i] ) )
726 clippedData[ numClippedPoints++ ] = points[i];
728 painter->drawPoints( clippedData, numClippedPoints );
732 painter->drawPoints( points, pointCount );
738 const QPointF* points,
int pointCount )
741 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
743 if ( deviceClipping )
745 QPolygonF clippedPolygon( pointCount );
746 QPointF* clippedData = clippedPolygon.data();
748 int numClippedPoints = 0;
749 for (
int i = 0; i < pointCount; i++ )
751 if ( clipRect.contains( points[i] ) )
752 clippedData[ numClippedPoints++ ] = points[i];
754 painter->drawPoints( clippedData, numClippedPoints );
758 painter->drawPoints( points, pointCount );
764 const QRectF& rect,
const QImage& image )
766 const QRect alignedRect = rect.toAlignedRect();
768 if ( alignedRect != rect )
770 const QRectF clipRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
773 painter->setClipRect( clipRect, Qt::IntersectClip );
774 painter->drawImage( alignedRect, image );
779 painter->drawImage( alignedRect, image );
785 const QRectF& rect,
const QPixmap& pixmap )
787 const QRect alignedRect = rect.toAlignedRect();
789 if ( alignedRect != rect )
791 const QRectF clipRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
794 painter->setClipRect( clipRect, Qt::IntersectClip );
795 painter->drawPixmap( alignedRect, pixmap );
800 painter->drawPixmap( alignedRect, pixmap );
814 QStyleOptionFocusRect opt;
815 opt.initFrom( widget );
817 opt.state |= QStyle::State_HasFocus;
818 opt.backgroundColor = widget->palette().color( widget->backgroundRole() );
820 widget->style()->drawPrimitive(
821 QStyle::PE_FrameFocusRect, &opt, painter, widget );
836 const QRectF& rect,
const QPalette& palette,
837 int lineWidth,
int frameStyle )
847 if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken )
849 else if ( (frameStyle& QFrame::Raised) == QFrame::Raised )
852 const qreal lw2 = 0.5 * lineWidth;
853 QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
857 if ( style != Plain )
859 QColor c1 = palette.color( QPalette::Light );
860 QColor c2 = palette.color( QPalette::Dark );
862 if ( style == Sunken )
865 QLinearGradient gradient( r.topLeft(), r.bottomRight() );
866 gradient.setColorAt( 0.0, c1 );
868 gradient.setColorAt( 0.3, c1 );
869 gradient.setColorAt( 0.7, c2 );
871 gradient.setColorAt( 1.0, c2 );
873 brush = QBrush( gradient );
877 brush = palette.brush( QPalette::WindowText );
882 painter->setPen( QPen( brush, lineWidth ) );
883 painter->setBrush( Qt::NoBrush );
885 painter->drawEllipse( r );
902 const QPalette& palette, QPalette::ColorRole foregroundRole,
903 int frameWidth,
int midLineWidth,
int frameStyle )
905 if ( frameWidth <= 0 || rect.isEmpty() )
908 const int shadow = frameStyle & QFrame::Shadow_Mask;
912 if ( shadow == QFrame::Plain )
914 const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
915 const QRectF innerRect = outerRect.adjusted(
916 frameWidth, frameWidth, -frameWidth, -frameWidth );
919 path.addRect( outerRect );
920 path.addRect( innerRect );
922 painter->setPen( Qt::NoPen );
923 painter->setBrush( palette.color( foregroundRole ) );
925 painter->drawPath( path );
929 const int shape = frameStyle & QFrame::Shape_Mask;
931 if ( shape == QFrame::Box )
933 const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
934 const QRectF midRect1 = outerRect.adjusted(
935 frameWidth, frameWidth, -frameWidth, -frameWidth );
936 const QRectF midRect2 = midRect1.adjusted(
937 midLineWidth, midLineWidth, -midLineWidth, -midLineWidth );
939 const QRectF innerRect = midRect2.adjusted(
940 frameWidth, frameWidth, -frameWidth, -frameWidth );
943 path1.moveTo( outerRect.bottomLeft() );
944 path1.lineTo( outerRect.topLeft() );
945 path1.lineTo( outerRect.topRight() );
946 path1.lineTo( midRect1.topRight() );
947 path1.lineTo( midRect1.topLeft() );
948 path1.lineTo( midRect1.bottomLeft() );
951 path2.moveTo( outerRect.bottomLeft() );
952 path2.lineTo( outerRect.bottomRight() );
953 path2.lineTo( outerRect.topRight() );
954 path2.lineTo( midRect1.topRight() );
955 path2.lineTo( midRect1.bottomRight() );
956 path2.lineTo( midRect1.bottomLeft() );
959 path3.moveTo( midRect2.bottomLeft() );
960 path3.lineTo( midRect2.topLeft() );
961 path3.lineTo( midRect2.topRight() );
962 path3.lineTo( innerRect.topRight() );
963 path3.lineTo( innerRect.topLeft() );
964 path3.lineTo( innerRect.bottomLeft() );
967 path4.moveTo( midRect2.bottomLeft() );
968 path4.lineTo( midRect2.bottomRight() );
969 path4.lineTo( midRect2.topRight() );
970 path4.lineTo( innerRect.topRight() );
971 path4.lineTo( innerRect.bottomRight() );
972 path4.lineTo( innerRect.bottomLeft() );
975 path5.addRect( midRect1 );
976 path5.addRect( midRect2 );
978 painter->setPen( Qt::NoPen );
980 QBrush brush1 = palette.dark().color();
981 QBrush brush2 = palette.light().color();
983 if ( shadow == QFrame::Raised )
984 qSwap( brush1, brush2 );
986 painter->setBrush( brush1 );
987 painter->drawPath( path1 );
988 painter->drawPath( path4 );
990 painter->setBrush( brush2 );
991 painter->drawPath( path2 );
992 painter->drawPath( path3 );
994 painter->setBrush( palette.mid() );
995 painter->drawPath( path5 );
999 const QRectF outerRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 );
1000 const QRectF innerRect = outerRect.adjusted(
1001 frameWidth - 1.0, frameWidth - 1.0,
1002 -( frameWidth - 1.0 ), -( frameWidth - 1.0 ) );
1005 path1.moveTo( outerRect.bottomLeft() );
1006 path1.lineTo( outerRect.topLeft() );
1007 path1.lineTo( outerRect.topRight() );
1008 path1.lineTo( innerRect.topRight() );
1009 path1.lineTo( innerRect.topLeft() );
1010 path1.lineTo( innerRect.bottomLeft() );
1014 path2.moveTo( outerRect.bottomLeft() );
1015 path2.lineTo( outerRect.bottomRight() );
1016 path2.lineTo( outerRect.topRight() );
1017 path2.lineTo( innerRect.topRight() );
1018 path2.lineTo( innerRect.bottomRight() );
1019 path2.lineTo( innerRect.bottomLeft() );
1021 painter->setPen( Qt::NoPen );
1023 QBrush brush1 = palette.dark().color();
1024 QBrush brush2 = palette.light().color();
1026 if ( shadow == QFrame::Raised )
1027 qSwap( brush1, brush2 );
1029 painter->setBrush( brush1 );
1030 painter->drawPath( path1 );
1032 painter->setBrush( brush2 );
1033 painter->drawPath( path2 );
1056 const QRectF& rect, qreal xRadius, qreal yRadius,
1057 const QPalette& palette,
int lineWidth,
int frameStyle )
1060 painter->setRenderHint( QPainter::Antialiasing,
true );
1061 painter->setBrush( Qt::NoBrush );
1063 qreal lw2 = lineWidth * 0.5;
1064 QRectF innerRect = rect.adjusted( lw2, lw2, -lw2, -lw2 );
1067 path.addRoundedRect( innerRect, xRadius, yRadius );
1076 Style style = Plain;
1077 if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken )
1079 else if ( (frameStyle& QFrame::Raised) == QFrame::Raised )
1082 if ( style != Plain && path.elementCount() == 17 )
1085 QPainterPath pathList[8];
1087 for (
int i = 0; i < 4; i++ )
1089 const int j = i * 4 + 1;
1091 pathList[ 2 * i ].moveTo(
1092 path.elementAt(j - 1).x, path.elementAt( j - 1 ).y
1095 pathList[ 2 * i ].cubicTo(
1096 path.elementAt(j + 0).x, path.elementAt(j + 0).y,
1097 path.elementAt(j + 1).x, path.elementAt(j + 1).y,
1098 path.elementAt(j + 2).x, path.elementAt(j + 2).y );
1100 pathList[ 2 * i + 1 ].moveTo(
1101 path.elementAt(j + 2).x, path.elementAt(j + 2).y
1103 pathList[ 2 * i + 1 ].lineTo(
1104 path.elementAt(j + 3).x, path.elementAt(j + 3).y
1108 QColor c1( palette.color( QPalette::Dark ) );
1109 QColor c2( palette.color( QPalette::Light ) );
1111 if ( style == Raised )
1114 for (
int i = 0; i < 4; i++ )
1116 const QRectF r = pathList[2 * i].controlPointRect();
1119 arcPen.setCapStyle( Qt::FlatCap );
1120 arcPen.setWidth( lineWidth );
1123 linePen.setCapStyle( Qt::FlatCap );
1124 linePen.setWidth( lineWidth );
1130 arcPen.setColor( c1 );
1131 linePen.setColor( c1 );
1136 QLinearGradient gradient;
1137 gradient.setStart( r.topLeft() );
1138 gradient.setFinalStop( r.bottomRight() );
1139 gradient.setColorAt( 0.0, c1 );
1140 gradient.setColorAt( 1.0, c2 );
1142 arcPen.setBrush( gradient );
1143 linePen.setColor( c2 );
1148 arcPen.setColor( c2 );
1149 linePen.setColor( c2 );
1154 QLinearGradient gradient;
1156 gradient.setStart( r.bottomRight() );
1157 gradient.setFinalStop( r.topLeft() );
1158 gradient.setColorAt( 0.0, c2 );
1159 gradient.setColorAt( 1.0, c1 );
1161 arcPen.setBrush( gradient );
1162 linePen.setColor( c1 );
1168 painter->setPen( arcPen );
1169 painter->drawPath( pathList[ 2 * i] );
1171 painter->setPen( linePen );
1172 painter->drawPath( pathList[ 2 * i + 1] );
1177 QPen pen( palette.color( QPalette::WindowText ), lineWidth );
1178 painter->setPen( pen );
1179 painter->drawPath( path );
1197 const QwtScaleMap& scaleMap, Qt::Orientation orientation,
1198 const QRectF& rect )
1206 const QRect devRect = rect.toAlignedRect();
1213 QPixmap pixmap( devRect.size() );
1214 pixmap.fill( Qt::transparent );
1216 QPainter pmPainter( &pixmap );
1217 pmPainter.translate( -devRect.x(), -devRect.y() );
1219 if ( orientation == Qt::Horizontal )
1224 for (
int x = devRect.left(); x <= devRect.right(); x++ )
1229 c.setRgba( colorMap.
rgb( interval, value ) );
1231 c = colorTable[colorMap.
colorIndex( 256, interval, value )];
1233 pmPainter.setPen( c );
1234 pmPainter.drawLine( x, devRect.top(), x, devRect.bottom() );
1242 for (
int y = devRect.top(); y <= devRect.bottom(); y++ )
1247 c.setRgba( colorMap.
rgb( interval, value ) );
1249 c = colorTable[colorMap.
colorIndex( 256, interval, value )];
1251 pmPainter.setPen( c );
1252 pmPainter.drawLine( devRect.left(), y, devRect.right(), y );
1260static inline void qwtFillRect(
const QWidget* widget, QPainter* painter,
1261 const QRect& rect,
const QBrush& brush)
1263 if ( brush.style() == Qt::TexturePattern )
1267 painter->setClipRect( rect );
1268 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft() );
1272 else if ( brush.gradient() )
1276 painter->setClipRect( rect );
1277 painter->fillRect(0, 0, widget->width(),
1278 widget->height(), brush);
1284 painter->fillRect(rect, brush);
1302 QPixmap& pixmap,
const QPoint& offset )
1304 const QRect rect( offset, pixmap.size() );
1306 QPainter painter( &pixmap );
1307 painter.translate( -offset );
1309 const QBrush autoFillBrush =
1310 widget->palette().brush( widget->backgroundRole() );
1312 if ( !( widget->autoFillBackground() && autoFillBrush.isOpaque() ) )
1314 const QBrush bg = widget->palette().brush( QPalette::Window );
1315 qwtFillRect( widget, &painter, rect, bg);
1318 if ( widget->autoFillBackground() )
1319 qwtFillRect( widget, &painter, rect, autoFillBrush);
1321 if ( widget->testAttribute(Qt::WA_StyledBackground) )
1323 painter.setClipRegion( rect );
1326 opt.initFrom( widget );
1327 widget->style()->drawPrimitive( QStyle::PE_Widget,
1328 &opt, &painter, widget );
1342 const QRectF& rect,
const QWidget* widget )
1344 if ( widget->testAttribute( Qt::WA_StyledBackground ) )
1347 opt.initFrom( widget );
1348 opt.rect = rect.toAlignedRect();
1350 widget->style()->drawPrimitive(
1351 QStyle::PE_Widget, &opt, painter, widget);
1355 const QBrush brush =
1356 widget->palette().brush( widget->backgroundRole() );
1358 painter->fillRect( rect, brush );
1370 const QFontMetrics& fontMetrics,
const QString& text )
1372#if QT_VERSION >= 0x050b00
1373 return fontMetrics.horizontalAdvance( text );
1375 return fontMetrics.width( text );
1388 const QFontMetricsF& fontMetrics,
const QString& text )
1390#if QT_VERSION >= 0x050b00
1391 return fontMetrics.horizontalAdvance( text );
1393 return fontMetrics.width( text );
1405 const QFontMetrics& fontMetrics, QChar ch )
1407#if QT_VERSION >= 0x050b00
1408 return fontMetrics.horizontalAdvance( ch );
1410 return fontMetrics.width( ch );
1422 const QFontMetricsF& fontMetrics, QChar ch )
1424#if QT_VERSION >= 0x050b00
1425 return fontMetrics.horizontalAdvance( ch );
1427 return fontMetrics.width( ch );
1442 if ( paintDevice == NULL )
1444#if QT_VERSION < 0x060000
1445 paintDevice = QApplication::desktop();
1447 class PaintDevice :
public QPaintDevice
1449 virtual QPaintEngine* paintEngine()
const QWT_OVERRIDE
1454 virtual int metric( PaintDeviceMetric metric )
const QWT_OVERRIDE
1456 if ( metric == PdmDpiY )
1458 QScreen* screen = QGuiApplication::primaryScreen();
1461 return screen->logicalDotsPerInchY();
1465 return QPaintDevice::metric( metric );
1469 static PaintDevice dummyPaintDevice;
1470 paintDevice = &dummyPaintDevice;
1474 return QFont( font,
const_cast< QPaintDevice*
>( paintDevice ) );
1483 qreal pixelRatio = 0.0;
1485#if QT_VERSION >= 0x050100
1488#if QT_VERSION >= 0x050600
1489 pixelRatio = paintDevice->devicePixelRatioF();
1491 pixelRatio = paintDevice->devicePixelRatio();
1495 Q_UNUSED( paintDevice )
1498#if QT_VERSION >= 0x050000
1499 if ( pixelRatio == 0.0 && qApp )
1500 pixelRatio = qApp->devicePixelRatio();
1503 if ( pixelRatio == 0.0 )
1519#if QT_VERSION >= 0x050000
1522 pm = QPixmap( size * pixelRatio );
1523 pm.setDevicePixelRatio( pixelRatio );
1525 pm = QPixmap( size );
1531 if ( pm.x11Info().screen() != widget->x11Info().screen() )
1532 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 void drawPixmap(QPainter *, const QRectF &, const QPixmap &)
Wrapper for QPainter::drawPixmap()
static QFont scaledFont(const QFont &, const QPaintDevice *=NULL)
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)