示例#1
0
void QwtPlotTextLabel::draw( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect ) const
{
    Q_UNUSED( xMap );
    Q_UNUSED( yMap );

    const int m = d_data->margin;

    const QRectF adjustedRect = canvasRect.adjusted( m, m, -m, -m );

    const bool doAlign = QwtPainter::roundingAlignment( painter );

    if ( doAlign )
    {
        // when the paint device is aligning it is not one
        // where scalability matters ( PDF, SVG ).
        // As rendering a text label is an expensive operation
        // we use a cache.

        const QSize sz = d_data->text.textSize( painter->font() ).toSize();

        if ( d_data->pixmap.isNull() || sz != d_data->pixmap.size()  )
        {
            d_data->pixmap = QPixmap( sz );
            d_data->pixmap.fill( Qt::transparent );

            const QRect cacheRect( QPoint(), sz );

            QPainter pmPainter( &d_data->pixmap );
            d_data->text.draw( &pmPainter, cacheRect );
        }

        const QRect r = qwtItemRect( d_data->text.renderFlags(),
            adjustedRect.toRect(), d_data->pixmap.size() );

        painter->drawPixmap( r, d_data->pixmap );
    }
    else
    {
        d_data->text.draw( painter, adjustedRect );
    }
}
示例#2
0
/*!
   \brief Align the text label

   \param rect Canvas rectangle with margins subtracted
   \param textSize Size required to draw the text

   \return A rectangle aligned according the the alignment flags of
           the text.

   \sa setMargin(), QwtText::renderFlags(), QwtText::textSize()
 */
QRectF QwtPlotTextLabel::textRect(
    const QRectF &rect, const QSizeF &textSize ) const
{
    return qwtItemRect( d_data->text.renderFlags(), rect, textSize );
}