Skip to content
qwt_plot_canvas.cpp 28 KiB
Newer Older
Bryant's avatar
Bryant committed
  \param painter Painter
*/
void QwtPlotCanvas::drawFocusIndicator( QPainter *painter )
{
    const int margin = 1;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    QRect focusRect = contentsRect();
    focusRect.setRect( focusRect.x() + margin, focusRect.y() + margin,
        focusRect.width() - 2 * margin, focusRect.height() - 2 * margin );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    QwtPainter::drawFocusRect( painter, this, focusRect );
}
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
/*!
   Invalidate the paint cache and repaint the canvas
   \sa invalidatePaintCache()
*/
void QwtPlotCanvas::replot()
{
    invalidateBackingStore();
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    if ( testPaintAttribute( QwtPlotCanvas::ImmediatePaint ) )
        repaint( contentsRect() );
    else
        update( contentsRect() );
}
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
//! Update the cached information about the current style sheet
void QwtPlotCanvas::updateStyleSheetInfo()
{
    if ( !testAttribute(Qt::WA_StyledBackground ) )
        return;
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
    QwtStyleSheetRecorder recorder( size() );
    
    QPainter painter( &recorder );
    
    QStyleOption opt;
    opt.initFrom(this);
    style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, this);
    
    painter.end();

    d_data->styleSheet.hasBorder = !recorder.border.rectList.isEmpty();
    d_data->styleSheet.cornerRects = recorder.clipRects;

    if ( recorder.background.path.isEmpty() )
    {
        if ( !recorder.border.rectList.isEmpty() )
        {
            d_data->styleSheet.borderPath = 
                qwtCombinePathList( rect(), recorder.border.pathList );
pixhawk's avatar
pixhawk committed
        }
Bryant's avatar
Bryant committed
    }
    else
    {
        d_data->styleSheet.borderPath = recorder.background.path;
        d_data->styleSheet.background.brush = recorder.background.brush;
        d_data->styleSheet.background.origin = recorder.background.origin;
pixhawk's avatar
pixhawk committed
    }
}

Bryant's avatar
Bryant committed
/*!
   Calculate the painter path for a styled or rounded border

   When the canvas has no styled background or rounded borders
   the painter path is empty.

   \param rect Bounding rectangle of the canvas
   \return Painter path, that can be used for clipping
*/
QPainterPath QwtPlotCanvas::borderPath( const QRect &rect ) const
pixhawk's avatar
pixhawk committed
{
Bryant's avatar
Bryant committed
    if ( testAttribute(Qt::WA_StyledBackground ) )
    {
        QwtStyleSheetRecorder recorder( rect.size() );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
        QPainter painter( &recorder );
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
        QStyleOption opt;
        opt.initFrom(this);
        opt.rect = rect;
        style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, this);
pixhawk's avatar
pixhawk committed

Bryant's avatar
Bryant committed
        painter.end();

        if ( !recorder.background.path.isEmpty() )
            return recorder.background.path;

        if ( !recorder.border.rectList.isEmpty() )
            return qwtCombinePathList( rect, recorder.border.pathList );
pixhawk's avatar
pixhawk committed
    }
Bryant's avatar
Bryant committed
    else if ( d_data->borderRadius > 0.0 )
    {
        double fw2 = frameWidth() * 0.5;
        QRectF r = QRectF(rect).adjusted( fw2, fw2, -fw2, -fw2 );

        QPainterPath path;
        path.addRoundedRect( r, d_data->borderRadius, d_data->borderRadius );
        return path;
    }
    
    return QPainterPath();
pixhawk's avatar
pixhawk committed
}