Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_painter.cpp


Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (3 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_painter.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1313#include "qwt_color_map.h"
    1414#include "qwt_scale_map.h"
    15 #include <qwindowdefs.h>
     15
    1616#include <qwidget.h>
    1717#include <qframe.h>
    … …  
    2828#include <qpaintengine.h>
    2929#include <qapplication.h>
     30
     31#if QT_VERSION >= 0x060000
     32#include <qscreen.h>
     33#else
    3034#include <qdesktopwidget.h>
    31 
    32 #if QT_VERSION >= 0x050000
    33 #include <qwindow.h>
    3435#endif
    3536
    … …  
    4243#endif
    4344
    44 bool QwtPainter::d_polylineSplitting = true;
    45 bool QwtPainter::d_roundingAlignment = true;
     45#include <cstring>
     46
     47bool QwtPainter::m_polylineSplitting = true;
     48bool QwtPainter::m_roundingAlignment = true;
     49
     50static inline bool qwtIsRasterPaintEngineBuggy()
     51{
     52#if 0
     53    static int isBuggy = -1;
     54    if ( isBuggy < 0 )
     55    {
     56        // auto detect bug of the raster paint engine,
     57        // fixed with: https://codereview.qt-project.org/#/c/99456/
     58
     59        QImage image( 2, 3, QImage::Format_ARGB32 );
     60        image.fill( 0u );
     61
     62        QPolygonF p;
     63        p += QPointF(0, 1);
     64        p += QPointF(0, 0);
     65        p += QPointF(1, 0 );
     66        p += QPointF(1, 2 );
     67
     68        QPainter painter( &image );
     69        painter.drawPolyline( p );
     70        painter.end();
     71
     72        isBuggy = ( image.pixel( 1, 1 ) == 0 ) ? 1 : 0;
     73    }
     74
     75    return isBuggy == 1;
     76#endif
     77
     78#if QT_VERSION < 0x050000
     79    return true;
     80#elif QT_VERSION < 0x050100
     81    return false;
     82#elif QT_VERSION < 0x050400
     83    return true;
     84#else
     85    return false;
     86#endif
     87}
    4688
    4789static inline bool qwtIsClippingNeeded(
    48     const QPainter *painter, QRectF &clipRect )
     90    const QPainter* painter, QRectF& clipRect )
    4991{
    5092    bool doClipping = false;
    51     const QPaintEngine *pe = painter->paintEngine();
     93    const QPaintEngine* pe = painter->paintEngine();
    5294    if ( pe && pe->type() == QPaintEngine::SVG )
    5395    {
    … …  
    64106}
    65107
    66 template <class T>
    67 static inline void qwtDrawPolyline( QPainter *painter,
    68     const T *points, int pointCount, bool polylineSplitting )
     108template< class T >
     109static inline void qwtDrawPolyline( QPainter* painter,
     110    const T* points, int pointCount, bool polylineSplitting )
    69111{
    70112    bool doSplit = false;
    71113    if ( polylineSplitting )
    72114    {
    73         const QPaintEngine *pe = painter->paintEngine();
     115        const QPaintEngine* pe = painter->paintEngine();
    74116        if ( pe && pe->type() == QPaintEngine::Raster )
    75117        {
    76118            /*
    77                 The raster paint engine seems to use some algo with O(n*n).
    78                 ( Qt 4.3 is better than Qt 4.2, but remains unacceptable)
    79                 To work around this problem, we have to split the polygon into
    80                 smaller pieces.
     119               Raster paint engine is much faster when splitting
     120               the polygon, but of course we might see some issues where
     121               the pieces are joining
    81122             */
    82123            doSplit = true;
    … …  
    86127    if ( doSplit )
    87128    {
     129        QPen pen = painter->pen();
     130
    88131        const int splitSize = 6;
    89132
    90         for ( int i = 0; i < pointCount; i += splitSize )
    91         {
    92             const int n = qMin( splitSize + 1, pointCount - i );
    93             painter->drawPolyline( points + i, n );
     133        if ( pen.width() <= 1 && pen.isSolid() && qwtIsRasterPaintEngineBuggy()
     134            && !( painter->renderHints() & QPainter::Antialiasing ) )
     135        {
     136            int k = 0;
     137
     138            for ( int i = k + 1; i < pointCount; i++ )
     139            {
     140                const QPointF& p1 = points[i - 1];
     141                const QPointF& p2 = points[i];
     142
     143                const bool isBad = ( qAbs( p2.y() - p1.y() ) <= 1 )
     144                    && qAbs( p2.x() - p1.x() ) <= 1;
     145
     146                if ( isBad || ( i - k >= splitSize ) )
     147                {
     148                    painter->drawPolyline( points + k, i - k + 1 );
     149                    k = i;
     150                }
     151            }
     152
     153            painter->drawPolyline( points + k, pointCount - k );
     154        }
     155        else
     156        {
     157            for ( int i = 0; i < pointCount; i += splitSize )
     158            {
     159                const int n = qMin( splitSize + 1, pointCount - i );
     160                painter->drawPolyline( points + i, n );
     161            }
    94162        }
    95163    }
    … …  
    105173    if ( !screenResolution.isValid() )
    106174    {
    107         QDesktopWidget *desktop = QApplication::desktop();
     175        /*
     176            We might have screens with different resolutions. TODO ...
     177         */
     178#if QT_VERSION >= 0x060000
     179        QScreen* screen = QGuiApplication::primaryScreen();
     180        if ( screen )
     181        {
     182            screenResolution.setWidth( screen->logicalDotsPerInchX() );
     183            screenResolution.setHeight( screen->logicalDotsPerInchY() );
     184        }
     185#else
     186        QDesktopWidget* desktop = QApplication::desktop();
    108187        if ( desktop )
    109188        {
    … …  
    111190            screenResolution.setHeight( desktop->logicalDpiY() );
    112191        }
     192#endif
    113193    }
    114194
    … …  
    116196}
    117197
    118 static inline void qwtUnscaleFont( QPainter *painter )
     198static inline void qwtUnscaleFont( QPainter* painter )
    119199{
    120200    if ( painter->font().pixelSize() >= 0 )
    … …  
    123203    const QSize screenResolution = qwtScreenResolution();
    124204
    125     const QPaintDevice *pd = painter->device();
     205    const QPaintDevice* pd = painter->device();
    126206    if ( pd->logicalDpiX() != screenResolution.width() ||
    127207        pd->logicalDpiY() != screenResolution.height() )
    128208    {
    129         QFont pixelFont( painter->font(), QApplication::desktop() );
     209        QFont pixelFont = QwtPainter::scaledFont( painter->font() );
    130210        pixelFont.setPixelSize( QFontInfo( pixelFont ).pixelSize() );
    131211
    … …  
    135215
    136216/*!
    137   Check is the application is running with the X11 graphics system
    138   that has some special capabilities that can be used for incremental
    139   painting to a widget.
    140 
    141   \return True, when the graphics system is X11
    142 */
     217   Check is the application is running with the X11 graphics system
     218   that has some special capabilities that can be used for incremental
     219   painting to a widget.
     220
     221   \return True, when the graphics system is X11
     222 */
    143223bool QwtPainter::isX11GraphicsSystem()
    144224{
    … …  
    162242
    163243/*!
    164   Check if the painter is using a paint engine, that aligns
    165   coordinates to integers. Today these are all paint engines
    166   beside QPaintEngine::Pdf and QPaintEngine::SVG.
    167 
    168   If we have an integer based paint engine it is also
    169   checked if the painter has a transformation matrix,
    170   that rotates or scales.
    171 
    172   \param  painter Painter
    173   \return true, when the painter is aligning
    174 
    175   \sa setRoundingAlignment()
    176 */
    177 bool QwtPainter::isAligning( QPainter *painter )
     244   Check if the painter is using a paint engine, that aligns
     245   coordinates to integers. Today these are all paint engines
     246   beside QPaintEngine::Pdf and QPaintEngine::SVG.
     247
     248   If we have an integer based paint engine it is also
     249   checked if the painter has a transformation matrix,
     250   that rotates or scales.
     251
     252   \param  painter Painter
     253   \return true, when the painter is aligning
     254
     255   \sa setRoundingAlignment()
     256 */
     257bool QwtPainter::isAligning( const QPainter* painter )
    178258{
    179259    if ( painter && painter->isActive() )
    180260    {
    181         switch ( painter->paintEngine()->type() )
     261        const QPaintEngine::Type type =
     262            painter->paintEngine()->type();
     263
     264        if ( type >= QPaintEngine::User )
     265        {
     266            // we have no idea - better don't align
     267            return false;
     268        }
     269
     270        switch ( type )
    182271        {
    183272            case QPaintEngine::Pdf:
    184273            case QPaintEngine::SVG:
     274#if 0
     275            case QPaintEngine::MacPrinter:
     276#endif
    185277                return false;
    186278
    187             default:;
    188         }
    189 
    190         const QTransform &tr = painter->transform();
     279            default:
     280                break;
     281        }
     282
     283        const QTransform& tr = painter->transform();
    191284        if ( tr.isRotating() || tr.isScaling() )
    192285        {
    … …  
    200293
    201294/*!
    202   Enable whether coordinates should be rounded, before they are painted
    203   to a paint engine that floors to integer values. For other paint engines
    204   ( PDF, SVG ) this flag has no effect.
    205   QwtPainter stores this flag only, the rounding itself is done in
    206   the painting code ( f.e the plot items ).
    207 
    208   The default setting is true.
    209 
    210   \sa roundingAlignment(), isAligning()
    211 */
     295   Enable whether coordinates should be rounded, before they are painted
     296   to a paint engine that floors to integer values. For other paint engines
     297   ( PDF, SVG ) this flag has no effect.
     298   QwtPainter stores this flag only, the rounding itself is done in
     299   the painting code ( f.e the plot items ).
     300
     301   The default setting is true.
     302
     303   \sa roundingAlignment(), isAligning()
     304 */
    212305void QwtPainter::setRoundingAlignment( bool enable )
    213306{
    214     d_roundingAlignment = enable;
    215 }
    216 
    217 /*!
    218   \brief En/Disable line splitting for the raster paint engine
    219 
    220   In some Qt versions the raster paint engine paints polylines of many points
    221   much faster when they are split in smaller chunks: f.e all supported Qt versions
    222   >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2.
    223 
    224   Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... )
    225   for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked
    226   around in this mode.
    227 
    228   The default setting is true.
    229 
    230   \sa polylineSplitting()
    231 */
     307    m_roundingAlignment = enable;
     308}
     309
     310/*!
     311   \brief En/Disable line splitting for the raster paint engine
     312
     313   In some Qt versions the raster paint engine paints polylines of many points
     314   much faster when they are split in smaller chunks: f.e all supported Qt versions
     315   >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2.
     316
     317   Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... )
     318   for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked
     319   around in this mode.
     320
     321   The default setting is true.
     322
     323   \sa polylineSplitting()
     324 */
    232325void QwtPainter::setPolylineSplitting( bool enable )
    233326{
    234     d_polylineSplitting = enable;
     327    m_polylineSplitting = enable;
    235328}
    236329
    237330//! Wrapper for QPainter::drawPath()
    238 void QwtPainter::drawPath( QPainter *painter, const QPainterPath &path )
     331void QwtPainter::drawPath( QPainter* painter, const QPainterPath& path )
    239332{
    240333    painter->drawPath( path );
    … …  
    242335
    243336//! Wrapper for QPainter::drawRect()
    244 void QwtPainter::drawRect( QPainter *painter, double x, double y, double w, double h )
     337void QwtPainter::drawRect( QPainter* painter, qreal x, qreal y, qreal w, qreal h )
    245338{
    246339    drawRect( painter, QRectF( x, y, w, h ) );
    … …  
    248341
    249342//! Wrapper for QPainter::drawRect()
    250 void QwtPainter::drawRect( QPainter *painter, const QRectF &rect )
     343void QwtPainter::drawRect( QPainter* painter, const QRectF& rect )
    251344{
    252345    const QRectF r = rect;
    … …  
    277370
    278371//! Wrapper for QPainter::fillRect()
    279 void QwtPainter::fillRect( QPainter *painter,
    280     const QRectF &rect, const QBrush &brush )
     372void QwtPainter::fillRect( QPainter* painter,
     373    const QRectF& rect, const QBrush& brush )
    281374{
    282375    if ( !rect.isValid() )
    … …  
    287380
    288381    /*
    289       Performance of Qt4 is horrible for a non trivial brush. Without
    290       clipping expect minutes or hours for repainting large rectangles
    291       (might result from zooming)
    292     */
     382       Performance of Qt4 is horrible for a non trivial brush. Without
     383       clipping expect minutes or hours for repainting large rectangles
     384       (might result from zooming)
     385     */
    293386
    294387    if ( deviceClipping )
    … …  
    309402
    310403//! Wrapper for QPainter::drawPie()
    311 void QwtPainter::drawPie( QPainter *painter, const QRectF &rect,
     404void QwtPainter::drawPie( QPainter* painter, const QRectF& rect,
    312405    int a, int alen )
    313406{
    … …  
    321414
    322415//! Wrapper for QPainter::drawEllipse()
    323 void QwtPainter::drawEllipse( QPainter *painter, const QRectF &rect )
     416void QwtPainter::drawEllipse( QPainter* painter, const QRectF& rect )
    324417{
    325418    QRectF clipRect;
    … …  
    333426
    334427//! Wrapper for QPainter::drawText()
    335 void QwtPainter::drawText( QPainter *painter, double x, double y,
    336         const QString &text )
     428void QwtPainter::drawText( QPainter* painter,
     429    qreal x, qreal y, const QString& text )
    337430{
    338431    drawText( painter, QPointF( x, y ), text );
    … …  
    340433
    341434//! Wrapper for QPainter::drawText()
    342 void QwtPainter::drawText( QPainter *painter, const QPointF &pos,
    343         const QString &text )
     435void QwtPainter::drawText( QPainter* painter, const QPointF& pos,
     436    const QString& text )
    344437{
    345438    QRectF clipRect;
    … …  
    357450
    358451//! Wrapper for QPainter::drawText()
    359 void QwtPainter::drawText( QPainter *painter,
    360     double x, double y, double w, double h,
    361     int flags, const QString &text )
     452void QwtPainter::drawText( QPainter* painter,
     453    qreal x, qreal y, qreal w, qreal h,
     454    int flags, const QString& text )
    362455{
    363456    drawText( painter, QRectF( x, y, w, h ), flags, text );
    … …  
    365458
    366459//! Wrapper for QPainter::drawText()
    367 void QwtPainter::drawText( QPainter *painter, const QRectF &rect,
    368         int flags, const QString &text )
     460void QwtPainter::drawText( QPainter* painter, const QRectF& rect,
     461    int flags, const QString& text )
    369462{
    370463    painter->save();
    … …  
    377470
    378471/*!
    379   Draw a text document into a rectangle
    380 
    381   \param painter Painter
    382   \param rect Traget rectangle
    383   \param flags Alignments/Text flags, see QPainter::drawText()
    384   \param text Text document
    385 */
    386 void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
    387     int flags, const QTextDocument &text )
    388 {
    389     QTextDocument *txt = text.clone();
     472   Draw a text document into a rectangle
     473
     474   \param painter Painter
     475   \param rect Target rectangle
     476   \param flags Alignments/Text flags, see QPainter::drawText()
     477   \param text Text document
     478 */
     479void QwtPainter::drawSimpleRichText( QPainter* painter, const QRectF& rect,
     480    int flags, const QTextDocument& text )
     481{
     482    QTextDocument* txt = text.clone();
    390483
    391484    painter->save();
    … …  
    397490        const QSize res = qwtScreenResolution();
    398491
    399         const QPaintDevice *pd = painter->device();
     492        const QPaintDevice* pd = painter->device();
    400493        if ( pd->logicalDpiX() != res.width() ||
    401494            pd->logicalDpiY() != res.height() )
    402495        {
    403496            QTransform transform;
    404             transform.scale( res.width() / double( pd->logicalDpiX() ),
    405                 res.height() / double( pd->logicalDpiY() ));
     497            transform.scale( res.width() / qreal( pd->logicalDpiX() ),
     498                res.height() / qreal( pd->logicalDpiY() ) );
    406499
    407500            painter->setWorldTransform( transform, true );
    … …  
    415508    QAbstractTextDocumentLayout* layout = txt->documentLayout();
    416509
    417     const double height = layout->documentSize().height();
    418     double y = unscaledRect.y();
     510    const qreal height = layout->documentSize().height();
     511    qreal y = unscaledRect.y();
    419512    if ( flags & Qt::AlignBottom )
    420513        y += ( unscaledRect.height() - height );
    … …  
    436529
    437530//! Wrapper for QPainter::drawLine()
    438 void QwtPainter::drawLine( QPainter *painter,
    439     const QPointF &p1, const QPointF &p2 )
     531void QwtPainter::drawLine( QPainter* painter,
     532    const QPointF& p1, const QPointF& p2 )
    440533{
    441534    QRectF clipRect;
    … …  
    456549
    457550//! Wrapper for QPainter::drawPolygon()
    458 void QwtPainter::drawPolygon( QPainter *painter, const QPolygonF &polygon )
     551void QwtPainter::drawPolygon( QPainter* painter, const QPolygonF& polygon )
    459552{
    460553    QRectF clipRect;
    461554    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    462555
    463     QPolygonF cpa = polygon;
    464556    if ( deviceClipping )
    465         cpa = QwtClipper::clipPolygonF( clipRect, polygon, true );
    466 
    467     painter->drawPolygon( cpa );
     557    {
     558        painter->drawPolygon(
     559            QwtClipper::clippedPolygonF( clipRect, polygon, true ) );
     560    }
     561    else
     562    {
     563        painter->drawPolygon( polygon );
     564    }
    468565}
    469566
    470567//! Wrapper for QPainter::drawPolyline()
    471 void QwtPainter::drawPolyline( QPainter *painter, const QPolygonF &polygon )
     568void QwtPainter::drawPolyline( QPainter* painter, const QPolygonF& polygon )
    472569{
    473570    QRectF clipRect;
    474571    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    475572
    476     QPolygonF cpa = polygon;
    477573    if ( deviceClipping )
    478         cpa = QwtClipper::clipPolygonF( clipRect, cpa );
    479 
    480     qwtDrawPolyline<QPointF>( painter,
    481         cpa.constData(), cpa.size(), d_polylineSplitting );
     574    {
     575        const QPolygonF cpa = QwtClipper::clippedPolygonF( clipRect, polygon );
     576
     577        qwtDrawPolyline< QPointF >( painter,
     578            cpa.constData(), cpa.size(), m_polylineSplitting );
     579    }
     580    else
     581    {
     582        qwtDrawPolyline< QPointF >( painter,
     583            polygon.constData(), polygon.size(), m_polylineSplitting );
     584    }
    482585}
    483586
    484587//! Wrapper for QPainter::drawPolyline()
    485 void QwtPainter::drawPolyline( QPainter *painter,
    486     const QPointF *points, int pointCount )
     588void QwtPainter::drawPolyline( QPainter* painter,
     589    const QPointF* points, int pointCount )
    487590{
    488591    QRectF clipRect;
    … …  
    492595    {
    493596        QPolygonF polygon( pointCount );
    494         ::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
    495 
    496         polygon = QwtClipper::clipPolygonF( clipRect, polygon );
    497         qwtDrawPolyline<QPointF>( painter,
    498             polygon.constData(), polygon.size(), d_polylineSplitting );
     597        std::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
     598
     599        QwtClipper::clipPolygonF( clipRect, polygon );
     600        qwtDrawPolyline< QPointF >( painter,
     601            polygon.constData(), polygon.size(), m_polylineSplitting );
    499602    }
    500603    else
    501604    {
    502         qwtDrawPolyline<QPointF>( painter, points, pointCount, d_polylineSplitting );
     605        qwtDrawPolyline< QPointF >( painter, points, pointCount, m_polylineSplitting );
    503606    }
    504607}
    505608
    506609//! Wrapper for QPainter::drawPolygon()
    507 void QwtPainter::drawPolygon( QPainter *painter, const QPolygon &polygon )
     610void QwtPainter::drawPolygon( QPainter* painter, const QPolygon& polygon )
    508611{
    509612    QRectF clipRect;
    510613    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    511614
    512     QPolygon cpa = polygon;
    513615    if ( deviceClipping )
    514         cpa = QwtClipper::clipPolygon( clipRect, polygon, true );
    515 
    516     painter->drawPolygon( cpa );
     616    {
     617        painter->drawPolygon(
     618            QwtClipper::clippedPolygon( clipRect, polygon, true ) );
     619    }
     620    else
     621    {
     622        painter->drawPolygon( polygon );
     623    }
    517624}
    518625
    519626//! Wrapper for QPainter::drawPolyline()
    520 void QwtPainter::drawPolyline( QPainter *painter, const QPolygon &polygon )
     627void QwtPainter::drawPolyline( QPainter* painter, const QPolygon& polygon )
    521628{
    522629    QRectF clipRect;
    523630    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    524631
    525     QPolygon cpa = polygon;
    526632    if ( deviceClipping )
    527         cpa = QwtClipper::clipPolygon( clipRect, cpa );
    528 
    529     qwtDrawPolyline<QPoint>( painter,
    530         cpa.constData(), cpa.size(), d_polylineSplitting );
     633    {
     634        const QPolygon cpa = QwtClipper::clippedPolygon( clipRect, polygon );
     635
     636        qwtDrawPolyline< QPoint >( painter,
     637            cpa.constData(), cpa.size(), m_polylineSplitting );
     638    }
     639    else
     640    {
     641        qwtDrawPolyline< QPoint >( painter,
     642            polygon.constData(), polygon.size(), m_polylineSplitting );
     643    }
    531644}
    532645
    533646//! Wrapper for QPainter::drawPolyline()
    534 void QwtPainter::drawPolyline( QPainter *painter,
    535     const QPoint *points, int pointCount )
     647void QwtPainter::drawPolyline( QPainter* painter,
     648    const QPoint* points, int pointCount )
    536649{
    537650    QRectF clipRect;
    … …  
    541654    {
    542655        QPolygon polygon( pointCount );
    543         ::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) );
    544 
    545         polygon = QwtClipper::clipPolygon( clipRect, polygon );
    546         qwtDrawPolyline<QPoint>( painter,
    547             polygon.constData(), polygon.size(), d_polylineSplitting );
     656        std::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) );
     657
     658        QwtClipper::clipPolygon( clipRect, polygon );
     659        qwtDrawPolyline< QPoint >( painter,
     660            polygon.constData(), polygon.size(), m_polylineSplitting );
    548661    }
    549662    else
    550663    {
    551         qwtDrawPolyline<QPoint>( painter, points, pointCount, d_polylineSplitting );
     664        qwtDrawPolyline< QPoint >( painter, points, pointCount, m_polylineSplitting );
    552665    }
    553666}
    554667
    555668//! Wrapper for QPainter::drawPoint()
    556 void QwtPainter::drawPoint( QPainter *painter, const QPointF &pos )
     669void QwtPainter::drawPoint( QPainter* painter, const QPointF& pos )
    557670{
    558671    QRectF clipRect;
    … …  
    566679
    567680//! Wrapper for QPainter::drawPoint()
    568 void QwtPainter::drawPoint( QPainter *painter, const QPoint &pos )
     681void QwtPainter::drawPoint( QPainter* painter, const QPoint& pos )
    569682{
    570683    QRectF clipRect;
    … …  
    573686    if ( deviceClipping )
    574687    {
    575         const int minX = qCeil( clipRect.left() );
    576         const int maxX = qFloor( clipRect.right() );
    577         const int minY = qCeil( clipRect.top() );
    578         const int maxY = qFloor( clipRect.bottom() );
     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() );
    579692
    580693        if ( pos.x() < minX || pos.x() > maxX
    … …  
    589702
    590703//! Wrapper for QPainter::drawPoints()
    591 void QwtPainter::drawPoints( QPainter *painter,
    592     const QPoint *points, int pointCount )
     704void QwtPainter::drawPoints( QPainter* painter,
     705    const QPoint* points, int pointCount )
    593706{
    594707    QRectF clipRect;
    … …  
    597710    if ( deviceClipping )
    598711    {
    599         const int minX = qCeil( clipRect.left() );
    600         const int maxX = qFloor( clipRect.right() );
    601         const int minY = qCeil( clipRect.top() );
    602         const int maxY = qFloor( clipRect.bottom() );
     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() );
    603716
    604717        const QRect r( minX, minY, maxX - minX, maxY - minY );
    605718
    606719        QPolygon clippedPolygon( pointCount );
    607         QPoint *clippedData = clippedPolygon.data();
     720        QPoint* clippedData = clippedPolygon.data();
    608721
    609722        int numClippedPoints = 0;
    … …  
    622735
    623736//! Wrapper for QPainter::drawPoints()
    624 void QwtPainter::drawPoints( QPainter *painter,
    625     const QPointF *points, int pointCount )
     737void QwtPainter::drawPoints( QPainter* painter,
     738    const QPointF* points, int pointCount )
    626739{
    627740    QRectF clipRect;
    … …  
    631744    {
    632745        QPolygonF clippedPolygon( pointCount );
    633         QPointF *clippedData = clippedPolygon.data();
     746        QPointF* clippedData = clippedPolygon.data();
    634747
    635748        int numClippedPoints = 0;
    … …  
    648761
    649762//! Wrapper for QPainter::drawImage()
    650 void QwtPainter::drawImage( QPainter *painter,
    651     const QRectF &rect, const QImage &image )
     763void QwtPainter::drawImage( QPainter* painter,
     764    const QRectF& rect, const QImage& image )
    652765{
    653766    const QRect alignedRect = rect.toAlignedRect();
    … …  
    669782
    670783//! Wrapper for QPainter::drawPixmap()
    671 void QwtPainter::drawPixmap( QPainter *painter,
    672     const QRectF &rect, const QPixmap &pixmap )
     784void QwtPainter::drawPixmap( QPainter* painter,
     785    const QRectF& rect, const QPixmap& pixmap )
    673786{
    674787    const QRect alignedRect = rect.toAlignedRect();
    … …  
    690803
    691804//! Draw a focus rectangle on a widget using its style.
    692 void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget )
     805void QwtPainter::drawFocusRect( QPainter* painter, const QWidget* widget )
    693806{
    694807    drawFocusRect( painter, widget, widget->rect() );
    … …  
    696809
    697810//! Draw a focus rectangle on a widget using its style.
    698 void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget,
    699     const QRect &rect )
     811void QwtPainter::drawFocusRect( QPainter* painter, const QWidget* widget,
     812    const QRect& rect )
    700813{
    701814    QStyleOptionFocusRect opt;
    702     opt.init( widget );
     815    opt.initFrom( widget );
    703816    opt.rect = rect;
    704817    opt.state |= QStyle::State_HasFocus;
    … …  
    710823
    711824/*!
    712   Draw a round frame
    713 
    714   \param painter Painter
    715   \param rect Frame rectangle
    716   \param palette QPalette::WindowText is used for plain borders
     825   Draw a round frame
     826
     827   \param painter Painter
     828   \param rect Frame rectangle
     829   \param palette QPalette::WindowText is used for plain borders
    717830                 QPalette::Dark and QPalette::Light for raised
    718831                 or sunken borders
    719   \param lineWidth Line width
    720   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
    721 */
    722 void QwtPainter::drawRoundFrame( QPainter *painter,
    723     const QRectF &rect, const QPalette &palette,
     832   \param lineWidth Line width
     833   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
     834 */
     835void QwtPainter::drawRoundFrame( QPainter* painter,
     836    const QRectF& rect, const QPalette& palette,
    724837    int lineWidth, int frameStyle )
    725838{
    … …  
    732845
    733846    Style style = Plain;
    734     if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
     847    if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken )
    735848        style = Sunken;
    736     else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
     849    else if ( (frameStyle& QFrame::Raised) == QFrame::Raised )
    737850        style = Raised;
    738851
    739     const double lw2 = 0.5 * lineWidth;
     852    const qreal lw2 = 0.5 * lineWidth;
    740853    QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
    741854
    … …  
    776889
    777890/*!
    778   Draw a rectangular frame
    779 
    780   \param painter Painter
    781   \param rect Frame rectangle
    782   \param palette Palette
    783   \param foregroundRole Foreground role used for QFrame::Plain
    784   \param frameWidth Frame width
    785   \param midLineWidth Used for QFrame::Box
    786   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
    787 */
    788 void QwtPainter::drawFrame( QPainter *painter, const QRectF &rect,
    789     const QPalette &palette, QPalette::ColorRole foregroundRole,
     891   Draw a rectangular frame
     892
     893   \param painter Painter
     894   \param rect Frame rectangle
     895   \param palette Palette
     896   \param foregroundRole Foreground role used for QFrame::Plain
     897   \param frameWidth Frame width
     898   \param midLineWidth Used for QFrame::Box
     899   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
     900 */
     901void QwtPainter::drawFrame( QPainter* painter, const QRectF& rect,
     902    const QPalette& palette, QPalette::ColorRole foregroundRole,
    790903    int frameWidth, int midLineWidth, int frameStyle )
    791904{
    … …  
    882995            painter->drawPath( path5 );
    883996        }
    884 #if 0
    885         // qDrawWinPanel doesn't result in something nice
    886         // on a scalable document like PDF. Better draw a
    887         // Panel.
    888 
    889         else if ( shape == QFrame::WinPanel )
    890         {
    891             painter->setRenderHint( QPainter::NonCosmeticDefaultPen, true );
    892             qDrawWinPanel ( painter, rect.toRect(), palette,
    893                 frameStyle & QFrame::Sunken );
    894         }
    895         else if ( shape == QFrame::StyledPanel )
    896         {
    897         }
    898 #endif
    899997        else
    900998        {
    … …  
    9421040
    9431041/*!
    944   Draw a rectangular frame with rounded borders
    945 
    946   \param painter Painter
    947   \param rect Frame rectangle
    948   \param xRadius x-radius of the ellipses defining the corners
    949   \param yRadius y-radius of the ellipses defining the corners
    950   \param palette QPalette::WindowText is used for plain borders
     1042   Draw a rectangular frame with rounded borders
     1043
     1044   \param painter Painter
     1045   \param rect Frame rectangle
     1046   \param xRadius x-radius of the ellipses defining the corners
     1047   \param yRadius y-radius of the ellipses defining the corners
     1048   \param palette QPalette::WindowText is used for plain borders
    9511049                 QPalette::Dark and QPalette::Light for raised
    9521050                 or sunken borders
    953   \param lineWidth Line width
    954   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
    955 */
    956 
    957 void QwtPainter::drawRoundedFrame( QPainter *painter,
    958     const QRectF &rect, double xRadius, double yRadius,
    959     const QPalette &palette, int lineWidth, int frameStyle )
     1051   \param lineWidth Line width
     1052   \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
     1053 */
     1054
     1055void QwtPainter::drawRoundedFrame( QPainter* painter,
     1056    const QRectF& rect, qreal xRadius, qreal yRadius,
     1057    const QPalette& palette, int lineWidth, int frameStyle )
    9601058{
    9611059    painter->save();
    … …  
    9631061    painter->setBrush( Qt::NoBrush );
    9641062
    965     double lw2 = lineWidth * 0.5;
     1063    qreal lw2 = lineWidth * 0.5;
    9661064    QRectF innerRect = rect.adjusted( lw2, lw2, -lw2, -lw2 );
    9671065
    … …  
    9771075
    9781076    Style style = Plain;
    979     if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
     1077    if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken )
    9801078        style = Sunken;
    981     else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
     1079    else if ( (frameStyle& QFrame::Raised) == QFrame::Raised )
    9821080        style = Raised;
    9831081
    … …  
    9931091            pathList[ 2 * i ].moveTo(
    9941092                path.elementAt(j - 1).x, path.elementAt( j - 1 ).y
    995             );
     1093                );
    9961094
    9971095            pathList[ 2 * i ].cubicTo(
    … …  
    10021100            pathList[ 2 * i + 1 ].moveTo(
    10031101                path.elementAt(j + 2).x, path.elementAt(j + 2).y
    1004             );
     1102                );
    10051103            pathList[ 2 * i + 1 ].lineTo(
    10061104                path.elementAt(j + 3).x, path.elementAt(j + 3).y
    1007             );
     1105                );
    10081106        }
    10091107
    … …  
    10861184
    10871185/*!
    1088   Draw a color bar into a rectangle
    1089 
    1090   \param painter Painter
    1091   \param colorMap Color map
    1092   \param interval Value range
    1093   \param scaleMap Scale map
    1094   \param orientation Orientation
    1095   \param rect Traget rectangle
    1096 */
    1097 void QwtPainter::drawColorBar( QPainter *painter,
    1098         const QwtColorMap &colorMap, const QwtInterval &interval,
    1099         const QwtScaleMap &scaleMap, Qt::Orientation orientation,
    1100         const QRectF &rect )
    1101 {
    1102     QVector<QRgb> colorTable;
     1186   Draw a color bar into a rectangle
     1187
     1188   \param painter Painter
     1189   \param colorMap Color map
     1190   \param interval Value range
     1191   \param scaleMap Scale map
     1192   \param orientation Orientation
     1193   \param rect Target rectangle
     1194 */
     1195void QwtPainter::drawColorBar( QPainter* painter,
     1196    const QwtColorMap& colorMap, const QwtInterval& interval,
     1197    const QwtScaleMap& scaleMap, Qt::Orientation orientation,
     1198    const QRectF& rect )
     1199{
     1200    QVector< QRgb > colorTable;
    11031201    if ( colorMap.format() == QwtColorMap::Indexed )
    1104         colorTable = colorMap.colorTable( interval );
     1202        colorTable = colorMap.colorTable256();
    11051203
    11061204    QColor c;
    … …  
    11091207
    11101208    /*
    1111       We paint to a pixmap first to have something scalable for printing
    1112       ( f.e. in a Pdf document )
     1209       We paint to a pixmap first to have something scalable for printing
     1210       ( f.e. in a Pdf document )
    11131211     */
    11141212
    … …  
    11311229                c.setRgba( colorMap.rgb( interval, value ) );
    11321230            else
    1133                 c = colorTable[colorMap.colorIndex( interval, value )];
     1231                c = colorTable[colorMap.colorIndex( 256, interval, value )];
    11341232
    11351233            pmPainter.setPen( c );
    … …  
    11491247                c.setRgba( colorMap.rgb( interval, value ) );
    11501248            else
    1151                 c = colorTable[colorMap.colorIndex( interval, value )];
     1249                c = colorTable[colorMap.colorIndex( 256, interval, value )];
    11521250
    11531251            pmPainter.setPen( c );
    … …  
    11601258}
    11611259
    1162 static inline void qwtFillRect( const QWidget *widget, QPainter *painter,
    1163     const QRect &rect, const QBrush &brush)
     1260static inline void qwtFillRect( const QWidget* widget, QPainter* painter,
     1261    const QRect& rect, const QBrush& brush)
    11641262{
    11651263    if ( brush.style() == Qt::TexturePattern )
    … …  
    11681266
    11691267        painter->setClipRect( rect );
    1170         painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
     1268        painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft() );
    11711269
    11721270        painter->restore();
    … …  
    11891287
    11901288/*!
    1191   Fill a pixmap with the content of a widget
    1192 
    1193   In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy
    1194   for backgrounds with gradients. Thus fillPixmap() offers
    1195   an alternative implementation.
    1196 
    1197   \param widget Widget
    1198   \param pixmap Pixmap to be filled
    1199   \param offset Offset
    1200 
    1201   \sa QPixmap::fill()
    1202  */
    1203 void QwtPainter::fillPixmap( const QWidget *widget,
    1204     QPixmap &pixmap, const QPoint &offset )
     1289   Fill a pixmap with the content of a widget
     1290
     1291   In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy
     1292   for backgrounds with gradients. Thus fillPixmap() offers
     1293   an alternative implementation.
     1294
     1295   \param widget Widget
     1296   \param pixmap Pixmap to be filled
     1297   \param offset Offset
     1298
     1299   \sa QPixmap::fill()
     1300 */
     1301void QwtPainter::fillPixmap( const QWidget* widget,
     1302    QPixmap& pixmap, const QPoint& offset )
    12051303{
    12061304    const QRect rect( offset, pixmap.size() );
    … …  
    12331331
    12341332/*!
    1235   Fill rect with the background of a widget
    1236 
    1237   \param painter Painter
    1238   \param rect Rectangle to be filled
    1239   \param widget Widget
    1240 
    1241   \sa QStyle::PE_Widget, QWidget::backgroundRole()
    1242  */
    1243 void QwtPainter::drawBackgound( QPainter *painter,
    1244     const QRectF &rect, const QWidget *widget )
     1333   Fill rect with the background of a widget
     1334
     1335   \param painter Painter
     1336   \param rect Rectangle to be filled
     1337   \param widget Widget
     1338
     1339   \sa QStyle::PE_Widget, QWidget::backgroundRole()
     1340 */
     1341void QwtPainter::drawBackgound( QPainter* painter,
     1342    const QRectF& rect, const QWidget* widget )
    12451343{
    12461344    if ( widget->testAttribute( Qt::WA_StyledBackground ) )
    … …  
    12631361
    12641362/*!
    1265   \return A pixmap that can be used as backing store
    1266 
    1267   \param widget Widget, for which the backingstore is intended
    1268   \param size Size of the pixmap
    1269  */
    1270 QPixmap QwtPainter::backingStore( QWidget *widget, const QSize &size )
     1363   Distance appropriate for drawing a subsequent character after text.
     1364
     1365   \param fontMetrics Font metrics
     1366   \param text Text
     1367   \return horizontal advance in pixels
     1368 */
     1369int QwtPainter::horizontalAdvance(
     1370    const QFontMetrics& fontMetrics, const QString& text )
     1371{
     1372#if QT_VERSION >= 0x050b00
     1373    return fontMetrics.horizontalAdvance( text );
     1374#else
     1375    return fontMetrics.width( text );
     1376#endif
     1377
     1378}
     1379
     1380/*!
     1381   Distance appropriate for drawing a subsequent character after text.
     1382
     1383   \param fontMetrics Font metrics
     1384   \param text Text
     1385   \return horizontal advance in pixels
     1386 */
     1387qreal QwtPainter::horizontalAdvance(
     1388    const QFontMetricsF& fontMetrics, const QString& text )
     1389{
     1390#if QT_VERSION >= 0x050b00
     1391    return fontMetrics.horizontalAdvance( text );
     1392#else
     1393    return fontMetrics.width( text );
     1394#endif
     1395}
     1396
     1397/*!
     1398   Distance appropriate for drawing a subsequent character after ch.
     1399
     1400   \param fontMetrics Font metrics
     1401   \param ch Character
     1402   \return horizontal advance in pixels
     1403 */
     1404int QwtPainter::horizontalAdvance(
     1405    const QFontMetrics& fontMetrics, QChar ch )
     1406{
     1407#if QT_VERSION >= 0x050b00
     1408    return fontMetrics.horizontalAdvance( ch );
     1409#else
     1410    return fontMetrics.width( ch );
     1411#endif
     1412}
     1413
     1414/*!
     1415   Distance appropriate for drawing a subsequent character after ch.
     1416
     1417   \param fontMetrics Font metrics
     1418   \param ch Character
     1419   \return horizontal advance in pixels
     1420 */
     1421qreal QwtPainter::horizontalAdvance(
     1422    const QFontMetricsF& fontMetrics, QChar ch )
     1423{
     1424#if QT_VERSION >= 0x050b00
     1425    return fontMetrics.horizontalAdvance( ch );
     1426#else
     1427    return fontMetrics.width( ch );
     1428#endif
     1429}
     1430
     1431/*!
     1432   Adjust the DPI value of font according to the DPI value of the paint device
     1433
     1434   \param font Unscaled font
     1435   \param paintDevice Paint device providing a DPI value. If paintDevice == null
     1436                     the DPI value of the primary screen will be used
     1437
     1438   \return Font being adjusted to the DPI value of the paint device
     1439 */
     1440QFont QwtPainter::scaledFont( const QFont& font, const QPaintDevice* paintDevice )
     1441{
     1442    if ( paintDevice == NULL )
     1443    {
     1444#if QT_VERSION < 0x060000
     1445        paintDevice = QApplication::desktop();
     1446#else
     1447        class PaintDevice : public QPaintDevice
     1448        {
     1449            virtual QPaintEngine* paintEngine() const QWT_OVERRIDE
     1450            {
     1451                return NULL;
     1452            }
     1453
     1454            virtual int metric( PaintDeviceMetric metric ) const QWT_OVERRIDE
     1455            {
     1456                if ( metric == PdmDpiY )
     1457                {
     1458                    QScreen* screen = QGuiApplication::primaryScreen();
     1459                    if ( screen )
     1460                    {
     1461                        return screen->logicalDotsPerInchY();
     1462                    }
     1463                }
     1464
     1465                return QPaintDevice::metric( metric );
     1466            }
     1467        };
     1468
     1469        static PaintDevice dummyPaintDevice;
     1470        paintDevice = &dummyPaintDevice;
     1471#endif
     1472    }
     1473
     1474    return QFont( font, const_cast< QPaintDevice* >( paintDevice ) );
     1475}
     1476
     1477/*!
     1478   \return Pixel ratio for a paint device
     1479   \param paintDevice Paint device
     1480 */
     1481qreal QwtPainter::devicePixelRatio( const QPaintDevice* paintDevice )
     1482{
     1483    qreal pixelRatio = 0.0;
     1484
     1485#if QT_VERSION >= 0x050100
     1486    if ( paintDevice )
     1487    {
     1488#if QT_VERSION >= 0x050600
     1489        pixelRatio = paintDevice->devicePixelRatioF();
     1490#else
     1491        pixelRatio = paintDevice->devicePixelRatio();
     1492#endif
     1493    }
     1494#else
     1495    Q_UNUSED( paintDevice )
     1496#endif
     1497
     1498#if QT_VERSION >= 0x050000
     1499    if ( pixelRatio == 0.0 && qApp )
     1500        pixelRatio = qApp->devicePixelRatio();
     1501#endif
     1502
     1503    if ( pixelRatio == 0.0 )
     1504        pixelRatio = 1.0;
     1505
     1506    return pixelRatio;
     1507}
     1508
     1509/*!
     1510   \return A pixmap that can be used as backing store
     1511
     1512   \param widget Widget, for which the backingstore is intended
     1513   \param size Size of the pixmap
     1514 */
     1515QPixmap QwtPainter::backingStore( QWidget* widget, const QSize& size )
    12711516{
    12721517    QPixmap pm;
    12731518
    1274 #define QWT_HIGH_DPI 1
    1275 
    1276 #if QT_VERSION >= 0x050000 && QWT_HIGH_DPI
    1277     qreal pixelRatio = 1.0;
    1278 
    1279     if ( widget && widget->windowHandle() )
    1280     {
    1281 #if QT_VERSION < 0x050100
    1282         pixelRatio = widget->windowHandle()->devicePixelRatio();
    1283 #else
    1284         pixelRatio = widget->devicePixelRatio();
    1285 #endif
    1286     }
    1287     else
    1288     {
    1289         if ( qApp )
    1290             pixelRatio = qApp->devicePixelRatio();
    1291     }
     1519#if QT_VERSION >= 0x050000
     1520    const qreal pixelRatio = QwtPainter::devicePixelRatio( widget );
    12921521
    12931522    pm = QPixmap( size * pixelRatio );
    12941523    pm.setDevicePixelRatio( pixelRatio );
    12951524#else
    1296     Q_UNUSED( widget )
    12971525    pm = QPixmap( size );
    12981526#endif
    12991527
    1300 #if QT_VERSION < 0x050000
    13011528#ifdef Q_WS_X11
    13021529    if ( widget && isX11GraphicsSystem() )
    … …  
    13051532            pm.x11SetScreen( widget->x11Info().screen() );
    13061533    }
    1307 #endif
     1534#else
     1535    Q_UNUSED( widget )
    13081536#endif
    13091537
    13101538    return pm;
    13111539}
    1312 
Note: See TracChangeset for help on using the changeset viewer.