Home · All Classes · Main Classes · Deprecated
Public Types | Public Slots | Signals | Public Member Functions | Properties

MLabel Class Reference

MLabel provides functionality for displaying text. More...

Inherits MWidgetController.

List of all members.

Public Types

enum  PreferredLineCountBehavior { LineCountLimitsPreferredHeight = 0, LineCountSetsPreferredHeight }

Public Slots

void setText (const QString &text)

Signals

void linkActivated (const QString &link)

Public Member Functions

 MLabel (QGraphicsItem *parent=0, MLabelModel *model=0)
 MLabel (QString const &text, QGraphicsItem *parent=0)
virtual ~MLabel ()
void setAlignment (Qt::Alignment alignment)
Qt::Alignment alignment () const
QTextOption::WrapMode wrapMode () const
void setWrapMode (QTextOption::WrapMode wrapMode)
void setWordWrap (bool wrap)
bool wordWrap () const
QString text () const
QString renderedText () const
void setTextElide (bool elide)
bool textElide () const
void setPreferredLineCount (int lineCount)
void setPreferredLineCount (int lineCount, PreferredLineCountBehavior behavior)
int preferredLineCount () const
void setFont (const QFont &font)
QFont font () const
void setColor (const QColor &color)
QColor color () const
void addHighlighter (MLabelHighlighter *highlighter)
void removeHighlighter (MLabelHighlighter *highlighter)
void removeAllHighlighters ()
void setTextFormat (Qt::TextFormat textFormat)
Qt::TextFormat textFormat () const

Properties

Qt::Alignment alignment
bool wordWrap
QTextOption::WrapMode wrapMode
bool textElide
int preferredLineCount
QString text
QString renderedText
QColor color
Qt::TextFormat textFormat

Detailed Description

MLabel provides functionality for displaying text.

Overview

MLabel provides functionality for displaying text. It can display plain text as well as rich text. The positioning of the text can be changed using setAlignment(). The appearance of the text can be tweaked using setTextDirection(), setWordWrap() and setTextElide().

Following list summarizes the functionality of MLabel:

Usage guidelines

Variants

Open issues

Examples

Simple label:

            //simple label with text
            MLabel* label = new MLabel("Simple label");

            //set/change the text of label
            label->setText("Text");

Rich label:

            //rich label with bold text.
            MLabel* label = new MLabel("Rich <b>bold</b> label");

            //manual line changes in rich label
            label->setText("row1<br><i>row2</i><br>row3");

Rich label with custom text color:

            QString styledText = "<style>red{color:#FF0000;}</style> <red>Rich</red> label can be <red>styled</red>.";
            MLabel* label = new MLabel(styledText);

Links in rich label:

            //create label with a link
            QString text = "Rich label can contain <a href=\"http://www.nokia.com\"> links </a>.";
            MLabel* label = new MLabel(styledText);

            //connect to signal to receive notification when user clicks a link in label
            connect(label, SIGNAL(linkActivated(QString)), this, SLOT(linkActivated(QString)));
See also:
MLabelModel MLabelStyle Supported HTML Subset

Member Enumeration Documentation

This enumeration is used by MLabel to indicate how preferredLineCount property affects its preferred height.

Enumerator:
LineCountLimitsPreferredHeight 

Preferred height will hold the value needed to accomodate the current text up to the number of lines defined by preferredLineCount. If the text needs more lines to be fully displayed than what preferredLineCount says, preferredHeight will still correspond to preferredLineCount.

LineCountSetsPreferredHeight 

Preferred height will correspond to the number of lines defined by preferredLineCount regardless of label's text.


Constructor & Destructor Documentation

MLabel::MLabel ( QGraphicsItem parent = 0,
MLabelModel model = 0 
)

Constructs label widget.

Parameters:
parent optional parent.
model optional model.
MLabel::MLabel ( QString const &  text,
QGraphicsItem parent = 0 
) [explicit]

Constructs a label with a text.

Parameters:
text Label text.
parent Optional parent.
MLabel::~MLabel (  )  [virtual]

Destructs label widget.


Member Function Documentation

void MLabel::addHighlighter ( MLabelHighlighter highlighter  ) 

Add highlighter object to mlabel.

Attention:
Adding a highlighter turns the label into a rich text label. This means that "\n" is interpreted as space like in HTML. Use "<br>" to force a line change.
See also:
MLabelHighlighter
Qt::Alignment MLabel::alignment (  )  const

Returns the current alignmentation.

Returns:
alignment
QColor MLabel::color (  )  const

Returns the color previously set with setColor().

Returns:
current color
QFont MLabel::font (  )  const

Return the current font.

The current font is either a font previously set with setFont() or if nothing has been manually set the one that has been defined in css for this particular label.

Overrides QGraphicsWidget::font() const.

Returns:
current font
void MLabel::linkActivated ( const QString link  )  [signal]

A signal which is emitted when an anchor in the label is clicked.

link contains the clicked link. The signal is only emitted when the link is defined using anchor "<a href=\"http://www.nokia.com"> nokia " html tag.

int MLabel::preferredLineCount (  )  const

To get the current preferredLineCount() behavior you need to:

        model()->preferredLineCountBehavior();
Returns:
Number of lines, or -1 (default) indicating that the number of lines in preferred height is not limited and neither set.
See also:
MLabel::textElide()
void MLabel::removeAllHighlighters (  ) 

Remove all highlighter objects from mlabel.

See also:
MLabelHighlighter
void MLabel::removeHighlighter ( MLabelHighlighter highlighter  ) 

Remove highlighter object from mlabel.

See also:
MLabelHighlighter
QString MLabel::renderedText (  )  const

Returns the text that is rendered on the display. The rendered text might differ from MLabel::text e.g. because the rendered text got elided or got line breaks.

Returns:
rendered text
void MLabel::setAlignment ( Qt::Alignment  alignment  ) 

Set an alignmentation for the text.

See also:
Qt::Alignment
void MLabel::setColor ( const QColor color  ) 

Set the text color for the MLabel.

By default MLabel uses color defined in the css file. This method can be used to change the color from code. Giving invalid color (QColor()) takes font in the css back to use.

void MLabel::setFont ( const QFont font  ) 

Set the font used in MLabel.

By default MLabel uses font defined in the css file. This method can be used to change the font from code.

Overrides QGraphicsWidget::setFont(const QFont &font)

void MLabel::setPreferredLineCount ( int  lineCount  ) 

Sets the preferred height returned by sizeHint() to the given number of lines of text.

Equivalent to:

Parameters:
lineCount indicates how many lines of text is preferred to be shown.

Default is -1, disabling this feature.

See also:
MLabel::textElide()
MLabel::PreferredLineCountBehavior
void MLabel::setPreferredLineCount ( int  lineCount,
PreferredLineCountBehavior  behavior 
)

Limits or sets the preferred height returned by sizeHint() to the given number of lines of text, with optional behavior.

Parameters:
lineCount indicates how many lines of text is preferred to be shown.
behavior indicates how preferredLineCount() affects the preferred height of the label.

Default is -1, disabling this feature.

See also:
MLabel::textElide()
MLabel::PreferredLineCountBehavior
void MLabel::setText ( const QString text  )  [slot]

Set text for the label.

void MLabel::setTextElide ( bool  elide  ) 

Enable/disable automatic text eliding.

If the label doesn't have enough space to show the full text on one line, the will be elided with three dots.

See also:
Qt::TextElideMode
void MLabel::setTextFormat ( Qt::TextFormat  textFormat  ) 

Set text format.

This function sets the format in which the label text is displayed. Calling this function with Qt::PlainText or Qt::RichText is used to turn off auto-recognition of text format, calling with Qt::AutoText turns auto-recognition back on.

void MLabel::setWordWrap ( bool  wrap  ) 

Enable/disable automatic word wrapping.

If true, wrapping is done according to the mode set with setWrapMode.

void MLabel::setWrapMode ( QTextOption::WrapMode  wrapMode  ) 

Set word wrapping mode.

See also:
wrapMode
QString MLabel::text (  )  const

Returns the current text.

Returns:
text
bool MLabel::textElide (  )  const

Returns the elide mode of the label.

Returns:
elide mode of the label
See also:
Qt::TextElideMode
Qt::TextFormat MLabel::textFormat (  )  const

Returns the text format.

This method returns the format in which MLabel displays its text. Note that this function does not give information about the actual format of the label text string, only about the way it is displayed.

Returns:
text format
bool MLabel::wordWrap (  )  const

Returns whether the text in label will be wrapped or not.

If the label doesn't have enough space to show the full text on one line, the text will be wrapped to multiple lines.

Returns:
wrap mode
QTextOption::WrapMode MLabel::wrapMode (  )  const

Returns wrapping mode for the text in the label.

If the label doesn't have enough space to show the full text on one line, the text will be wrapped to multiple lines if a mode with wrapping behavior is active.

Returns:
wrap mode

Property Documentation

MLabel::alignment [read, write]

Alignmentation of the label.

See MLabelModel::alignment for details.

MLabel::color [read, write]

Color of the label text.

See MLabelModel::color for details.

MLabel::preferredLineCount [read, write]

Limits the preferred height returned sizeHint() to the given number of lines of text.

Default is -1, disabling this feature.

See also:
textElide()
MLabel::renderedText [read]

Text that is rendered on the display.

See MLabel::renderedText for details.

MLabel::text [read, write]

Text of the label.

See MLabelModel::text for details.

MLabel::textElide [read, write]

Text eliding mode of the label.

See MLabelModel::textElide for details.

MLabel::textFormat [read, write]

Format the label text is displayed in.

This property is used for deciding whether a text string should be interpreted as plain text or rich text. Supported text formats are Qt::PlainText, Qt::RichText and Qt::AutoText. The default format is Qt::AutoText, which causes MLabel to guess the format of the text on a case-by-case basis.

MLabel::wordWrap [read, write]

Is word wrapping done or not.

QTextOption::WrapMode MLabel::wrapMode [read, write]

Copyright © 2010 Nokia Corporation
MeeGo Touch