A Widget which displays a QwtText. More...
#include <qwt_text_label.h>


Classes | |
| class | PrivateData |
Public Slots | |
| void | setText (const QString &, QwtText::TextFormat textFormat=QwtText::AutoText) |
| virtual void | setText (const QwtText &) |
| void | clear () |
| Clear the text and all QwtText attributes. | |
Public Member Functions | |
| QwtTextLabel (QWidget *parent=NULL) | |
| QwtTextLabel (QWidget *parent, const char *name) | |
| QwtTextLabel (const QwtText &, QWidget *parent=NULL) | |
| virtual | ~QwtTextLabel () |
| Destructor. | |
| const QwtText & | text () const |
| Return the text. | |
| int | indent () const |
| void | setIndent (int) |
| int | margin () const |
| void | setMargin (int) |
| virtual QSize | sizeHint () const |
| Return label's margin in pixels. | |
| virtual QSize | minimumSizeHint () const |
| Return a minimum size hint. | |
| virtual int | heightForWidth (int) const |
| QRect | textRect () const |
Protected Member Functions | |
| virtual void | paintEvent (QPaintEvent *e) |
| virtual void | drawContents (QPainter *) |
| Redraw the text and focus indicator. | |
| virtual void | drawText (QPainter *, const QRect &) |
| Redraw the text. | |
Properties | |
| int | indent |
| Return label's text indent in pixels. | |
| int | margin |
| Return label's text indent in pixels. | |
A Widget which displays a QwtText.
Definition at line 25 of file qwt_text_label.h.
| QwtTextLabel::QwtTextLabel | ( | QWidget * | parent = NULL ) |
[explicit] |
Constructs an empty label.
| parent | Parent widget |
Definition at line 36 of file qwt_text_label.cpp.
:
QFrame(parent)
{
init();
}
| QwtTextLabel::QwtTextLabel | ( | QWidget * | parent, |
| const char * | name | ||
| ) | [explicit] |
Constructs an empty label.
| parent | Parent widget |
| name | Object name |
Definition at line 48 of file qwt_text_label.cpp.
:
QFrame(parent, name)
{
init();
}
| QwtTextLabel::QwtTextLabel | ( | const QwtText & | text, |
| QWidget * | parent = NULL |
||
| ) | [explicit] |
Constructs a label that displays the text, text
| parent | Parent widget |
| text | Text |
Definition at line 60 of file qwt_text_label.cpp.
References text(), and QwtTextLabel::PrivateData::text.
| QwtTextLabel::~QwtTextLabel | ( | ) | [virtual] |
| void QwtTextLabel::clear | ( | ) | [slot] |
Clear the text and all QwtText attributes.
Definition at line 113 of file qwt_text_label.cpp.
References QwtTextLabel::PrivateData::text.
| void QwtTextLabel::drawContents | ( | QPainter * | painter ) | [protected, virtual] |
Redraw the text and focus indicator.
Definition at line 244 of file qwt_text_label.cpp.
References QwtPainter::drawFocusRect(), drawText(), margin(), and textRect().
Referenced by paintEvent(), and QwtLegendItem::paintEvent().
{
const QRect r = textRect();
if ( r.isEmpty() )
return;
painter->setFont(font());
#if QT_VERSION < 0x040000
painter->setPen(palette().color(QPalette::Active, QColorGroup::Text));
#else
painter->setPen(palette().color(QPalette::Active, QPalette::Text));
#endif
drawText(painter, r);
if ( hasFocus() )
{
const int margin = 2;
QRect focusRect = contentsRect();
focusRect.setRect(focusRect.x() + margin, focusRect.y() + margin,
focusRect.width() - 2 * margin - 2,
focusRect.height() - 2 * margin - 2);
QwtPainter::drawFocusRect(painter, this, focusRect);
}
}
| void QwtTextLabel::drawText | ( | QPainter * | painter, |
| const QRect & | textRect | ||
| ) | [protected, virtual] |
Redraw the text.
Reimplemented in QwtLegendItem.
Definition at line 273 of file qwt_text_label.cpp.
References QwtText::draw(), and QwtTextLabel::PrivateData::text.
Referenced by drawContents().
| int QwtTextLabel::heightForWidth | ( | int | width ) | const [virtual] |
Returns the preferred height for this widget, given the width.
| width | Width |
Definition at line 196 of file qwt_text_label.cpp.
References QwtText::heightForWidth(), QwtTextLabel::PrivateData::indent, indent(), QwtText::renderFlags(), and QwtTextLabel::PrivateData::text.
Referenced by QwtPlotLayout::minimumSizeHint().
{
const int renderFlags = d_data->text.renderFlags();
int indent = d_data->indent;
if ( indent <= 0 )
indent = defaultIndent();
width -= 2 * frameWidth();
if ( renderFlags & Qt::AlignLeft || renderFlags & Qt::AlignRight )
width -= indent;
int height = d_data->text.heightForWidth(width, font());
if ( renderFlags & Qt::AlignTop || renderFlags & Qt::AlignBottom )
height += indent;
height += 2 * frameWidth();
return height;
}
| int QwtTextLabel::indent | ( | ) | const |
Referenced by heightForWidth(), minimumSizeHint(), setIndent(), and textRect().
| int QwtTextLabel::margin | ( | ) | const |
| QSize QwtTextLabel::minimumSizeHint | ( | ) | const [virtual] |
Return a minimum size hint.
Definition at line 167 of file qwt_text_label.cpp.
References QwtTextLabel::PrivateData::indent, indent(), QwtTextLabel::PrivateData::margin, QwtText::renderFlags(), QwtTextLabel::PrivateData::text, and QwtText::textSize().
Referenced by sizeHint().
{
QSize sz = d_data->text.textSize(font());
int mw = 2 * (frameWidth() + d_data->margin);
int mh = mw;
int indent = d_data->indent;
if ( indent <= 0 )
indent = defaultIndent();
if ( indent > 0 )
{
const int align = d_data->text.renderFlags();
if ( align & Qt::AlignLeft || align & Qt::AlignRight )
mw += d_data->indent;
else if ( align & Qt::AlignTop || align & Qt::AlignBottom )
mh += d_data->indent;
}
sz += QSize(mw, mh);
return sz;
}
| void QwtTextLabel::paintEvent | ( | QPaintEvent * | event ) | [protected, virtual] |
Qt paint event
| event | Paint event |
Reimplemented in QwtLegendItem.
Definition at line 221 of file qwt_text_label.cpp.
References drawContents().
{
#if QT_VERSION >= 0x040000
QPainter painter(this);
if ( !contentsRect().contains( event->rect() ) )
{
painter.save();
painter.setClipRegion( event->region() & frameRect() );
drawFrame( &painter );
painter.restore();
}
painter.setClipRegion(event->region() & contentsRect());
drawContents( &painter );
#else // QT_VERSION < 0x040000
QFrame::paintEvent(event);
#endif
}
| void QwtTextLabel::setIndent | ( | int | indent ) |
Set label's text indent in pixels
| indent | Indentation in pixels |
Definition at line 131 of file qwt_text_label.cpp.
References indent(), and QwtTextLabel::PrivateData::indent.
Referenced by QwtLegendItem::setIdentifierWidth(), and QwtLegendItem::setSpacing().
| void QwtTextLabel::setMargin | ( | int | margin ) |
Set label's margin in pixels
| margin | Margin in pixels |
Definition at line 152 of file qwt_text_label.cpp.
References margin(), and QwtTextLabel::PrivateData::margin.
Referenced by QwtLegendItem::setItemMode().
| void QwtTextLabel::setText | ( | const QwtText & | text ) | [virtual, slot] |
Change the label's text
| text | New text |
Reimplemented in QwtLegendItem.
Definition at line 98 of file qwt_text_label.cpp.
References text(), and QwtTextLabel::PrivateData::text.
| void QwtTextLabel::setText | ( | const QString & | text, |
| QwtText::TextFormat | textFormat = QwtText::AutoText |
||
| ) | [slot] |
Change the label's text, keeping all other QwtText attributes
| text | New text |
| textFormat | Format of text |
Definition at line 86 of file qwt_text_label.cpp.
References QwtText::setText(), and QwtTextLabel::PrivateData::text.
Referenced by QwtPlotPrintFilter::reset().
| QSize QwtTextLabel::sizeHint | ( | ) | const [virtual] |
Return label's margin in pixels.
Reimplemented in QwtLegendItem.
Definition at line 161 of file qwt_text_label.cpp.
References minimumSizeHint().
{
return minimumSizeHint();
}
| const QwtText & QwtTextLabel::text | ( | ) | const |
Return the text.
Definition at line 107 of file qwt_text_label.cpp.
References QwtTextLabel::PrivateData::text.
Referenced by QwtLegendItem::drawItem(), QwtPlotLayout::LayoutData::init(), QwtPlot::print(), QwtPlot::printTitle(), QmitkHistogramWidget::QmitkHistogramWidget(), QwtTextLabel(), QwtPlotPrintFilter::reset(), setText(), and QwtLegendItem::setText().
{
return d_data->text;
}
| QRect QwtTextLabel::textRect | ( | ) | const |
Calculate the rect for the text in widget coordinates
Definition at line 282 of file qwt_text_label.cpp.
References QwtTextLabel::PrivateData::indent, indent(), QwtTextLabel::PrivateData::margin, QwtText::renderFlags(), and QwtTextLabel::PrivateData::text.
Referenced by drawContents().
{
QRect r = contentsRect();
if ( !r.isEmpty() && d_data->margin > 0 )
{
r.setRect(r.x() + d_data->margin, r.y() + d_data->margin,
r.width() - 2 * d_data->margin, r.height() - 2 * d_data->margin );
}
if ( !r.isEmpty() )
{
int indent = d_data->indent;
if ( indent <= 0 )
indent = defaultIndent();
if ( indent > 0 )
{
const int renderFlags = d_data->text.renderFlags();
if ( renderFlags & Qt::AlignLeft )
r.setX(r.x() + indent);
else if ( renderFlags & Qt::AlignRight )
r.setWidth(r.width() - indent);
else if ( renderFlags & Qt::AlignTop )
r.setY(r.y() + indent);
else if ( renderFlags & Qt::AlignBottom )
r.setHeight(r.height() - indent);
}
}
return r;
}
int QwtTextLabel::indent [read, write] |
Return label's text indent in pixels.
Definition at line 29 of file qwt_text_label.h.
int QwtTextLabel::margin [read, write] |
Return label's text indent in pixels.
Definition at line 30 of file qwt_text_label.h.
1.7.2