10 #include "qwt_plot_textlabel.h" 
   11 #include "qwt_painter.h" 
   16 #include <qpaintengine.h> 
   19 static QRect qwtItemRect( 
int renderFlags,
 
   20     const QRectF& rect, 
const QSizeF& itemSize )
 
   23     if ( renderFlags & Qt::AlignLeft )
 
   27     else if ( renderFlags & Qt::AlignRight )
 
   29         x = rect.right() - itemSize.width();
 
   33         x = rect.center().x() - 0.5 * itemSize.width();
 
   37     if ( renderFlags & Qt::AlignTop )
 
   41     else if ( renderFlags & Qt::AlignBottom )
 
   43         y = rect.bottom() - itemSize.height();
 
   47         y = rect.center().y() - 0.5 * itemSize.height();
 
   50     return QRect( x, y, itemSize.width(), itemSize.height() );
 
   53 class QwtPlotTextLabel::PrivateData
 
   85     m_data = 
new PrivateData;
 
  117     if ( m_data->text != 
text )
 
  149     if ( m_data->margin != 
margin )
 
  162     return m_data->margin;
 
  178     const QRectF& canvasRect )
 const 
  183     const int m = m_data->margin;
 
  185     const QRectF rect = 
textRect( canvasRect.adjusted( m, m, -m, -m ),
 
  186         m_data->text.textSize( painter->font() ) );
 
  191         switch( painter->paintEngine()->type() )
 
  193             case QPaintEngine::Picture:
 
  194             case QPaintEngine::User: 
 
  212         if ( m_data->text.borderPen().style() != Qt::NoPen )
 
  213             pw = qMax( m_data->text.borderPen().width(), 1 );
 
  216         pixmapRect.setLeft( qwtFloor( rect.left() ) - pw );
 
  217         pixmapRect.setTop( qwtFloor( rect.top() ) - pw );
 
  218         pixmapRect.setRight( qwtCeil( rect.right() ) + pw );
 
  219         pixmapRect.setBottom( qwtCeil( rect.bottom() ) + pw );
 
  221 #if QT_VERSION >= 0x050000 
  223         const QSize scaledSize = pixmapRect.size() * pixelRatio;
 
  225         const QSize scaledSize = pixmapRect.size();
 
  228         if ( m_data->pixmap.isNull() ||
 
  229             ( scaledSize != m_data->pixmap.size() ) )
 
  231             m_data->pixmap = QPixmap( scaledSize );
 
  232 #if QT_VERSION >= 0x050000 
  233             m_data->pixmap.setDevicePixelRatio( pixelRatio );
 
  235             m_data->pixmap.fill( Qt::transparent );
 
  237             const QRect r( pw, pw,
 
  238                 pixmapRect.width() - 2 * pw, pixmapRect.height() - 2 * pw );
 
  240             QPainter pmPainter( &m_data->pixmap );
 
  241             m_data->text.draw( &pmPainter, r );
 
  244         painter->drawPixmap( pixmapRect, m_data->pixmap );
 
  248         m_data->text.draw( painter, rect );
 
  264     const QRectF& rect, 
const QSizeF& textSize )
 const 
  266     return qwtItemRect( m_data->text.renderFlags(), rect, textSize );
 
  272     m_data->pixmap = QPixmap();
 
static qreal devicePixelRatio(const QPaintDevice *)
static bool roundingAlignment()
Base class for items on the plot canvas.
void setZ(double z)
Set the z value.
void setItemAttribute(ItemAttribute, bool on=true)
@ Rtti_PlotTextLabel
For QwtPlotTextLabel.
virtual void itemChanged()
@ Legend
The item is represented on the legend.
QwtPlotTextLabel()
Constructor.
virtual ~QwtPlotTextLabel()
Destructor.
void setMargin(int margin)
void invalidateCache()
Invalidate all internal cache.
virtual void draw(QPainter *, const QwtScaleMap &, const QwtScaleMap &, const QRectF &) const override
virtual QRectF textRect(const QRectF &, const QSizeF &) const
Align the text label.
void setText(const QwtText &)
virtual int rtti() const override
A class representing a text.