class KURLLabel

A drop-in replacement for QLabel that displays hyperlinks. More...

Definition#include <kurllabel.h>
InheritsQLabel (qt)
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Public Slots

Signals

Protected Methods


Detailed Description

A label class that supports displaying an active hyperlink.

KURLLabel is a drop-in replacement for QLabel that handles text in a fashion similar to how an HTML widget handles hyperlinks. The text can be underlined (or not) and set to different colors. It can also "glow" (cycle colors) when the mouse passes over it.

KURLLabel also provides signals for several events, including the mouse leaving and entering the text area and all forms of mouse clicking.

A typical usage would be something like so:


     KURLLabel *address = new KURLLabel(this);
     address->setText("My homepage");
     address->setURL("http://www.home.com/~me");
     connect(address, SIGNAL(leftClickedURL(const QString&)),
                      SLOT(processMyURL(const QString&)));

In this example, the text "My homepage" would be displayed as blue, underlined text. When the mouse passed over it, it would "glow" red. When the user clicks on the text, the signal leftClickedURL() would be emitted with "http://www.home.com/~me" as its argument.

 KURLLabel (QWidget *parent=0, const char *name=0, WFlags f=0)

Constructor.

Use this exactly like you would QLabel.

KURLLabel ()

[virtual]

Destructor.

const QString  url ()

[const]

Retreive the URL.

This will be the same as text() if setURL() is not used.

Returns: The URL.

const QString  text ()

[const]

Retrieve the current text.

Returns: The current text.

Reimplemented from QLabel

const QPixmap*  pixmap ()

[const]

Retrieve the current pixmap.

Returns: The current pixmap.

Reimplemented from QLabel

QSize  sizeHint ()

[const]

Retrieve the recommended size for this label.

Reimplemented from QLabel

void  setTransparentMode (bool state)

Enable or disable "transparent mode".

If transparent mode is enabled, the label copies its own background from its parent widget so that it seems to be transparent. Transparent mode is disabled by default. Please note that the method does not repaint the widget. Changes take effect on the next repainting. Transparent widgets do not (currently) work if there is another widget (a frame, for example) layered between this widget and its parent in Z-order.

void  setGlow (bool glow = true)

[slot]

Turn on or off the "glow" feature.

When this is on, the text will switch to the selected color whenever the mouse passes over it. By default, it is @bf on.

void  setFloat (bool do_float = true)

[slot]

Turn on or off the "float" feature.

This feature is very similar to the "glow" feature in that the color of the label switches to the selected color when the cursor passes over it. In addition, underlining is turned on for as long as the mouse is overhead. Note that if "glow" and underlining are both already turned on, this feature will have no visible effect. By default, it is @bf off.

void  setUseCursor (bool use_cursor, const QCursor* cursor = 0)

[slot]

Turn on or off the custom cursor feature.

When this is on, the cursor will change to a custom cursor (default is a "pointing hand") whenever the cursor passes over the label. By default, it is @bf on.

void  setUseTips (bool tips = true)

[slot]

Turn on or off the tool tip feature.

When this is on, the URL will be displayed as a tooltip whenever the mouse passes passes over it. By default, it is @bf off.

void  setTipText (const QString& tip)

[slot]

Specifies what text to display when tooltips are turned on.

If this is not used, the tip will default to the URL.

void  setTextAlignment (TextAlignment align)

[slot]

Set the text alignment.

void  setUnderline (bool underline = true)

[slot]

Turn on or off the underlining.

When this is on, the text will be underlined. By default, it is @bf on.

void  setHighlightedColor (const QColor& highcolor)

[slot]

Set the highlight color.

This is the default foreground color (non-selected). By default, it is @bf blue.

void  setHighlightedColor (const QString& highcolor)

[slot]

This is an overloaded version for convenience.

void  setSelectedColor (const QColor& selcolor)

[slot]

Set the selected color.

This is the color the text will change to when either a mouse passes over it and "glow" mode is on or when it is selected (clicked). By default, it is @bf red.

void  setSelectedColor (const QString& selcolor)

[slot]

This is an overloaded versionfor convenience.

void  setBackgroundColor (const QColor& bgcolor)

[slot]

Set the background color.

By default, it is set to the KDE background color.

Reimplemented from QWidget

void  setBackgroundColor (const QString& bgcolor)

[slot]

This is an overloaded version for convenience.

Reimplemented from QWidget

void  setFont (const QFont& font)

[slot]

Set the font for the label.

Reimplemented from QWidget

void  setText (const QString& text)

[slot]

Set the label contents to text.

Reimplemented from QLabel

void  setPixmap (const QPixmap& pixmap)

[slot]

Set the pixmap.

Unlike QLabel, this can co-exist with setText(). It cannot be used along with setMovie(), however.

Reimplemented from QLabel

void  setAltPixmap (const QPixmap& pixmap)

[slot]

Set the "alt" pixmap.

This pixmap will be displayed when the cursor passes over the label. The effect is similar to the trick done with 'onMouseOver' in javascript.

void  setMovie (const QMovie& movie)

[slot]

Set the movie.

Cannot be used with setPixmap ()

Reimplemented from QLabel

void  setURL (const QString& url)

[slot]

Sets the URL for this label to url.

void  enteredURL (const QString& url)

[signal]

The mouse has passed over the label.

Parameters:
urlThe URL for this label.

void  enteredURL ()

[signal]

The mouse has passed over the label.

void  leftURL (const QString& url)

[signal]

The mouse is no longer over the label.

Parameters:
urlThe URL for this label.

void  leftURL ()

[signal]

The mouse is no longer over the label.

void  leftClickedURL (const QString& url)

[signal]

The user clicked the left mouse button on this label.

Parameters:
urlThe URL for this label.

void  leftClickedURL ()

[signal]

The user clicked the left mouse button on this label.

void  rightClickedURL (const QString& url)

[signal]

The user clicked the right mouse button on this label.

Parameters:
urlThe URL for this label.

void  rightClickedURL ()

[signal]

The user clicked the left mouse button on this label.

void  middleClickedURL (const QString& url)

[signal]

The user clicked the middle mouse button on this label.

Parameters:
urlThe URL for this label.

void  middleClickedURL ()

[signal]

The user clicked the left mouse button on this label.

void  drawContents (QPainter *)

[protected]

Draws the text, pixmap, and/or movie

Reimplemented from QLabel

void  timerEvent (QTimerEvent *)

[protected]

Used to "glow" the text when it is selected.

Reimplemented from QObject

void  m_enterEvent ()

[protected]

<CODE>emit</CODE>s the enteredURL signal. If glow is on, it sets the selected color.

void  m_leaveEvent ()

[protected]

<CODE>emit</CODE>s the leftURL signal. If glow is on, it sets the normal color.

void  leaveEvent (QEvent *event)

[protected]

Processes "true" leave events since mouseMoveEvent cannot

Reimplemented from QWidget

void  mouseMoveEvent (QMouseEvent *)

[protected]

Tracks if the cursor is above the text as well as the mouse state. It <CODE>emit</CODE>s either the enteredURL, leftURL, leftClickedURL, middleClickedURL, or rightClickedURL as appropriate.

Reimplemented from QWidget

void  mousePressEvent (QMouseEvent *)

[protected]

<CODE>emit</CODE>s either the leftClickedURL, rightClickedURL, or middleClickedURL signal depending on which one the user clicked. Changes the color to selected to indicate that it was selected. Starts a timer to deselect it.

Reimplemented from QWidget

void  paintEvent (QPaintEvent*)

[protected]

An overloaded repaint event that handles the background in transparent mode. It sets a background pixmap that is obtained from the widgets parent and calls the QLabel repaint handler after that.

Reimplemented from QFrame