Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_canvas.cpp


Ignore:
Timestamp:
May 10, 2017, 3:20:54 PM (7 years ago)
Author:
stoecker
Message:

update qwt and qwtpolar, many QT5 fixes (unfinished)

File:
1 edited

Legend:

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

    r4271 r8127  
    1818#include <qpaintengine.h>
    1919#include <qevent.h>
    20 #include <qbitmap.h>
    21 #ifdef Q_WS_X11
    22 #include <qx11info_x11.h>
    23 #endif
    2420
    2521class QwtStyleSheetRecorder: public QwtNullPaintDevice
     
    2723public:
    2824    QwtStyleSheetRecorder( const QSize &size ):
    29         QwtNullPaintDevice( QPaintEngine::AllFeatures )
    30     {
    31         setSize( size );
     25        d_size( size )
     26    {
    3227    }
    3328
     
    5651    virtual void drawPath( const QPainterPath &path )
    5752    {
    58         const QRectF rect( QPointF( 0.0, 0.0 ) , size() );
     53        const QRectF rect( QPointF( 0.0, 0.0 ), d_size );
    5954        if ( path.controlPointRect().contains( rect.center() ) )
    6055        {
     
    117112    }
    118113
     114protected:
     115    virtual QSize sizeMetrics() const
     116    {
     117        return d_size;
     118    }
     119
    119120private:
    120121    void alignCornerRects( const QRectF &rect )
     
    154155
    155156private:
     157    const QSize d_size;
     158
    156159    QPen d_pen;
    157160    QBrush d_brush;
     
    159162};
    160163
    161 static void qwtDrawBackground( QPainter *painter, QWidget *widget )
    162 {
     164static void qwtDrawBackground( QPainter *painter, QwtPlotCanvas *canvas )
     165{
     166    painter->save();
     167
     168    const QPainterPath borderClip = canvas->borderPath( canvas->rect() );
     169    if ( !borderClip.isEmpty() )
     170        painter->setClipPath( borderClip, Qt::IntersectClip );
     171
    163172    const QBrush &brush =
    164         widget->palette().brush( widget->backgroundRole() );
     173        canvas->palette().brush( canvas->backgroundRole() );
    165174
    166175    if ( brush.style() == Qt::TexturePattern )
    167176    {
    168         QPixmap pm( widget->size() );
    169         pm.fill( widget, 0, 0 );
     177        QPixmap pm( canvas->size() );
     178        QwtPainter::fillPixmap( canvas, pm );
    170179        painter->drawPixmap( 0, 0, pm );
    171180    }
     
    176185        if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode )
    177186        {
    178             rects += widget->rect();
     187            rects += canvas->rect();
    179188        }
    180189        else
     
    215224            }
    216225           
    217             QImage image( widget->size(), format );
     226            QImage image( canvas->size(), format );
    218227
    219228            QPainter p( &image );
     
    229238        else
    230239        {
    231             painter->save();
    232 
    233240            painter->setPen( Qt::NoPen );
    234241            painter->setBrush( brush );
    235242
    236243            painter->drawRects( rects );
    237 
    238             painter->restore();
    239244        }
    240245    }
    241246    else
    242247    {
    243         painter->save();
    244 
    245248        painter->setPen( Qt::NoPen );
    246249        painter->setBrush( brush );
     
    248251        painter->drawRects( painter->clipRegion().rects() );
    249252
    250         painter->restore();
    251     }
     253    }
     254
     255    painter->restore();
    252256}
    253257
     
    256260    if ( path.elementCount() == 4 )
    257261    {
    258         QPainterPath::Element &el0 =
    259             const_cast<QPainterPath::Element &>( path.elementAt(0) );
    260         QPainterPath::Element &el2 =
    261             const_cast<QPainterPath::Element &>( path.elementAt(3) );
    262 
    263         qSwap( el0.x, el2.x );
    264         qSwap( el0.y, el2.y );
     262        QPainterPath::Element el0 = path.elementAt(0);
     263        QPainterPath::Element el3 = path.elementAt(3);
     264
     265        path.setElementPositionAt( 0, el3.x, el3.y );
     266        path.setElementPositionAt( 3, el0.x, el0.y );
    265267    }
    266268}
     
    439441        {
    440442            QPixmap pm( rect.size() );
    441             pm.fill( bgWidget, widget->mapTo( bgWidget, rect.topLeft() ) );
     443            QwtPainter::fillPixmap( bgWidget, pm, widget->mapTo( bgWidget, rect.topLeft() ) );
    442444            painter->drawPixmap( rect, pm );
    443445        }
     
    468470        if ( radius > 0.0 )
    469471        {
    470             QSize sz( radius, radius );
     472            QSizeF sz( radius, radius );
    471473
    472474            rects += QRectF( r.topLeft(), sz );
     
    519521};
    520522
    521 //! Sets a cross cursor, enables QwtPlotCanvas::BackingStore
    522 
     523/*!
     524  \brief Constructor
     525
     526  \param plot Parent plot widget
     527  \sa QwtPlot::setCanvas()
     528*/
    523529QwtPlotCanvas::QwtPlotCanvas( QwtPlot *plot ):
    524530    QFrame( plot )
    525531{
     532    setFrameStyle( QFrame::Panel | QFrame::Sunken );
     533    setLineWidth( 2 );
     534
    526535    d_data = new PrivateData;
    527536
     
    545554QwtPlot *QwtPlotCanvas::plot()
    546555{
    547     return qobject_cast<QwtPlot *>( parentWidget() );
     556    return qobject_cast<QwtPlot *>( parent() );
    548557}
    549558
     
    551560const QwtPlot *QwtPlotCanvas::plot() const
    552561{
    553     return qobject_cast<const QwtPlot *>( parentWidget() );
     562    return qobject_cast<const QwtPlot *>( parent() );
    554563}
    555564
     
    583592                if ( isVisible() )
    584593                {
     594#if QT_VERSION >= 0x050000
     595                    *d_data->backingStore = grab( rect() );
     596#else
    585597                    *d_data->backingStore =
    586598                        QPixmap::grabWidget( this, rect() );
     599#endif
    587600                }
    588601            }
     
    610623
    611624/*!
    612   Test wether a paint attribute is enabled
     625  Test whether a paint attribute is enabled
    613626
    614627  \param attribute Paint attribute
    615   \return true if the attribute is enabled
     628  \return true, when attribute is enabled
    616629  \sa setPaintAttribute()
    617630*/
     
    676689/*!
    677690  Qt event handler for QEvent::PolishRequest and QEvent::StyleChange
     691
    678692  \param event Qt Event
     693  \return See QFrame::event()
    679694*/
    680695bool QwtPlotCanvas::event( QEvent *event )
     
    716731        if ( bs.size() != size() )
    717732        {
    718             bs = QPixmap( size() );
    719 
    720 #ifdef Q_WS_X11
    721             if ( bs.x11Info().screen() != x11Info().screen() )
    722                 bs.x11SetScreen( x11Info().screen() );
    723 #endif
     733            bs = QwtPainter::backingStore( this, size() );
    724734
    725735            if ( testAttribute(Qt::WA_StyledBackground) )
     
    734744                if ( d_data->borderRadius <= 0.0 )
    735745                {
    736                     bs.fill( this, 0, 0 );
     746                    QwtPainter::fillPixmap( this, bs );
    737747                    p.begin( &bs );
    738748                    drawCanvas( &p, false );
     
    771781            {
    772782                if ( autoFillBackground() )
     783                {
     784                    qwtFillBackground( &painter, this );
    773785                    qwtDrawBackground( &painter, this );
     786                }
     787            }
     788            else
     789            {
     790                if ( borderRadius() > 0.0 )
     791                {
     792                    QPainterPath clipPath;
     793                    clipPath.addRect( rect() );
     794                    clipPath = clipPath.subtracted( borderPath( rect() ) );
     795
     796                    painter.save();
     797
     798                    painter.setClipPath( clipPath, Qt::IntersectClip );
     799                    qwtFillBackground( &painter, this );
     800                    qwtDrawBackground( &painter, this );
     801
     802                    painter.restore();
     803                }
    774804            }
    775805
     
    838868            painter->setBrush( palette().brush( backgroundRole() ) );
    839869
    840             if ( d_data->borderRadius > 0.0 )
     870            if ( d_data->borderRadius > 0.0 && ( rect() == frameRect() ) )
    841871            {
    842872                if ( frameWidth() > 0 )
     
    853883            else
    854884            {
    855                 painter->drawRect( contentsRect() );
     885                painter->drawRect( rect() );
    856886            }
    857887        }
     
    870900    {
    871901        if ( d_data->borderRadius > 0.0 )
    872             painter->setClipPath( borderPath( rect() ), Qt::IntersectClip );
     902            painter->setClipPath( borderPath( frameRect() ), Qt::IntersectClip );
    873903        else
    874904            painter->setClipRect( contentsRect(), Qt::IntersectClip );
     
    892922
    893923  \param painter Painter
    894   \sa setBorderRadius(), QFrame::drawFrame()
     924  \sa setBorderRadius()
    895925*/
    896926void QwtPlotCanvas::drawBorder( QPainter *painter )
     
    900930        if ( frameWidth() > 0 )
    901931        {
    902             QwtPainter::drawRoundedFrame( painter, QRectF( rect() ),
     932            QwtPainter::drawRoundedFrame( painter, QRectF( frameRect() ),
    903933                d_data->borderRadius, d_data->borderRadius,
    904934                palette(), frameWidth(), frameStyle() );
     
    907937    else
    908938    {
     939#if QT_VERSION >= 0x040500
     940#if QT_VERSION < 0x050000
     941        QStyleOptionFrameV3 opt;
     942#else
     943        QStyleOptionFrame opt;
     944#endif
     945        opt.init(this);
     946
     947        int frameShape  = frameStyle() & QFrame::Shape_Mask;
     948        int frameShadow = frameStyle() & QFrame::Shadow_Mask;
     949
     950        opt.frameShape = QFrame::Shape( int( opt.frameShape ) | frameShape );
     951#if 0
     952        opt.rect = frameRect();
     953#endif
     954
     955        switch (frameShape)
     956        {
     957            case QFrame::Box:
     958            case QFrame::HLine:
     959            case QFrame::VLine:
     960            case QFrame::StyledPanel:
     961            case QFrame::Panel:
     962            {
     963                opt.lineWidth = lineWidth();
     964                opt.midLineWidth = midLineWidth();
     965                break;
     966            }
     967            default:
     968            {
     969                opt.lineWidth = frameWidth();
     970                break;
     971            }
     972        }
     973   
     974        if ( frameShadow == Sunken )
     975            opt.state |= QStyle::State_Sunken;
     976        else if ( frameShadow == Raised )
     977            opt.state |= QStyle::State_Raised;
     978
     979        style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter, this);
     980#else
    909981        drawFrame( painter );
     982#endif
    910983    }
    911984}
     
    9501023}
    9511024
    952 //! Update the cached informations about the current style sheet
     1025//! Update the cached information about the current style sheet
    9531026void QwtPlotCanvas::updateStyleSheetInfo()
    9541027{
     
    10271100    return QPainterPath();
    10281101}
    1029 
    1030 /*!
    1031    Calculate a mask, that can be used to clip away the border frame
    1032 
    1033    \param size Size including the frame
    1034 */
    1035 QBitmap QwtPlotCanvas::borderMask( const QSize &size ) const
    1036 {
    1037     const QRect r( 0, 0, size.width(), size.height() );
    1038 
    1039     const QPainterPath path = borderPath( r );
    1040     if ( path.isEmpty() )
    1041         return QBitmap();
    1042 
    1043     QImage image( size, QImage::Format_ARGB32_Premultiplied );
    1044     image.fill( Qt::color0 );
    1045 
    1046     QPainter painter( &image );
    1047     painter.setClipPath( path );
    1048     painter.fillRect( r, Qt::color1 );
    1049 
    1050     // now erase the frame
    1051 
    1052     painter.setCompositionMode( QPainter::CompositionMode_DestinationOut );
    1053 
    1054     if ( testAttribute(Qt::WA_StyledBackground ) )
    1055     {
    1056         QStyleOptionFrame opt;
    1057         opt.initFrom(this);
    1058         opt.rect = r;
    1059         style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );
    1060     }
    1061     else
    1062     {
    1063         if ( d_data->borderRadius > 0 && frameWidth() > 0 )
    1064         {
    1065             painter.setPen( QPen( Qt::color1, frameWidth() ) );
    1066             painter.setBrush( Qt::NoBrush );
    1067             painter.setRenderHint( QPainter::Antialiasing, true );
    1068 
    1069             painter.drawPath( path );
    1070         }
    1071     }
    1072 
    1073     painter.end();
    1074 
    1075     const QImage mask = image.createMaskFromColor(
    1076         QColor( Qt::color1 ).rgb(), Qt::MaskOutColor );
    1077 
    1078     return QBitmap::fromImage( mask );
    1079 }
Note: See TracChangeset for help on using the changeset viewer.