Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_panner.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_panner.cpp

    r4271 r8127  
    1111#include "qwt_scale_div.h"
    1212#include "qwt_plot.h"
    13 #include "qwt_plot_canvas.h"
     13#include "qwt_painter.h"
     14#include <qbitmap.h>
     15#include <qstyle.h>
     16#include <qstyleoption.h>
     17
     18static QBitmap qwtBorderMask( const QWidget *canvas, const QSize &size )
     19{
     20    const QRect r( 0, 0, size.width(), size.height() );
     21
     22    QPainterPath borderPath;
     23
     24    ( void )QMetaObject::invokeMethod(
     25        const_cast< QWidget *>( canvas ), "borderPath", Qt::DirectConnection,
     26        Q_RETURN_ARG( QPainterPath, borderPath ), Q_ARG( QRect, r ) );
     27
     28    if ( borderPath.isEmpty() )
     29    {
     30        if ( canvas->contentsRect() == canvas->rect() )
     31            return QBitmap();
     32
     33        QBitmap mask( size );
     34        mask.fill( Qt::color0 );
     35
     36        QPainter painter( &mask );
     37        painter.fillRect( canvas->contentsRect(), Qt::color1 );
     38
     39        return mask;
     40    }
     41
     42    QImage image( size, QImage::Format_ARGB32_Premultiplied );
     43    image.fill( Qt::color0 );
     44
     45    QPainter painter( &image );
     46    painter.setClipPath( borderPath );
     47    painter.fillRect( r, Qt::color1 );
     48
     49    // now erase the frame
     50
     51    painter.setCompositionMode( QPainter::CompositionMode_DestinationOut );
     52
     53    if ( canvas->testAttribute(Qt::WA_StyledBackground ) )
     54    {
     55        QStyleOptionFrame opt;
     56        opt.initFrom(canvas);
     57        opt.rect = r;
     58        canvas->style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, canvas );
     59    }
     60    else
     61    {
     62        const QVariant borderRadius = canvas->property( "borderRadius" );
     63        const QVariant frameWidth = canvas->property( "frameWidth" );
     64
     65        if ( borderRadius.type() == QVariant::Double
     66            && frameWidth.type() == QVariant::Int )
     67        {
     68            const double br = borderRadius.toDouble();
     69            const int fw = frameWidth.toInt();
     70       
     71            if ( br > 0.0 && fw > 0 )
     72            {
     73                painter.setPen( QPen( Qt::color1, fw ) );
     74                painter.setBrush( Qt::NoBrush );
     75                painter.setRenderHint( QPainter::Antialiasing, true );
     76
     77                painter.drawPath( borderPath );
     78            }
     79        }
     80    }
     81
     82    painter.end();
     83
     84    const QImage mask = image.createMaskFromColor(
     85        QColor( Qt::color1 ).rgb(), Qt::MaskOutColor );
     86
     87    return QBitmap::fromImage( mask );
     88}
    1489
    1590class QwtPlotPanner::PrivateData
     
    26101
    27102/*!
    28   \brief Create a plot panner
     103  \brief A panner for the canvas of a QwtPlot
    29104
    30105  The panner is enabled for all axes
     
    34109  \sa setAxisEnabled()
    35110*/
    36 QwtPlotPanner::QwtPlotPanner( QwtPlotCanvas *canvas ):
     111QwtPlotPanner::QwtPlotPanner( QWidget *canvas ):
    37112    QwtPanner( canvas )
    38113{
     
    83158
    84159//! Return observed plot canvas
    85 QwtPlotCanvas *QwtPlotPanner::canvas()
    86 {
    87     return qobject_cast<QwtPlotCanvas *>( parentWidget() );
     160QWidget *QwtPlotPanner::canvas()
     161{
     162    return parentWidget();
    88163}
    89164
    90165//! Return Observed plot canvas
    91 const QwtPlotCanvas *QwtPlotPanner::canvas() const
    92 {
    93     return qobject_cast<const QwtPlotCanvas *>( parentWidget() );
     166const QWidget *QwtPlotPanner::canvas() const
     167{
     168    return parentWidget();
    94169}
    95170
     
    97172QwtPlot *QwtPlotPanner::plot()
    98173{
    99     QwtPlotCanvas *w = canvas();
     174    QWidget *w = canvas();
    100175    if ( w )
    101         return w->plot();
    102 
    103     return NULL;
     176        w = w->parentWidget();
     177
     178    return qobject_cast<QwtPlot *>( w );
    104179}
    105180
     
    107182const QwtPlot *QwtPlotPanner::plot() const
    108183{
    109     const QwtPlotCanvas *w = canvas();
     184    const QWidget *w = canvas();
    110185    if ( w )
    111         return w->plot();
    112 
    113     return NULL;
     186        w = w->parentWidget();
     187
     188    return qobject_cast<const QwtPlot *>( w );
    114189}
    115190
     
    141216        const QwtScaleMap map = plot->canvasMap( axis );
    142217
    143         const double p1 = map.transform( plot->axisScaleDiv( axis )->lowerBound() );
    144         const double p2 = map.transform( plot->axisScaleDiv( axis )->upperBound() );
     218        const double p1 = map.transform( plot->axisScaleDiv( axis ).lowerBound() );
     219        const double p2 = map.transform( plot->axisScaleDiv( axis ).upperBound() );
    145220
    146221        double d1, d2;
     
    164239
    165240/*!
    166     Calculate a mask from the border mask of the canvas
    167     \sa QwtPlotCanvas::borderMask()
     241   Calculate a mask from the border path of the canvas
     242
     243   \return Mask as bitmap
     244   \sa QwtPlotCanvas::borderPath()
    168245*/
    169246QBitmap QwtPlotPanner::contentsMask() const
    170247{
    171248    if ( canvas() )
    172         return canvas()->borderMask( size() );
     249        return qwtBorderMask( canvas(), size() );
    173250
    174251    return QwtPanner::contentsMask();
    175252}
     253
     254/*!
     255   \return Pixmap with the content of the canvas
     256 */
     257QPixmap QwtPlotPanner::grab() const
     258{   
     259    const QWidget *cv = canvas();
     260    if ( cv && cv->inherits( "QGLWidget" ) )
     261    {
     262        // we can't grab from a QGLWidget
     263
     264        QPixmap pm( cv->size() );
     265        QwtPainter::fillPixmap( cv, pm );
     266
     267        QPainter painter( &pm );
     268        const_cast<QwtPlot *>( plot() )->drawCanvas( &painter );
     269
     270        return pm;
     271    }
     272
     273    return QwtPanner::grab();
     274}   
     275
Note: See TracChangeset for help on using the changeset viewer.