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

    r4271 r8127  
    1212#include "qwt_painter.h"
    1313#include "qwt_math.h"
     14#include "qwt_widget_overlay.h"
    1415#include <qapplication.h>
    1516#include <qevent.h>
     
    2223#include <qmath.h>
    2324
    24 class QwtPicker::PickerWidget: public QWidget
     25static inline QRegion qwtMaskRegion( const QRect &r, int penWidth )
     26{
     27    const int pw = qMax( penWidth, 1 );
     28    const int pw2 = penWidth / 2;
     29
     30    int x1 = r.left() - pw2;
     31    int x2 = r.right() + 1 + pw2 + ( pw % 2 );
     32
     33    int y1 = r.top() - pw2;
     34    int y2 = r.bottom() + 1 + pw2 + ( pw % 2 );
     35
     36    QRegion region;
     37
     38    region += QRect( x1, y1, x2 - x1, pw );
     39    region += QRect( x1, y1, pw, y2 - y1 );
     40    region += QRect( x1, y2 - pw, x2 - x1, pw );
     41    region += QRect( x2 - pw, y1, pw, y2 - y1 );
     42
     43    return region;
     44}
     45
     46static inline QRegion qwtMaskRegion( const QLine &l, int penWidth )
     47{
     48    const int pw = qMax( penWidth, 1 );
     49    const int pw2 = penWidth / 2;
     50
     51    QRegion region;
     52
     53    if ( l.x1() == l.x2() )
     54    {
     55        region += QRect( l.x1() - pw2, l.y1(),
     56            pw, l.y2() ).normalized();
     57    }
     58    else if ( l.y1() == l.y2() )
     59    {
     60        region += QRect( l.x1(), l.y1() - pw2,
     61            l.x2(), pw ).normalized();
     62    }
     63
     64    return region;
     65}
     66
     67class QwtPickerRubberband: public QwtWidgetOverlay
    2568{
    2669public:
    27     enum Type
    28     {
    29         RubberBand,
    30         Text
    31     };
    32 
    33     PickerWidget( QwtPicker *, QWidget *, Type );
    34     void updateMask();
    35 
    36     /*
    37        For a tracker text with a background we can use the background
    38        rect as mask. Also for "regular" Qt widgets >= 4.3.0 we
    39        don't need to mask the text anymore.
    40      */
    41     bool d_hasTextMask;
     70    QwtPickerRubberband( QwtPicker *, QWidget * );
    4271
    4372protected:
    44     virtual void paintEvent( QPaintEvent * );
     73    virtual void drawOverlay( QPainter * ) const;
     74    virtual QRegion maskHint() const;
    4575
    4676    QwtPicker *d_picker;
    47     Type d_type;
    4877};
    4978
     79class QwtPickerTracker: public QwtWidgetOverlay
     80{                                 
     81public:
     82    QwtPickerTracker( QwtPicker *, QWidget * );
     83   
     84protected:
     85    virtual void drawOverlay( QPainter * ) const;
     86    virtual QRegion maskHint() const;
     87   
     88    QwtPicker *d_picker;
     89}; 
     90
     91
    5092class QwtPicker::PrivateData
    5193{
    5294public:
     95    PrivateData():
     96        enabled( false ),
     97        stateMachine( NULL ),
     98        resizeMode( QwtPicker::Stretch ),
     99        rubberBand( QwtPicker::NoRubberBand ),
     100        trackerMode( QwtPicker::AlwaysOff ),
     101        isActive( false ),
     102        trackerPosition( -1, -1 ),
     103        mouseTracking( false ),
     104        openGL( false )
     105    {
     106    }
     107       
    53108    bool enabled;
    54109
     
    70125    bool mouseTracking; // used to save previous value
    71126
    72     /*
    73       On X11 the widget below the picker widgets gets paint events
    74       with a region that is the bounding rect of the mask, if it is complex.
    75       In case of (f.e) a CrossRubberBand and a text this creates complete
    76       repaints of the widget. So we better use two different widgets.
    77      */
    78 
    79     QPointer<PickerWidget> rubberBandWidget;
    80     QPointer<PickerWidget> trackerWidget;
     127    QPointer< QwtPickerRubberband > rubberBandOverlay;
     128    QPointer< QwtPickerTracker> trackerOverlay;
     129
     130    bool openGL;
    81131};
    82132
    83 QwtPicker::PickerWidget::PickerWidget(
    84         QwtPicker *picker, QWidget *parent, Type type ):
    85     QWidget( parent ),
    86     d_hasTextMask( false ),
    87     d_picker( picker ),
    88     d_type( type )
    89 {
    90     setAttribute( Qt::WA_TransparentForMouseEvents );
    91     setAttribute( Qt::WA_NoSystemBackground );
    92     setFocusPolicy( Qt::NoFocus );
    93 }
    94 
    95 void QwtPicker::PickerWidget::updateMask()
    96 {
    97     QRegion mask;
    98 
    99     if ( d_type == RubberBand )
    100     {
    101         QBitmap bm( width(), height() );
    102         bm.fill( Qt::color0 );
    103 
    104         QPainter painter( &bm );
    105         QPen pen = d_picker->rubberBandPen();
    106         pen.setColor( Qt::color1 );
    107         painter.setPen( pen );
    108 
    109         d_picker->drawRubberBand( &painter );
    110 
    111         mask = QRegion( bm );
    112     }
    113     if ( d_type == Text )
    114     {
    115         d_hasTextMask = parentWidget()->testAttribute( Qt::WA_PaintOnScreen );
    116 
    117         if ( d_hasTextMask )
    118         {
    119             const QwtText label = d_picker->trackerText(
    120                 d_picker->trackerPosition() );
    121 
    122             if ( label.testPaintAttribute( QwtText::PaintBackground )
    123                 && label.backgroundBrush().style() != Qt::NoBrush )
    124             {
    125                 if ( label.backgroundBrush().color().alpha() > 0 )
    126                 {
    127                     // We don't need a text mask, when we have a background
    128                     d_hasTextMask = false;
    129                 }
    130             }
    131         }
    132 
    133         if ( d_hasTextMask )
    134         {
    135             QBitmap bm( width(), height() );
    136             bm.fill( Qt::color0 );
    137 
    138             QPainter painter( &bm );
    139             painter.setFont( font() );
    140 
    141             QPen pen = d_picker->trackerPen();
    142             pen.setColor( Qt::color1 );
    143             painter.setPen( pen );
    144 
    145             d_picker->drawTracker( &painter );
    146 
    147             mask = QRegion( bm );
    148         }
    149         else
    150         {
    151             mask = d_picker->trackerRect( font() );
    152         }
    153     }
    154 
    155     QWidget *w = parentWidget();
    156     if ( w && !w->testAttribute( Qt::WA_PaintOnScreen ) )
    157     {
    158         // The parent widget gets an update for its complete rectangle
    159         // when the mask is changed in visible state.
    160         // With this hide/show we only get an update for the
    161         // previous mask.
    162 
    163         hide();
    164     }
    165     setMask( mask );
    166     setVisible( !mask.isEmpty() );
    167 }
    168 
    169 void QwtPicker::PickerWidget::paintEvent( QPaintEvent *e )
    170 {
    171     QPainter painter( this );
    172     painter.setClipRegion( e->region() );
    173 
    174     if ( d_type == RubberBand )
    175     {
    176         painter.setPen( d_picker->rubberBandPen() );
    177         d_picker->drawRubberBand( &painter );
    178     }
    179 
    180     if ( d_type == Text )
    181     {
    182         /*
    183            If we have a text mask we simply fill the region of
    184            the mask. This gives better results for antialiased fonts.
    185          */
    186         if ( d_hasTextMask )
    187         {
    188             painter.fillRect( e->rect(),
    189                 QBrush( d_picker->trackerPen().color() ) );
    190         }
    191         else
    192         {
    193             painter.setPen( d_picker->trackerPen() );
    194             d_picker->drawTracker( &painter );
    195         }
    196     }
     133QwtPickerRubberband::QwtPickerRubberband(
     134        QwtPicker *picker, QWidget *parent ):
     135    QwtWidgetOverlay( parent ),
     136    d_picker( picker )
     137{
     138    setMaskMode( QwtWidgetOverlay::MaskHint );
     139}
     140
     141QRegion QwtPickerRubberband::maskHint() const
     142{
     143    return d_picker->rubberBandMask();
     144}
     145
     146void QwtPickerRubberband::drawOverlay( QPainter *painter ) const
     147{
     148    painter->setPen( d_picker->rubberBandPen() );
     149    d_picker->drawRubberBand( painter );
     150}
     151
     152QwtPickerTracker::QwtPickerTracker(
     153        QwtPicker *picker, QWidget *parent ):
     154    QwtWidgetOverlay( parent ),
     155    d_picker( picker )
     156{
     157    setMaskMode( QwtWidgetOverlay::MaskHint );
     158}
     159
     160QRegion QwtPickerTracker::maskHint() const
     161{
     162    return d_picker->trackerRect( font() );
     163}
     164
     165void QwtPickerTracker::drawOverlay( QPainter *painter ) const
     166{
     167    painter->setPen( d_picker->trackerPen() );
     168    d_picker->drawTracker( painter );
    197169}
    198170
     
    201173
    202174  Creates an picker that is enabled, but without a state machine.
    203   rubberband and tracker are disabled.
     175  rubber band and tracker are disabled.
    204176
    205177  \param parent Parent widget, that will be observed
     
    215187  Constructor
    216188
    217   \param rubberBand Rubberband style
     189  \param rubberBand Rubber band style
    218190  \param trackerMode Tracker mode
    219191  \param parent Parent widget, that will be observed
     
    230202{
    231203    setMouseTracking( false );
     204
    232205    delete d_data->stateMachine;
    233     delete d_data->rubberBandWidget;
    234     delete d_data->trackerWidget;
     206    delete d_data->rubberBandOverlay;
     207    delete d_data->trackerOverlay;
     208
    235209    delete d_data;
    236210}
    237211
    238 //! Init the picker, used by the constructors
     212//! Initialize the picker - used by the constructors
    239213void QwtPicker::init( QWidget *parent,
    240214    RubberBand rubberBand, DisplayMode trackerMode )
     
    242216    d_data = new PrivateData;
    243217
    244     d_data->rubberBandWidget = NULL;
    245     d_data->trackerWidget = NULL;
    246 
    247218    d_data->rubberBand = rubberBand;
    248     d_data->enabled = false;
    249     d_data->resizeMode = Stretch;
    250     d_data->trackerMode = AlwaysOff;
    251     d_data->isActive = false;
    252     d_data->trackerPosition = QPoint( -1, -1 );
    253     d_data->mouseTracking = false;
    254 
    255     d_data->stateMachine = NULL;
    256219
    257220    if ( parent )
     
    260223            parent->setFocusPolicy( Qt::WheelFocus );
    261224
     225        d_data->openGL = parent->inherits( "QGLWidget" );
    262226        d_data->trackerFont = parent->font();
    263227        d_data->mouseTracking = parent->hasMouseTracking();
     228
    264229        setEnabled( true );
    265230    }
     231
    266232    setTrackerMode( trackerMode );
    267233}
     
    326292
    327293/*!
    328   Set the rubberband style
    329 
    330   \param rubberBand Rubberband style
     294  Set the rubber band style
     295
     296  \param rubberBand Rubber band style
    331297         The default value is NoRubberBand.
    332298
     
    339305
    340306/*!
    341   \return Rubberband style
     307  \return Rubber band style
    342308  \sa setRubberBand(), RubberBand, rubberBandPen()
    343309*/
     
    500466  Set the pen for the rubberband
    501467
    502   \param pen Rubberband pen
     468  \param pen Rubber band pen
    503469  \sa rubberBandPen(), setRubberBand()
    504470*/
     
    513479
    514480/*!
    515   \return Rubberband pen
     481  \return Rubber band pen
    516482  \sa setRubberBandPen(), rubberBand()
    517483*/
     
    553519
    554520/*!
    555    Draw a rubberband, depending on rubberBand()
    556 
    557    \param painter Painter, initialized with clip rect
    558 
    559    \sa rubberBand(), RubberBand
    560 */
    561 
    562 void QwtPicker::drawRubberBand( QPainter *painter ) const
    563 {
     521  Calculate the mask for the rubber band overlay
     522
     523  \return Region for the mask
     524  \sa QWidget::setMask()
     525 */
     526QRegion QwtPicker::rubberBandMask() const
     527{
     528    QRegion mask;
     529
    564530    if ( !isActive() || rubberBand() == NoRubberBand ||
    565531        rubberBandPen().style() == Qt::NoPen )
    566532    {
    567         return;
    568     }
    569 
    570     const QRect &pRect = pickRect();
     533        return mask;
     534    }
     535
    571536    const QPolygon pa = adjustedPoints( d_data->pickedPoints );
    572537
     
    583548        {
    584549            if ( pa.count() < 1 )
     550                return mask;
     551
     552            const QPoint pos = pa[0];
     553            const int pw = rubberBandPen().width();
     554
     555            const QRect pRect = pickArea().boundingRect().toRect();
     556            switch ( rubberBand() )
     557            {
     558                case VLineRubberBand:
     559                {
     560                    mask += qwtMaskRegion( QLine( pos.x(), pRect.top(),
     561                        pos.x(), pRect.bottom() ), pw );
     562                    break;
     563                }
     564                case HLineRubberBand:
     565                {
     566                    mask += qwtMaskRegion( QLine( pRect.left(), pos.y(),
     567                        pRect.right(), pos.y() ), pw );
     568                    break;
     569                }
     570                case CrossRubberBand:
     571                {
     572                    mask += qwtMaskRegion( QLine( pos.x(), pRect.top(),
     573                        pos.x(), pRect.bottom() ), pw );
     574                    mask += qwtMaskRegion( QLine( pRect.left(), pos.y(),
     575                        pRect.right(), pos.y() ), pw );
     576                    break;
     577                }
     578                default:
     579                    break;
     580            }
     581            break;
     582        }
     583        case QwtPickerMachine::RectSelection:
     584        {
     585            if ( pa.count() < 2 )
     586                return mask;
     587
     588            const int pw = rubberBandPen().width();
     589
     590            switch ( rubberBand() )
     591            {
     592                case RectRubberBand:
     593                {
     594                    const QRect r = QRect( pa.first(), pa.last() );
     595                    mask = qwtMaskRegion( r.normalized(), pw );
     596                    break;
     597                }
     598                case EllipseRubberBand:
     599                {
     600                    const QRect r = QRect( pa.first(), pa.last() );
     601                    mask += r.adjusted( -pw, -pw, pw, pw );
     602                    break;
     603                }
     604                default:
     605                    break;
     606            }
     607            break;
     608        }
     609        case QwtPickerMachine::PolygonSelection:
     610        {
     611            const int pw = rubberBandPen().width();
     612            if ( pw <= 1 )
     613            {
     614                // because of the join style we better
     615                // return a mask for a pen width <= 1 only
     616
     617                const int off = 2 * pw;
     618                const QRect r = pa.boundingRect();
     619                mask += r.adjusted( -off, -off, off, off );
     620            }
     621            break;
     622        }
     623        default:
     624            break;
     625    }
     626
     627    return mask;
     628}
     629
     630/*!
     631   Draw a rubber band, depending on rubberBand()
     632
     633   \param painter Painter, initialized with a clip region
     634
     635   \sa rubberBand(), RubberBand
     636*/
     637
     638void QwtPicker::drawRubberBand( QPainter *painter ) const
     639{
     640    if ( !isActive() || rubberBand() == NoRubberBand ||
     641        rubberBandPen().style() == Qt::NoPen )
     642    {
     643        return;
     644    }
     645
     646    const QPolygon pa = adjustedPoints( d_data->pickedPoints );
     647
     648    QwtPickerMachine::SelectionType selectionType =
     649        QwtPickerMachine::NoSelection;
     650
     651    if ( d_data->stateMachine )
     652        selectionType = d_data->stateMachine->selectionType();
     653
     654    switch ( selectionType )
     655    {
     656        case QwtPickerMachine::NoSelection:
     657        case QwtPickerMachine::PointSelection:
     658        {
     659            if ( pa.count() < 1 )
    585660                return;
    586661
    587662            const QPoint pos = pa[0];
    588663
     664            const QRect pRect = pickArea().boundingRect().toRect();
    589665            switch ( rubberBand() )
    590666            {
    591667                case VLineRubberBand:
     668                {
    592669                    QwtPainter::drawLine( painter, pos.x(),
    593670                        pRect.top(), pos.x(), pRect.bottom() );
    594671                    break;
    595 
     672                }
    596673                case HLineRubberBand:
     674                {
    597675                    QwtPainter::drawLine( painter, pRect.left(),
    598676                        pos.y(), pRect.right(), pos.y() );
    599677                    break;
    600 
     678                }
    601679                case CrossRubberBand:
     680                {
    602681                    QwtPainter::drawLine( painter, pos.x(),
    603682                        pRect.top(), pos.x(), pRect.bottom() );
     
    605684                        pos.y(), pRect.right(), pos.y() );
    606685                    break;
     686                }
    607687                default:
    608688                    break;
     
    615695                return;
    616696
    617             const QPoint p1 = pa[0];
    618             const QPoint p2 = pa[int( pa.count() - 1 )];
    619 
    620             const QRect rect = QRect( p1, p2 ).normalized();
     697            const QRect rect = QRect( pa.first(), pa.last() ).normalized();
    621698            switch ( rubberBand() )
    622699            {
    623700                case EllipseRubberBand:
     701                {
    624702                    QwtPainter::drawEllipse( painter, rect );
    625703                    break;
     704                }
    626705                case RectRubberBand:
     706                {
    627707                    QwtPainter::drawRect( painter, rect );
    628708                    break;
     709                }
    629710                default:
    630711                    break;
     
    694775    return adjusted;
    695776}\endverbatim\n
     777
     778  \param points Selected points
     779  \return Selected points unmodified
    696780*/
    697781QPolygon QwtPicker::adjustedPoints( const QPolygon &points ) const
     
    773857    textRect.moveTopLeft( QPoint( x, y ) );
    774858
    775     int right = qMin( textRect.right(), pickRect().right() - margin );
    776     int bottom = qMin( textRect.bottom(), pickRect().bottom() - margin );
     859    const QRect pickRect = pickArea().boundingRect().toRect();
     860
     861    int right = qMin( textRect.right(), pickRect.right() - margin );
     862    int bottom = qMin( textRect.bottom(), pickRect.bottom() - margin );
    777863    textRect.moveBottomRight( QPoint( right, bottom ) );
    778864
    779     int left = qMax( textRect.left(), pickRect().left() + margin );
    780     int top = qMax( textRect.top(), pickRect().top() + margin );
     865    int left = qMax( textRect.left(), pickRect.left() + margin );
     866    int top = qMax( textRect.top(), pickRect.top() + margin );
    781867    textRect.moveTopLeft( QPoint( left, top ) );
    782868
     
    787873  \brief Event filter
    788874
    789   When isEnabled() == true all events of the observed widget are filtered.
     875  When isEnabled() is true all events of the observed widget are filtered.
    790876  Mouse and keyboard events are translated into widgetMouse- and widgetKey-
    791877  and widgetWheel-events. Paint and Resize events are handled to keep
    792   rubberband and tracker up to date.
     878  rubber band and tracker up to date.
    793879
    794880  \param object Object to be filtered
    795881  \param event Event
     882
     883  \return Always false.
    796884
    797885  \sa widgetEnterEvent(), widgetLeaveEvent(),
     
    809897            case QEvent::Resize:
    810898            {
    811                 const QResizeEvent *re = ( QResizeEvent * )event;
     899                const QResizeEvent *re = static_cast<QResizeEvent *>( event );
     900
     901                /*
     902                   Adding/deleting additional event filters inside of an event filter
     903                   is not safe dues to the implementation in Qt ( changing alist while iterating ).
     904                   So we create the overlays in a way, that they don't install en event filter
     905                   ( parent set to NULL ) and do the resizing here.
     906                 */
     907                if ( d_data->trackerOverlay )
     908                    d_data->trackerOverlay->resize( re->size() );
     909
     910                if ( d_data->rubberBandOverlay )
     911                    d_data->rubberBandOverlay->resize( re->size() );
     912
    812913                if ( d_data->resizeMode == Stretch )
    813914                    stretchSelection( re->oldSize(), re->size() );
    814915
    815                 if ( d_data->rubberBandWidget )
    816                     d_data->rubberBandWidget->resize( re->size() );
    817 
    818                 if ( d_data->trackerWidget )
    819                     d_data->trackerWidget->resize( re->size() );
     916                updateDisplay();
    820917                break;
    821918            }
    822919            case QEvent::Enter:
     920            {
    823921                widgetEnterEvent( event );
    824922                break;
     923            }
    825924            case QEvent::Leave:
     925            {
    826926                widgetLeaveEvent( event );
    827927                break;
     928            }
    828929            case QEvent::MouseButtonPress:
    829                 widgetMousePressEvent( ( QMouseEvent * )event );
     930            {
     931                widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );
    830932                break;
     933            }
    831934            case QEvent::MouseButtonRelease:
    832                 widgetMouseReleaseEvent( ( QMouseEvent * )event );
     935            {
     936                widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );
    833937                break;
     938            }
    834939            case QEvent::MouseButtonDblClick:
    835                 widgetMouseDoubleClickEvent( ( QMouseEvent * )event );
     940            {
     941                widgetMouseDoubleClickEvent( static_cast<QMouseEvent *>( event ) );
    836942                break;
     943            }
    837944            case QEvent::MouseMove:
    838                 widgetMouseMoveEvent( ( QMouseEvent * )event );
     945            {
     946                widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );
    839947                break;
     948            }
    840949            case QEvent::KeyPress:
    841                 widgetKeyPressEvent( ( QKeyEvent * )event );
     950            {
     951                widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );
    842952                break;
     953            }
    843954            case QEvent::KeyRelease:
    844                 widgetKeyReleaseEvent( ( QKeyEvent * )event );
     955            {
     956                widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );
    845957                break;
     958            }
    846959            case QEvent::Wheel:
    847                 widgetWheelEvent( ( QWheelEvent * )event );
     960            {
     961                widgetWheelEvent( static_cast<QWheelEvent *>( event ) );
    848962                break;
     963            }
    849964            default:
    850965                break;
     
    879994void QwtPicker::widgetMouseMoveEvent( QMouseEvent *mouseEvent )
    880995{
    881     if ( pickRect().contains( mouseEvent->pos() ) )
     996    if ( pickArea().contains( mouseEvent->pos() ) )
    882997        d_data->trackerPosition = mouseEvent->pos();
    883998    else
     
    9231038
    9241039/*!
    925   Handle a mouse relase event for the observed widget.
     1040  Handle a mouse release event for the observed widget.
    9261041
    9271042  \param mouseEvent Mouse event
     
    9641079void QwtPicker::widgetWheelEvent( QWheelEvent *wheelEvent )
    9651080{
    966     if ( pickRect().contains( wheelEvent->pos() ) )
     1081    if ( pickArea().contains( wheelEvent->pos() ) )
    9671082        d_data->trackerPosition = wheelEvent->pos();
    9681083    else
     
    10141129    if ( dx != 0 || dy != 0 )
    10151130    {
    1016         const QRect rect = pickRect();
     1131        const QRect rect = pickArea().boundingRect().toRect();
    10171132        const QPoint pos = parentWidget()->mapFromGlobal( QCursor::pos() );
    10181133
     
    10481163  Passes an event to the state machine and executes the resulting
    10491164  commands. Append and Move commands use the current position
    1050   of the cursor (QCursor::pos()).
     1165  of the cursor ( QCursor::pos() ).
    10511166
    10521167  \param event Event
     
    11771292
    11781293/*!
    1179    Reset the state machine and terminate (end(false)) the selection
     1294   Reset the state machine and terminate ( end(false) ) the selection
    11801295*/
    11811296void QwtPicker::reset()
     
    11891304
    11901305/*!
    1191   Append a point to the selection and update rubberband and tracker.
     1306  Append a point to the selection and update rubber band and tracker.
    11921307  The appended() signal is emitted.
    11931308
     
    12591374
    12601375/*!
    1261   \brief Validate and fixup the selection
     1376  \brief Validate and fix up the selection
    12621377
    12631378  Accepts all selections unmodified
    12641379
    1265   \param selection Selection to validate and fixup
     1380  \param selection Selection to validate and fix up
    12661381  \return true, when accepted, false otherwise
    12671382*/
     
    13591474  \return parentWidget()->contentsRect()
    13601475*/
    1361 QRect QwtPicker::pickRect() const
    1362 {
     1476QPainterPath QwtPicker::pickArea() const
     1477{
     1478    QPainterPath path;
     1479
    13631480    const QWidget *widget = parentWidget();
    13641481    if ( widget )
    1365         return widget->contentsRect();
    1366 
    1367     return QRect();
    1368 }
    1369 
    1370 //! Update the state of rubberband and tracker label
     1482        path.addRect( widget->contentsRect() );
     1483
     1484    return path;
     1485}
     1486
     1487//! Update the state of rubber band and tracker label
    13711488void QwtPicker::updateDisplay()
    13721489{
     
    13751492    bool showRubberband = false;
    13761493    bool showTracker = false;
     1494
    13771495    if ( w && w->isVisible() && d_data->enabled )
    13781496    {
     
    13861504            ( trackerMode() == ActiveOnly && isActive() ) )
    13871505        {
    1388             if ( trackerPen() != Qt::NoPen )
     1506            if ( trackerPen() != Qt::NoPen
     1507                && !trackerRect( QFont() ).isEmpty() )
     1508            {
    13891509                showTracker = true;
    1390         }
    1391     }
    1392 
    1393     QPointer<PickerWidget> &rw = d_data->rubberBandWidget;
     1510            }
     1511        }
     1512    }
     1513
     1514    QPointer< QwtPickerRubberband > &rw = d_data->rubberBandOverlay;
    13941515    if ( showRubberband )
    13951516    {
    13961517        if ( rw.isNull() )
    13971518        {
    1398             rw = new PickerWidget( this, w, PickerWidget::RubberBand );
     1519            rw = new QwtPickerRubberband( this, NULL ); // NULL -> no extra event filter
     1520            rw->setObjectName( "PickerRubberBand" );
     1521            rw->setParent( w );
    13991522            rw->resize( w->size() );
    14001523        }
    1401         rw->updateMask();
    1402         rw->update(); // Needed, when the mask doesn't change
     1524
     1525        if ( d_data->rubberBand <= RectRubberBand )
     1526            rw->setMaskMode( QwtWidgetOverlay::MaskHint );
     1527        else
     1528            rw->setMaskMode( QwtWidgetOverlay::AlphaMask );
     1529
     1530        rw->updateOverlay();
    14031531    }
    14041532    else
    1405         delete rw;
    1406 
    1407     QPointer<PickerWidget> &tw = d_data->trackerWidget;
     1533    {
     1534        if ( d_data->openGL )
     1535        {
     1536            // Qt 4.8 crashes for a delete
     1537            if ( !rw.isNull() )
     1538            {
     1539                rw->hide();
     1540                rw->deleteLater();
     1541                rw = NULL;
     1542            }
     1543        }
     1544        else
     1545        {
     1546            delete rw;
     1547        }
     1548    }
     1549
     1550    QPointer< QwtPickerTracker > &tw = d_data->trackerOverlay;
    14081551    if ( showTracker )
    14091552    {
    14101553        if ( tw.isNull() )
    14111554        {
    1412             tw = new PickerWidget( this, w, PickerWidget::Text );
     1555            tw = new QwtPickerTracker( this, NULL ); // NULL -> no extra event filter
     1556            tw->setObjectName( "PickerTracker" );
     1557            tw->setParent( w );
    14131558            tw->resize( w->size() );
    14141559        }
    14151560        tw->setFont( d_data->trackerFont );
    1416         tw->updateMask();
    1417         tw->update(); // Needed, when the mask doesn't change
     1561        tw->updateOverlay();
    14181562    }
    14191563    else
    1420         delete tw;
    1421 }
    1422 
    1423 //! \return Widget displaying the rubberband
    1424 const QWidget *QwtPicker::rubberBandWidget() const
    1425 {
    1426     return d_data->rubberBandWidget;
    1427 }
    1428 
    1429 //! \return Widget displaying the tracker text
    1430 const QWidget *QwtPicker::trackerWidget() const
    1431 {
    1432     return d_data->trackerWidget;
    1433 }
    1434 
     1564    {
     1565        if ( d_data->openGL )
     1566        {
     1567            // Qt 4.8 crashes for a delete
     1568            if ( !tw.isNull() )
     1569            {
     1570                tw->hide();
     1571                tw->deleteLater();
     1572                tw = NULL;
     1573            }
     1574        }
     1575        else
     1576        {
     1577            delete tw;
     1578        }
     1579    }
     1580}
     1581
     1582//! \return Overlay displaying the rubber band
     1583const QwtWidgetOverlay *QwtPicker::rubberBandOverlay() const
     1584{
     1585    return d_data->rubberBandOverlay;
     1586}
     1587
     1588//! \return Overlay displaying the tracker text
     1589const QwtWidgetOverlay *QwtPicker::trackerOverlay() const
     1590{
     1591    return d_data->trackerOverlay;
     1592}
     1593
Note: See TracChangeset for help on using the changeset viewer.