10#include "qwt_text_label.h"
12#include "qwt_painter.h"
16#include <qstyleoption.h>
21class QwtTextLabel::PrivateData
63void QwtTextLabel::init()
65 m_data =
new PrivateData();
66 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
86 return m_data->text.
text();
135 return m_data->indent;
156 return m_data->margin;
180 QSizeF sz = m_data->text.
textSize( font() );
182 const QMargins m = contentsMargins();
184 int mw = m.left() + m.right() + 2 * m_data->margin;
185 int mh = m.top() + m.bottom() + 2 * m_data->margin;
187 int indent = m_data->indent;
194 if ( align & Qt::AlignLeft || align & Qt::AlignRight )
195 mw += m_data->indent;
196 else if ( align & Qt::AlignTop || align & Qt::AlignBottom )
197 mh += m_data->indent;
200 sz += QSizeF( mw, mh );
202 return QSize( qwtCeil( sz.width() ), qwtCeil( sz.height() ) );
211 const int renderFlags = m_data->text.
renderFlags();
213 int indent = m_data->indent;
217 const QMargins m = contentsMargins();
219 width -= m.left() + m.right() - 2 * m_data->margin;
220 if ( renderFlags & Qt::AlignLeft || renderFlags & Qt::AlignRight )
223 int height = qwtCeil( m_data->text.
heightForWidth( width, font() ) );
224 if ( ( renderFlags & Qt::AlignTop ) || ( renderFlags & Qt::AlignBottom ) )
227 height += m.top() + m.bottom() + 2 * m_data->margin;
238 QPainter painter(
this );
239 painter.setClipRegion( event->region() );
243 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter,
this);
245 if ( !contentsRect().contains( event->rect() ) )
247 painter.setClipRegion( event->region() & frameRect() );
248 drawFrame( &painter );
251 painter.setClipRegion( event->region() & contentsRect() );
263 painter->setFont( font() );
264 painter->setPen( palette().color( QPalette::Active, QPalette::Text ) );
272 QRect focusRect = contentsRect().adjusted( m, m, -m + 1, -m + 1);
290 QRect r = contentsRect();
292 if ( !r.isEmpty() && m_data->margin > 0 )
294 const int m = m_data->margin;
295 r.adjust( m, m, -m, -m );
300 int indent = m_data->indent;
306 const int renderFlags = m_data->text.
renderFlags();
308 if ( renderFlags & Qt::AlignLeft )
312 else if ( renderFlags & Qt::AlignRight )
314 r.setWidth( r.width() -
indent );
316 else if ( renderFlags & Qt::AlignTop )
320 else if ( renderFlags & Qt::AlignBottom )
322 r.setHeight( r.height() -
indent );
330int QwtTextLabel::defaultIndent()
const
332 if ( frameWidth() <= 0 )
337 fnt = m_data->text.
font();
344#include "moc_qwt_text_label.cpp"
static void drawFocusRect(QPainter *, const QWidget *)
Draw a focus rectangle on a widget using its style.
static int horizontalAdvance(const QFontMetrics &, const QString &)
A class representing a text.
bool testPaintAttribute(PaintAttribute) const
QFont font() const
Return the font.
@ PaintUsingTextFont
The text has an individual font.
void setText(const QString &, QwtText::TextFormat textFormat=AutoText)
void draw(QPainter *painter, const QRectF &rect) const
double heightForWidth(double width) const
void setPlainText(const QString &)
virtual int heightForWidth(int) const override
int indent() const
Return label's text indent in pixels.
int margin() const
Return label's text margin in pixels.
const QwtText & text() const
Return the text.
virtual QSize sizeHint() const override
Return a size hint.
void clear()
Clear the text and all QwtText attributes.
QString plainText() const
virtual QSize minimumSizeHint() const override
Return a minimum size hint.
QwtTextLabel(QWidget *parent=NULL)
virtual void drawContents(QPainter *)
Redraw the text and focus indicator.
void setText(const QString &, QwtText::TextFormat textFormat=QwtText::AutoText)
virtual void paintEvent(QPaintEvent *) override
virtual ~QwtTextLabel()
Destructor.
virtual void drawText(QPainter *, const QRectF &)
Redraw the text.