Classes | Public Slots | Public Member Functions | Protected Member Functions | Properties

QwtTextLabel Class Reference

A Widget which displays a QwtText. More...

#include <qwt_text_label.h>

Inheritance diagram for QwtTextLabel:
Inheritance graph
[legend]
Collaboration diagram for QwtTextLabel:
Collaboration graph
[legend]

List of all members.

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 QwtTexttext () 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.

Detailed Description

A Widget which displays a QwtText.

Definition at line 25 of file qwt_text_label.h.


Constructor & Destructor Documentation

QwtTextLabel::QwtTextLabel ( QWidget *  parent = NULL ) [explicit]

Constructs an empty label.

Parameters:
parentParent 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.

Parameters:
parentParent widget
nameObject 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

Parameters:
parentParent widget
textText

Definition at line 60 of file qwt_text_label.cpp.

References text(), and QwtTextLabel::PrivateData::text.

                                                              :
    QFrame(parent)
{
    init();
    d_data->text = text;
}
QwtTextLabel::~QwtTextLabel (  ) [virtual]

Destructor.

Definition at line 68 of file qwt_text_label.cpp.

{
    delete d_data;
}

Member Function Documentation

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.

{
    d_data->text = QwtText();

    update();
    updateGeometry();
}
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().

{
    d_data->text.draw(painter, textRect);
}
int QwtTextLabel::heightForWidth ( int  width ) const [virtual]

Returns the preferred height for this widget, given the width.

Parameters:
widthWidth

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
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

Parameters:
eventPaint 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

Parameters:
indentIndentation 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().

{
    if ( indent < 0 )
        indent = 0;

    d_data->indent = indent;

    update();
    updateGeometry();
}
void QwtTextLabel::setMargin ( int  margin )

Set label's margin in pixels

Parameters:
marginMargin in pixels

Definition at line 152 of file qwt_text_label.cpp.

References margin(), and QwtTextLabel::PrivateData::margin.

Referenced by QwtLegendItem::setItemMode().

{
    d_data->margin = margin;

    update();
    updateGeometry();
}
void QwtTextLabel::setText ( const QwtText text ) [virtual, slot]

Change the label's text

Parameters:
textNew text

Reimplemented in QwtLegendItem.

Definition at line 98 of file qwt_text_label.cpp.

References text(), and QwtTextLabel::PrivateData::text.

{
    d_data->text = text;

    update();
    updateGeometry();
}
void QwtTextLabel::setText ( const QString &  text,
QwtText::TextFormat  textFormat = QwtText::AutoText 
) [slot]

Change the label's text, keeping all other QwtText attributes

Parameters:
textNew text
textFormatFormat of text
See also:
QwtText

Definition at line 86 of file qwt_text_label.cpp.

References QwtText::setText(), and QwtTextLabel::PrivateData::text.

Referenced by QwtPlotPrintFilter::reset().

{
    d_data->text.setText(text, textFormat);

    update();
    updateGeometry();
}
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
QRect QwtTextLabel::textRect (  ) const

Calculate the rect for the text in widget coordinates

Returns:
Text rect

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;
}

Property Documentation

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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines