void QwtWidgetOverlay::updateMask()
{
    d_data->resetRgbaBuffer();

    QRegion mask;

    if ( d_data->maskMode == QwtWidgetOverlay::MaskHint )
    {
        mask = maskHint();
    }
    else if ( d_data->maskMode == QwtWidgetOverlay::AlphaMask )
    {
        // TODO: the image doesn't need to be larger than
        //       the bounding rectangle of the hint !!

        QRegion hint = maskHint();
        if ( hint.isEmpty() )
            hint += QRect( 0, 0, width(), height() );

        // A fresh buffer from calloc() is usually faster
        // than reinitializing an existing one with
        // QImage::fill( 0 ) or memset()

        d_data->rgbaBuffer = ( uchar* )::calloc( width() * height(), 4 );

        QImage image( d_data->rgbaBuffer,
            width(), height(), qwtMaskImageFormat() );

        QPainter painter( &image );
        draw( &painter );
        painter.end();

        mask = qwtAlphaMask( image, hint.rects() );

        if ( d_data->renderMode == QwtWidgetOverlay::DrawOverlay )
        {
            // we don't need the buffer later
            d_data->resetRgbaBuffer();
        }
    }

    // A bug in Qt initiates a full repaint of the widget
    // when we change the mask, while we are visible !

    setVisible( false );

    if ( mask.isEmpty() )
        clearMask();
    else
        setMask( mask );

    setVisible( true );
}
示例#2
0
void Editor::setItemVisible( QwtPlotShapeItem *item, bool on )
{
    if ( plot() == NULL || item == NULL || item->isVisible() == on )
        return;

    const bool doAutoReplot = plot()->autoReplot();
    plot()->setAutoReplot( false );

    item->setVisible( on );

    plot()->setAutoReplot( doAutoReplot );

    /*
      Avoid replot with a full repaint of the canvas. 
      For special combinations - f.e. using the 
      raster paint engine on a remote display -
      this makes a difference.
     */

    QwtPlotCanvas *canvas =
        qobject_cast<QwtPlotCanvas *>( plot()->canvas() );
    if ( canvas )
        canvas->invalidateBackingStore();

    plot()->canvas()->update( maskHint( item ) );

}
示例#3
0
QRegion Editor::maskHint() const
{
    return maskHint( d_editedItem );
}