Index: trunk/BNC/qwt/qwt_painter.cpp
===================================================================
--- trunk/BNC/qwt/qwt_painter.cpp	(revision 9383)
+++ trunk/BNC/qwt/qwt_painter.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -13,5 +13,5 @@
 #include "qwt_color_map.h"
 #include "qwt_scale_map.h"
-#include <qwindowdefs.h>
+
 #include <qwidget.h>
 #include <qframe.h>
@@ -28,8 +28,9 @@
 #include <qpaintengine.h>
 #include <qapplication.h>
+
+#if QT_VERSION >= 0x060000
+#include <qscreen.h>
+#else
 #include <qdesktopwidget.h>
-
-#if QT_VERSION >= 0x050000
-#include <qwindow.h>
 #endif
 
@@ -42,12 +43,53 @@
 #endif
 
-bool QwtPainter::d_polylineSplitting = true;
-bool QwtPainter::d_roundingAlignment = true;
+#include <cstring>
+
+bool QwtPainter::m_polylineSplitting = true;
+bool QwtPainter::m_roundingAlignment = true;
+
+static inline bool qwtIsRasterPaintEngineBuggy()
+{
+#if 0
+    static int isBuggy = -1;
+    if ( isBuggy < 0 )
+    {
+        // auto detect bug of the raster paint engine,
+        // fixed with: https://codereview.qt-project.org/#/c/99456/
+
+        QImage image( 2, 3, QImage::Format_ARGB32 );
+        image.fill( 0u );
+
+        QPolygonF p;
+        p += QPointF(0, 1);
+        p += QPointF(0, 0);
+        p += QPointF(1, 0 );
+        p += QPointF(1, 2 );
+
+        QPainter painter( &image );
+        painter.drawPolyline( p );
+        painter.end();
+
+        isBuggy = ( image.pixel( 1, 1 ) == 0 ) ? 1 : 0;
+    }
+
+    return isBuggy == 1;
+#endif
+
+#if QT_VERSION < 0x050000
+    return true;
+#elif QT_VERSION < 0x050100
+    return false;
+#elif QT_VERSION < 0x050400
+    return true;
+#else
+    return false;
+#endif
+}
 
 static inline bool qwtIsClippingNeeded(
-    const QPainter *painter, QRectF &clipRect )
+    const QPainter* painter, QRectF& clipRect )
 {
     bool doClipping = false;
-    const QPaintEngine *pe = painter->paintEngine();
+    const QPaintEngine* pe = painter->paintEngine();
     if ( pe && pe->type() == QPaintEngine::SVG )
     {
@@ -64,19 +106,18 @@
 }
 
-template <class T>
-static inline void qwtDrawPolyline( QPainter *painter,
-    const T *points, int pointCount, bool polylineSplitting )
+template< class T >
+static inline void qwtDrawPolyline( QPainter* painter,
+    const T* points, int pointCount, bool polylineSplitting )
 {
     bool doSplit = false;
     if ( polylineSplitting )
     {
-        const QPaintEngine *pe = painter->paintEngine();
+        const QPaintEngine* pe = painter->paintEngine();
         if ( pe && pe->type() == QPaintEngine::Raster )
         {
             /*
-                The raster paint engine seems to use some algo with O(n*n).
-                ( Qt 4.3 is better than Qt 4.2, but remains unacceptable)
-                To work around this problem, we have to split the polygon into
-                smaller pieces.
+               Raster paint engine is much faster when splitting
+               the polygon, but of course we might see some issues where
+               the pieces are joining
              */
             doSplit = true;
@@ -86,10 +127,37 @@
     if ( doSplit )
     {
+        QPen pen = painter->pen();
+
         const int splitSize = 6;
 
-        for ( int i = 0; i < pointCount; i += splitSize )
-        {
-            const int n = qMin( splitSize + 1, pointCount - i );
-            painter->drawPolyline( points + i, n );
+        if ( pen.width() <= 1 && pen.isSolid() && qwtIsRasterPaintEngineBuggy()
+            && !( painter->renderHints() & QPainter::Antialiasing ) )
+        {
+            int k = 0;
+
+            for ( int i = k + 1; i < pointCount; i++ )
+            {
+                const QPointF& p1 = points[i - 1];
+                const QPointF& p2 = points[i];
+
+                const bool isBad = ( qAbs( p2.y() - p1.y() ) <= 1 )
+                    && qAbs( p2.x() - p1.x() ) <= 1;
+
+                if ( isBad || ( i - k >= splitSize ) )
+                {
+                    painter->drawPolyline( points + k, i - k + 1 );
+                    k = i;
+                }
+            }
+
+            painter->drawPolyline( points + k, pointCount - k );
+        }
+        else
+        {
+            for ( int i = 0; i < pointCount; i += splitSize )
+            {
+                const int n = qMin( splitSize + 1, pointCount - i );
+                painter->drawPolyline( points + i, n );
+            }
         }
     }
@@ -105,5 +173,16 @@
     if ( !screenResolution.isValid() )
     {
-        QDesktopWidget *desktop = QApplication::desktop();
+        /*
+            We might have screens with different resolutions. TODO ...
+         */
+#if QT_VERSION >= 0x060000
+        QScreen* screen = QGuiApplication::primaryScreen();
+        if ( screen )
+        {
+            screenResolution.setWidth( screen->logicalDotsPerInchX() );
+            screenResolution.setHeight( screen->logicalDotsPerInchY() );
+        }
+#else
+        QDesktopWidget* desktop = QApplication::desktop();
         if ( desktop )
         {
@@ -111,4 +190,5 @@
             screenResolution.setHeight( desktop->logicalDpiY() );
         }
+#endif
     }
 
@@ -116,5 +196,5 @@
 }
 
-static inline void qwtUnscaleFont( QPainter *painter )
+static inline void qwtUnscaleFont( QPainter* painter )
 {
     if ( painter->font().pixelSize() >= 0 )
@@ -123,9 +203,9 @@
     const QSize screenResolution = qwtScreenResolution();
 
-    const QPaintDevice *pd = painter->device();
+    const QPaintDevice* pd = painter->device();
     if ( pd->logicalDpiX() != screenResolution.width() ||
         pd->logicalDpiY() != screenResolution.height() )
     {
-        QFont pixelFont( painter->font(), QApplication::desktop() );
+        QFont pixelFont = QwtPainter::scaledFont( painter->font() );
         pixelFont.setPixelSize( QFontInfo( pixelFont ).pixelSize() );
 
@@ -135,10 +215,10 @@
 
 /*!
-  Check is the application is running with the X11 graphics system
-  that has some special capabilities that can be used for incremental
-  painting to a widget.
-
-  \return True, when the graphics system is X11
-*/
+   Check is the application is running with the X11 graphics system
+   that has some special capabilities that can be used for incremental
+   painting to a widget.
+
+   \return True, when the graphics system is X11
+ */
 bool QwtPainter::isX11GraphicsSystem()
 {
@@ -162,31 +242,44 @@
 
 /*!
-  Check if the painter is using a paint engine, that aligns
-  coordinates to integers. Today these are all paint engines
-  beside QPaintEngine::Pdf and QPaintEngine::SVG.
-
-  If we have an integer based paint engine it is also
-  checked if the painter has a transformation matrix,
-  that rotates or scales.
-
-  \param  painter Painter
-  \return true, when the painter is aligning
-
-  \sa setRoundingAlignment()
-*/
-bool QwtPainter::isAligning( QPainter *painter )
+   Check if the painter is using a paint engine, that aligns
+   coordinates to integers. Today these are all paint engines
+   beside QPaintEngine::Pdf and QPaintEngine::SVG.
+
+   If we have an integer based paint engine it is also
+   checked if the painter has a transformation matrix,
+   that rotates or scales.
+
+   \param  painter Painter
+   \return true, when the painter is aligning
+
+   \sa setRoundingAlignment()
+ */
+bool QwtPainter::isAligning( const QPainter* painter )
 {
     if ( painter && painter->isActive() )
     {
-        switch ( painter->paintEngine()->type() )
+        const QPaintEngine::Type type =
+            painter->paintEngine()->type();
+
+        if ( type >= QPaintEngine::User )
+        {
+            // we have no idea - better don't align
+            return false;
+        }
+
+        switch ( type )
         {
             case QPaintEngine::Pdf:
             case QPaintEngine::SVG:
+#if 0
+            case QPaintEngine::MacPrinter:
+#endif
                 return false;
 
-            default:;
-        }
-
-        const QTransform &tr = painter->transform();
+            default:
+                break;
+        }
+
+        const QTransform& tr = painter->transform();
         if ( tr.isRotating() || tr.isScaling() )
         {
@@ -200,41 +293,41 @@
 
 /*!
-  Enable whether coordinates should be rounded, before they are painted
-  to a paint engine that floors to integer values. For other paint engines
-  ( PDF, SVG ) this flag has no effect.
-  QwtPainter stores this flag only, the rounding itself is done in
-  the painting code ( f.e the plot items ).
-
-  The default setting is true.
-
-  \sa roundingAlignment(), isAligning()
-*/
+   Enable whether coordinates should be rounded, before they are painted
+   to a paint engine that floors to integer values. For other paint engines
+   ( PDF, SVG ) this flag has no effect.
+   QwtPainter stores this flag only, the rounding itself is done in
+   the painting code ( f.e the plot items ).
+
+   The default setting is true.
+
+   \sa roundingAlignment(), isAligning()
+ */
 void QwtPainter::setRoundingAlignment( bool enable )
 {
-    d_roundingAlignment = enable;
-}
-
-/*!
-  \brief En/Disable line splitting for the raster paint engine
-
-  In some Qt versions the raster paint engine paints polylines of many points
-  much faster when they are split in smaller chunks: f.e all supported Qt versions
-  >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2.
-
-  Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... )
-  for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked
-  around in this mode.
-
-  The default setting is true.
-
-  \sa polylineSplitting()
-*/
+    m_roundingAlignment = enable;
+}
+
+/*!
+   \brief En/Disable line splitting for the raster paint engine
+
+   In some Qt versions the raster paint engine paints polylines of many points
+   much faster when they are split in smaller chunks: f.e all supported Qt versions
+   >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2.
+
+   Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... )
+   for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked
+   around in this mode.
+
+   The default setting is true.
+
+   \sa polylineSplitting()
+ */
 void QwtPainter::setPolylineSplitting( bool enable )
 {
-    d_polylineSplitting = enable;
+    m_polylineSplitting = enable;
 }
 
 //! Wrapper for QPainter::drawPath()
-void QwtPainter::drawPath( QPainter *painter, const QPainterPath &path )
+void QwtPainter::drawPath( QPainter* painter, const QPainterPath& path )
 {
     painter->drawPath( path );
@@ -242,5 +335,5 @@
 
 //! Wrapper for QPainter::drawRect()
-void QwtPainter::drawRect( QPainter *painter, double x, double y, double w, double h )
+void QwtPainter::drawRect( QPainter* painter, qreal x, qreal y, qreal w, qreal h )
 {
     drawRect( painter, QRectF( x, y, w, h ) );
@@ -248,5 +341,5 @@
 
 //! Wrapper for QPainter::drawRect()
-void QwtPainter::drawRect( QPainter *painter, const QRectF &rect )
+void QwtPainter::drawRect( QPainter* painter, const QRectF& rect )
 {
     const QRectF r = rect;
@@ -277,6 +370,6 @@
 
 //! Wrapper for QPainter::fillRect()
-void QwtPainter::fillRect( QPainter *painter,
-    const QRectF &rect, const QBrush &brush )
+void QwtPainter::fillRect( QPainter* painter,
+    const QRectF& rect, const QBrush& brush )
 {
     if ( !rect.isValid() )
@@ -287,8 +380,8 @@
 
     /*
-      Performance of Qt4 is horrible for a non trivial brush. Without
-      clipping expect minutes or hours for repainting large rectangles
-      (might result from zooming)
-    */
+       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 )
@@ -309,5 +402,5 @@
 
 //! Wrapper for QPainter::drawPie()
-void QwtPainter::drawPie( QPainter *painter, const QRectF &rect,
+void QwtPainter::drawPie( QPainter* painter, const QRectF& rect,
     int a, int alen )
 {
@@ -321,5 +414,5 @@
 
 //! Wrapper for QPainter::drawEllipse()
-void QwtPainter::drawEllipse( QPainter *painter, const QRectF &rect )
+void QwtPainter::drawEllipse( QPainter* painter, const QRectF& rect )
 {
     QRectF clipRect;
@@ -333,6 +426,6 @@
 
 //! Wrapper for QPainter::drawText()
-void QwtPainter::drawText( QPainter *painter, double x, double y,
-        const QString &text )
+void QwtPainter::drawText( QPainter* painter,
+    qreal x, qreal y, const QString& text )
 {
     drawText( painter, QPointF( x, y ), text );
@@ -340,6 +433,6 @@
 
 //! Wrapper for QPainter::drawText()
-void QwtPainter::drawText( QPainter *painter, const QPointF &pos,
-        const QString &text )
+void QwtPainter::drawText( QPainter* painter, const QPointF& pos,
+    const QString& text )
 {
     QRectF clipRect;
@@ -357,7 +450,7 @@
 
 //! Wrapper for QPainter::drawText()
-void QwtPainter::drawText( QPainter *painter,
-    double x, double y, double w, double h,
-    int flags, const QString &text )
+void QwtPainter::drawText( QPainter* painter,
+    qreal x, qreal y, qreal w, qreal h,
+    int flags, const QString& text )
 {
     drawText( painter, QRectF( x, y, w, h ), flags, text );
@@ -365,6 +458,6 @@
 
 //! Wrapper for QPainter::drawText()
-void QwtPainter::drawText( QPainter *painter, const QRectF &rect,
-        int flags, const QString &text )
+void QwtPainter::drawText( QPainter* painter, const QRectF& rect,
+    int flags, const QString& text )
 {
     painter->save();
@@ -377,15 +470,15 @@
 
 /*!
-  Draw a text document into a rectangle
-
-  \param painter Painter
-  \param rect Traget rectangle
-  \param flags Alignments/Text flags, see QPainter::drawText()
-  \param text Text document
-*/
-void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
-    int flags, const QTextDocument &text )
-{
-    QTextDocument *txt = text.clone();
+   Draw a text document into a rectangle
+
+   \param painter Painter
+   \param rect Target rectangle
+   \param flags Alignments/Text flags, see QPainter::drawText()
+   \param text Text document
+ */
+void QwtPainter::drawSimpleRichText( QPainter* painter, const QRectF& rect,
+    int flags, const QTextDocument& text )
+{
+    QTextDocument* txt = text.clone();
 
     painter->save();
@@ -397,11 +490,11 @@
         const QSize res = qwtScreenResolution();
 
-        const QPaintDevice *pd = painter->device();
+        const QPaintDevice* pd = painter->device();
         if ( pd->logicalDpiX() != res.width() ||
             pd->logicalDpiY() != res.height() )
         {
             QTransform transform;
-            transform.scale( res.width() / double( pd->logicalDpiX() ),
-                res.height() / double( pd->logicalDpiY() ));
+            transform.scale( res.width() / qreal( pd->logicalDpiX() ),
+                res.height() / qreal( pd->logicalDpiY() ) );
 
             painter->setWorldTransform( transform, true );
@@ -415,6 +508,6 @@
     QAbstractTextDocumentLayout* layout = txt->documentLayout();
 
-    const double height = layout->documentSize().height();
-    double y = unscaledRect.y();
+    const qreal height = layout->documentSize().height();
+    qreal y = unscaledRect.y();
     if ( flags & Qt::AlignBottom )
         y += ( unscaledRect.height() - height );
@@ -436,6 +529,6 @@
 
 //! Wrapper for QPainter::drawLine()
-void QwtPainter::drawLine( QPainter *painter,
-    const QPointF &p1, const QPointF &p2 )
+void QwtPainter::drawLine( QPainter* painter,
+    const QPointF& p1, const QPointF& p2 )
 {
     QRectF clipRect;
@@ -456,33 +549,43 @@
 
 //! Wrapper for QPainter::drawPolygon()
-void QwtPainter::drawPolygon( QPainter *painter, const QPolygonF &polygon )
+void QwtPainter::drawPolygon( QPainter* painter, const QPolygonF& polygon )
 {
     QRectF clipRect;
     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
-    QPolygonF cpa = polygon;
     if ( deviceClipping )
-        cpa = QwtClipper::clipPolygonF( clipRect, polygon, true );
-
-    painter->drawPolygon( cpa );
+    {
+        painter->drawPolygon(
+            QwtClipper::clippedPolygonF( clipRect, polygon, true ) );
+    }
+    else
+    {
+        painter->drawPolygon( polygon );
+    }
 }
 
 //! Wrapper for QPainter::drawPolyline()
-void QwtPainter::drawPolyline( QPainter *painter, const QPolygonF &polygon )
+void QwtPainter::drawPolyline( QPainter* painter, const QPolygonF& polygon )
 {
     QRectF clipRect;
     const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
 
-    QPolygonF cpa = polygon;
     if ( deviceClipping )
-        cpa = QwtClipper::clipPolygonF( clipRect, cpa );
-
-    qwtDrawPolyline<QPointF>( painter,
-        cpa.constData(), cpa.size(), d_polylineSplitting );
+    {
+        const QPolygonF cpa = QwtClipper::clippedPolygonF( clipRect, polygon );
+
+        qwtDrawPolyline< QPointF >( painter,
+            cpa.constData(), cpa.size(), m_polylineSplitting );
+    }
+    else
+    {
+        qwtDrawPolyline< QPointF >( painter,
+            polygon.constData(), polygon.size(), m_polylineSplitting );
+    }
 }
 
 //! Wrapper for QPainter::drawPolyline()
-void QwtPainter::drawPolyline( QPainter *painter,
-    const QPointF *points, int pointCount )
+void QwtPainter::drawPolyline( QPainter* painter,
+    const QPointF* points, int pointCount )
 {
     QRectF clipRect;
@@ -492,46 +595,56 @@
     {
         QPolygonF polygon( pointCount );
-        ::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
-
-        polygon = QwtClipper::clipPolygonF( clipRect, polygon );
-        qwtDrawPolyline<QPointF>( painter,
-            polygon.constData(), polygon.size(), d_polylineSplitting );
+        std::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
+
+        QwtClipper::clipPolygonF( clipRect, polygon );
+        qwtDrawPolyline< QPointF >( painter,
+            polygon.constData(), polygon.size(), m_polylineSplitting );
     }
     else
     {
-        qwtDrawPolyline<QPointF>( painter, points, pointCount, d_polylineSplitting );
+        qwtDrawPolyline< QPointF >( painter, points, pointCount, m_polylineSplitting );
     }
 }
 
 //! Wrapper for QPainter::drawPolygon()
-void QwtPainter::drawPolygon( QPainter *painter, const QPolygon &polygon )
+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, true );
-
-    painter->drawPolygon( cpa );
+    {
+        painter->drawPolygon(
+            QwtClipper::clippedPolygon( clipRect, polygon, true ) );
+    }
+    else
+    {
+        painter->drawPolygon( polygon );
+    }
 }
 
 //! Wrapper for QPainter::drawPolyline()
-void QwtPainter::drawPolyline( QPainter *painter, const QPolygon &polygon )
+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 );
+    {
+        const QPolygon cpa = QwtClipper::clippedPolygon( clipRect, polygon );
+
+        qwtDrawPolyline< QPoint >( painter,
+            cpa.constData(), cpa.size(), m_polylineSplitting );
+    }
+    else
+    {
+        qwtDrawPolyline< QPoint >( painter,
+            polygon.constData(), polygon.size(), m_polylineSplitting );
+    }
 }
 
 //! Wrapper for QPainter::drawPolyline()
-void QwtPainter::drawPolyline( QPainter *painter,
-    const QPoint *points, int pointCount )
+void QwtPainter::drawPolyline( QPainter* painter,
+    const QPoint* points, int pointCount )
 {
     QRectF clipRect;
@@ -541,18 +654,18 @@
     {
         QPolygon polygon( pointCount );
-        ::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) );
-
-        polygon = QwtClipper::clipPolygon( clipRect, polygon );
-        qwtDrawPolyline<QPoint>( painter,
-            polygon.constData(), polygon.size(), d_polylineSplitting );
+        std::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) );
+
+        QwtClipper::clipPolygon( clipRect, polygon );
+        qwtDrawPolyline< QPoint >( painter,
+            polygon.constData(), polygon.size(), m_polylineSplitting );
     }
     else
     {
-        qwtDrawPolyline<QPoint>( painter, points, pointCount, d_polylineSplitting );
+        qwtDrawPolyline< QPoint >( painter, points, pointCount, m_polylineSplitting );
     }
 }
 
 //! Wrapper for QPainter::drawPoint()
-void QwtPainter::drawPoint( QPainter *painter, const QPointF &pos )
+void QwtPainter::drawPoint( QPainter* painter, const QPointF& pos )
 {
     QRectF clipRect;
@@ -566,5 +679,5 @@
 
 //! Wrapper for QPainter::drawPoint()
-void QwtPainter::drawPoint( QPainter *painter, const QPoint &pos )
+void QwtPainter::drawPoint( QPainter* painter, const QPoint& pos )
 {
     QRectF clipRect;
@@ -573,8 +686,8 @@
     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 int minX = qwtCeil( clipRect.left() );
+        const int maxX = qwtFloor( clipRect.right() );
+        const int minY = qwtCeil( clipRect.top() );
+        const int maxY = qwtFloor( clipRect.bottom() );
 
         if ( pos.x() < minX || pos.x() > maxX
@@ -589,6 +702,6 @@
 
 //! Wrapper for QPainter::drawPoints()
-void QwtPainter::drawPoints( QPainter *painter,
-    const QPoint *points, int pointCount )
+void QwtPainter::drawPoints( QPainter* painter,
+    const QPoint* points, int pointCount )
 {
     QRectF clipRect;
@@ -597,13 +710,13 @@
     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 int minX = qwtCeil( clipRect.left() );
+        const int maxX = qwtFloor( clipRect.right() );
+        const int minY = qwtCeil( clipRect.top() );
+        const int maxY = qwtFloor( clipRect.bottom() );
 
         const QRect r( minX, minY, maxX - minX, maxY - minY );
 
         QPolygon clippedPolygon( pointCount );
-        QPoint *clippedData = clippedPolygon.data();
+        QPoint* clippedData = clippedPolygon.data();
 
         int numClippedPoints = 0;
@@ -622,6 +735,6 @@
 
 //! Wrapper for QPainter::drawPoints()
-void QwtPainter::drawPoints( QPainter *painter,
-    const QPointF *points, int pointCount )
+void QwtPainter::drawPoints( QPainter* painter,
+    const QPointF* points, int pointCount )
 {
     QRectF clipRect;
@@ -631,5 +744,5 @@
     {
         QPolygonF clippedPolygon( pointCount );
-        QPointF *clippedData = clippedPolygon.data();
+        QPointF* clippedData = clippedPolygon.data();
 
         int numClippedPoints = 0;
@@ -648,6 +761,6 @@
 
 //! Wrapper for QPainter::drawImage()
-void QwtPainter::drawImage( QPainter *painter,
-    const QRectF &rect, const QImage &image )
+void QwtPainter::drawImage( QPainter* painter,
+    const QRectF& rect, const QImage& image )
 {
     const QRect alignedRect = rect.toAlignedRect();
@@ -669,6 +782,6 @@
 
 //! Wrapper for QPainter::drawPixmap()
-void QwtPainter::drawPixmap( QPainter *painter,
-    const QRectF &rect, const QPixmap &pixmap )
+void QwtPainter::drawPixmap( QPainter* painter,
+    const QRectF& rect, const QPixmap& pixmap )
 {
     const QRect alignedRect = rect.toAlignedRect();
@@ -690,5 +803,5 @@
 
 //! Draw a focus rectangle on a widget using its style.
-void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget )
+void QwtPainter::drawFocusRect( QPainter* painter, const QWidget* widget )
 {
     drawFocusRect( painter, widget, widget->rect() );
@@ -696,9 +809,9 @@
 
 //! Draw a focus rectangle on a widget using its style.
-void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget,
-    const QRect &rect )
+void QwtPainter::drawFocusRect( QPainter* painter, const QWidget* widget,
+    const QRect& rect )
 {
     QStyleOptionFocusRect opt;
-    opt.init( widget );
+    opt.initFrom( widget );
     opt.rect = rect;
     opt.state |= QStyle::State_HasFocus;
@@ -710,16 +823,16 @@
 
 /*!
-  Draw a round frame
-
-  \param painter Painter
-  \param rect Frame rectangle
-  \param palette QPalette::WindowText is used for plain borders
+   Draw a round frame
+
+   \param painter Painter
+   \param rect Frame rectangle
+   \param palette QPalette::WindowText is used for plain borders
                  QPalette::Dark and QPalette::Light for raised
                  or sunken borders
-  \param lineWidth Line width
-  \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
-*/
-void QwtPainter::drawRoundFrame( QPainter *painter,
-    const QRectF &rect, const QPalette &palette,
+   \param lineWidth Line width
+   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
+ */
+void QwtPainter::drawRoundFrame( QPainter* painter,
+    const QRectF& rect, const QPalette& palette,
     int lineWidth, int frameStyle )
 {
@@ -732,10 +845,10 @@
 
     Style style = Plain;
-    if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
+    if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken )
         style = Sunken;
-    else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
+    else if ( (frameStyle& QFrame::Raised) == QFrame::Raised )
         style = Raised;
 
-    const double lw2 = 0.5 * lineWidth;
+    const qreal lw2 = 0.5 * lineWidth;
     QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
 
@@ -776,16 +889,16 @@
 
 /*!
-  Draw a rectangular frame
-
-  \param painter Painter
-  \param rect Frame rectangle
-  \param palette Palette
-  \param foregroundRole Foreground role used for QFrame::Plain
-  \param frameWidth Frame width
-  \param midLineWidth Used for QFrame::Box
-  \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
-*/
-void QwtPainter::drawFrame( QPainter *painter, const QRectF &rect,
-    const QPalette &palette, QPalette::ColorRole foregroundRole,
+   Draw a rectangular frame
+
+   \param painter Painter
+   \param rect Frame rectangle
+   \param palette Palette
+   \param foregroundRole Foreground role used for QFrame::Plain
+   \param frameWidth Frame width
+   \param midLineWidth Used for QFrame::Box
+   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
+ */
+void QwtPainter::drawFrame( QPainter* painter, const QRectF& rect,
+    const QPalette& palette, QPalette::ColorRole foregroundRole,
     int frameWidth, int midLineWidth, int frameStyle )
 {
@@ -882,19 +995,4 @@
             painter->drawPath( path5 );
         }
-#if 0
-        // qDrawWinPanel doesn't result in something nice
-        // on a scalable document like PDF. Better draw a
-        // Panel.
-
-        else if ( shape == QFrame::WinPanel )
-        {
-            painter->setRenderHint( QPainter::NonCosmeticDefaultPen, true );
-            qDrawWinPanel ( painter, rect.toRect(), palette,
-                frameStyle & QFrame::Sunken );
-        }
-        else if ( shape == QFrame::StyledPanel )
-        {
-        }
-#endif
         else
         {
@@ -942,20 +1040,20 @@
 
 /*!
-  Draw a rectangular frame with rounded borders
-
-  \param painter Painter
-  \param rect Frame rectangle
-  \param xRadius x-radius of the ellipses defining the corners
-  \param yRadius y-radius of the ellipses defining the corners
-  \param palette QPalette::WindowText is used for plain borders
+   Draw a rectangular frame with rounded borders
+
+   \param painter Painter
+   \param rect Frame rectangle
+   \param xRadius x-radius of the ellipses defining the corners
+   \param yRadius y-radius of the ellipses defining the corners
+   \param palette QPalette::WindowText is used for plain borders
                  QPalette::Dark and QPalette::Light for raised
                  or sunken borders
-  \param lineWidth Line width
-  \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
-*/
-
-void QwtPainter::drawRoundedFrame( QPainter *painter,
-    const QRectF &rect, double xRadius, double yRadius,
-    const QPalette &palette, int lineWidth, int frameStyle )
+   \param lineWidth Line width
+   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
+ */
+
+void QwtPainter::drawRoundedFrame( QPainter* painter,
+    const QRectF& rect, qreal xRadius, qreal yRadius,
+    const QPalette& palette, int lineWidth, int frameStyle )
 {
     painter->save();
@@ -963,5 +1061,5 @@
     painter->setBrush( Qt::NoBrush );
 
-    double lw2 = lineWidth * 0.5;
+    qreal lw2 = lineWidth * 0.5;
     QRectF innerRect = rect.adjusted( lw2, lw2, -lw2, -lw2 );
 
@@ -977,7 +1075,7 @@
 
     Style style = Plain;
-    if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
+    if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken )
         style = Sunken;
-    else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
+    else if ( (frameStyle& QFrame::Raised) == QFrame::Raised )
         style = Raised;
 
@@ -993,5 +1091,5 @@
             pathList[ 2 * i ].moveTo(
                 path.elementAt(j - 1).x, path.elementAt( j - 1 ).y
-            );
+                );
 
             pathList[ 2 * i ].cubicTo(
@@ -1002,8 +1100,8 @@
             pathList[ 2 * i + 1 ].moveTo(
                 path.elementAt(j + 2).x, path.elementAt(j + 2).y
-            );
+                );
             pathList[ 2 * i + 1 ].lineTo(
                 path.elementAt(j + 3).x, path.elementAt(j + 3).y
-            );
+                );
         }
 
@@ -1086,21 +1184,21 @@
 
 /*!
-  Draw a color bar into a rectangle
-
-  \param painter Painter
-  \param colorMap Color map
-  \param interval Value range
-  \param scaleMap Scale map
-  \param orientation Orientation
-  \param rect Traget rectangle
-*/
-void QwtPainter::drawColorBar( QPainter *painter,
-        const QwtColorMap &colorMap, const QwtInterval &interval,
-        const QwtScaleMap &scaleMap, Qt::Orientation orientation,
-        const QRectF &rect )
-{
-    QVector<QRgb> colorTable;
+   Draw a color bar into a rectangle
+
+   \param painter Painter
+   \param colorMap Color map
+   \param interval Value range
+   \param scaleMap Scale map
+   \param orientation Orientation
+   \param rect Target rectangle
+ */
+void QwtPainter::drawColorBar( QPainter* painter,
+    const QwtColorMap& colorMap, const QwtInterval& interval,
+    const QwtScaleMap& scaleMap, Qt::Orientation orientation,
+    const QRectF& rect )
+{
+    QVector< QRgb > colorTable;
     if ( colorMap.format() == QwtColorMap::Indexed )
-        colorTable = colorMap.colorTable( interval );
+        colorTable = colorMap.colorTable256();
 
     QColor c;
@@ -1109,6 +1207,6 @@
 
     /*
-      We paint to a pixmap first to have something scalable for printing
-      ( f.e. in a Pdf document )
+       We paint to a pixmap first to have something scalable for printing
+       ( f.e. in a Pdf document )
      */
 
@@ -1131,5 +1229,5 @@
                 c.setRgba( colorMap.rgb( interval, value ) );
             else
-                c = colorTable[colorMap.colorIndex( interval, value )];
+                c = colorTable[colorMap.colorIndex( 256, interval, value )];
 
             pmPainter.setPen( c );
@@ -1149,5 +1247,5 @@
                 c.setRgba( colorMap.rgb( interval, value ) );
             else
-                c = colorTable[colorMap.colorIndex( interval, value )];
+                c = colorTable[colorMap.colorIndex( 256, interval, value )];
 
             pmPainter.setPen( c );
@@ -1160,6 +1258,6 @@
 }
 
-static inline void qwtFillRect( const QWidget *widget, QPainter *painter,
-    const QRect &rect, const QBrush &brush)
+static inline void qwtFillRect( const QWidget* widget, QPainter* painter,
+    const QRect& rect, const QBrush& brush)
 {
     if ( brush.style() == Qt::TexturePattern )
@@ -1168,5 +1266,5 @@
 
         painter->setClipRect( rect );
-        painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
+        painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft() );
 
         painter->restore();
@@ -1189,18 +1287,18 @@
 
 /*!
-  Fill a pixmap with the content of a widget
-
-  In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy
-  for backgrounds with gradients. Thus fillPixmap() offers
-  an alternative implementation.
-
-  \param widget Widget
-  \param pixmap Pixmap to be filled
-  \param offset Offset
-
-  \sa QPixmap::fill()
- */
-void QwtPainter::fillPixmap( const QWidget *widget,
-    QPixmap &pixmap, const QPoint &offset )
+   Fill a pixmap with the content of a widget
+
+   In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy
+   for backgrounds with gradients. Thus fillPixmap() offers
+   an alternative implementation.
+
+   \param widget Widget
+   \param pixmap Pixmap to be filled
+   \param offset Offset
+
+   \sa QPixmap::fill()
+ */
+void QwtPainter::fillPixmap( const QWidget* widget,
+    QPixmap& pixmap, const QPoint& offset )
 {
     const QRect rect( offset, pixmap.size() );
@@ -1233,14 +1331,14 @@
 
 /*!
-  Fill rect with the background of a widget
-
-  \param painter Painter
-  \param rect Rectangle to be filled
-  \param widget Widget
-
-  \sa QStyle::PE_Widget, QWidget::backgroundRole()
- */
-void QwtPainter::drawBackgound( QPainter *painter,
-    const QRectF &rect, const QWidget *widget )
+   Fill rect with the background of a widget
+
+   \param painter Painter
+   \param rect Rectangle to be filled
+   \param widget Widget
+
+   \sa QStyle::PE_Widget, QWidget::backgroundRole()
+ */
+void QwtPainter::drawBackgound( QPainter* painter,
+    const QRectF& rect, const QWidget* widget )
 {
     if ( widget->testAttribute( Qt::WA_StyledBackground ) )
@@ -1263,40 +1361,169 @@
 
 /*!
-  \return A pixmap that can be used as backing store
-
-  \param widget Widget, for which the backingstore is intended
-  \param size Size of the pixmap
- */
-QPixmap QwtPainter::backingStore( QWidget *widget, const QSize &size )
+   Distance appropriate for drawing a subsequent character after text.
+
+   \param fontMetrics Font metrics
+   \param text Text
+   \return horizontal advance in pixels
+ */
+int QwtPainter::horizontalAdvance(
+    const QFontMetrics& fontMetrics, const QString& text )
+{
+#if QT_VERSION >= 0x050b00
+    return fontMetrics.horizontalAdvance( text );
+#else
+    return fontMetrics.width( text );
+#endif
+
+}
+
+/*!
+   Distance appropriate for drawing a subsequent character after text.
+
+   \param fontMetrics Font metrics
+   \param text Text
+   \return horizontal advance in pixels
+ */
+qreal QwtPainter::horizontalAdvance(
+    const QFontMetricsF& fontMetrics, const QString& text )
+{
+#if QT_VERSION >= 0x050b00
+    return fontMetrics.horizontalAdvance( text );
+#else
+    return fontMetrics.width( text );
+#endif
+}
+
+/*!
+   Distance appropriate for drawing a subsequent character after ch.
+
+   \param fontMetrics Font metrics
+   \param ch Character
+   \return horizontal advance in pixels
+ */
+int QwtPainter::horizontalAdvance(
+    const QFontMetrics& fontMetrics, QChar ch )
+{
+#if QT_VERSION >= 0x050b00
+    return fontMetrics.horizontalAdvance( ch );
+#else
+    return fontMetrics.width( ch );
+#endif
+}
+
+/*!
+   Distance appropriate for drawing a subsequent character after ch.
+
+   \param fontMetrics Font metrics
+   \param ch Character
+   \return horizontal advance in pixels
+ */
+qreal QwtPainter::horizontalAdvance(
+    const QFontMetricsF& fontMetrics, QChar ch )
+{
+#if QT_VERSION >= 0x050b00
+    return fontMetrics.horizontalAdvance( ch );
+#else
+    return fontMetrics.width( ch );
+#endif
+}
+
+/*!
+   Adjust the DPI value of font according to the DPI value of the paint device
+
+   \param font Unscaled font
+   \param paintDevice Paint device providing a DPI value. If paintDevice == null
+                     the DPI value of the primary screen will be used
+
+   \return Font being adjusted to the DPI value of the paint device
+ */
+QFont QwtPainter::scaledFont( const QFont& font, const QPaintDevice* paintDevice )
+{
+    if ( paintDevice == NULL )
+    {
+#if QT_VERSION < 0x060000
+        paintDevice = QApplication::desktop();
+#else
+        class PaintDevice : public QPaintDevice
+        {
+            virtual QPaintEngine* paintEngine() const QWT_OVERRIDE
+            {
+                return NULL;
+            }
+
+            virtual int metric( PaintDeviceMetric metric ) const QWT_OVERRIDE
+            {
+                if ( metric == PdmDpiY )
+                {
+                    QScreen* screen = QGuiApplication::primaryScreen();
+                    if ( screen )
+                    {
+                        return screen->logicalDotsPerInchY();
+                    }
+                }
+
+                return QPaintDevice::metric( metric );
+            }
+        };
+
+        static PaintDevice dummyPaintDevice;
+        paintDevice = &dummyPaintDevice;
+#endif
+    }
+
+    return QFont( font, const_cast< QPaintDevice* >( paintDevice ) );
+}
+
+/*!
+   \return Pixel ratio for a paint device
+   \param paintDevice Paint device
+ */
+qreal QwtPainter::devicePixelRatio( const QPaintDevice* paintDevice )
+{
+    qreal pixelRatio = 0.0;
+
+#if QT_VERSION >= 0x050100
+    if ( paintDevice )
+    {
+#if QT_VERSION >= 0x050600
+        pixelRatio = paintDevice->devicePixelRatioF();
+#else
+        pixelRatio = paintDevice->devicePixelRatio();
+#endif
+    }
+#else
+    Q_UNUSED( paintDevice )
+#endif
+
+#if QT_VERSION >= 0x050000
+    if ( pixelRatio == 0.0 && qApp )
+        pixelRatio = qApp->devicePixelRatio();
+#endif
+
+    if ( pixelRatio == 0.0 )
+        pixelRatio = 1.0;
+
+    return pixelRatio;
+}
+
+/*!
+   \return A pixmap that can be used as backing store
+
+   \param widget Widget, for which the backingstore is intended
+   \param size Size of the pixmap
+ */
+QPixmap QwtPainter::backingStore( QWidget* widget, const QSize& size )
 {
     QPixmap pm;
 
-#define QWT_HIGH_DPI 1
-
-#if QT_VERSION >= 0x050000 && QWT_HIGH_DPI
-    qreal pixelRatio = 1.0;
-
-    if ( widget && widget->windowHandle() )
-    {
-#if QT_VERSION < 0x050100
-        pixelRatio = widget->windowHandle()->devicePixelRatio();
-#else
-        pixelRatio = widget->devicePixelRatio();
-#endif
-    }
-    else
-    {
-        if ( qApp )
-            pixelRatio = qApp->devicePixelRatio();
-    }
+#if QT_VERSION >= 0x050000
+    const qreal pixelRatio = QwtPainter::devicePixelRatio( widget );
 
     pm = QPixmap( size * pixelRatio );
     pm.setDevicePixelRatio( pixelRatio );
 #else
-    Q_UNUSED( widget )
     pm = QPixmap( size );
 #endif
 
-#if QT_VERSION < 0x050000
 #ifdef Q_WS_X11
     if ( widget && isX11GraphicsSystem() )
@@ -1305,8 +1532,8 @@
             pm.x11SetScreen( widget->x11Info().screen() );
     }
-#endif
+#else
+    Q_UNUSED( widget )
 #endif
 
     return pm;
 }
-
