|
|
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 () |
Destructor.
const QString url () |
Retreive the URL.
This will be the same as text() if setURL() is not used.
Returns: The URL.
const QString text () |
Retrieve the current text.
Returns: The current text.
const QPixmap* pixmap () |
Retrieve the current pixmap.
Returns: The current pixmap.
QSize sizeHint () |
Retrieve the recommended size for this label.
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) |
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) |
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) |
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) |
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) |
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) |
Set the text alignment.
void setUnderline (bool underline = true) |
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) |
Set the highlight color.
This is the default foreground color (non-selected). By default, it is @bf blue.
void setHighlightedColor (const QString& highcolor) |
This is an overloaded version for convenience.
void setSelectedColor (const QColor& selcolor) |
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) |
This is an overloaded versionfor convenience.
void setBackgroundColor (const QColor& bgcolor) |
Set the background color.
By default, it is set to the KDE background color.
void setBackgroundColor (const QString& bgcolor) |
This is an overloaded version for convenience.
void setFont (const QFont& font) |
Set the font for the label.
void setText (const QString& text) |
Set the label contents to text
.
void setPixmap (const QPixmap& pixmap) |
Set the pixmap.
Unlike QLabel, this can co-exist with setText(). It cannot be used along with setMovie(), however.
void setAltPixmap (const QPixmap& pixmap) |
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) |
Set the movie.
Cannot be used with setPixmap ()
void setURL (const QString& url) |
Sets the URL for this label to url
.
void enteredURL (const QString& url) |
The mouse has passed over the label.
Parameters:
url | The URL for this label. |
void enteredURL () |
The mouse has passed over the label.
void leftURL (const QString& url) |
The mouse is no longer over the label.
Parameters:
url | The URL for this label. |
void leftURL () |
The mouse is no longer over the label.
void leftClickedURL (const QString& url) |
The user clicked the left mouse button on this label.
Parameters:
url | The URL for this label. |
void leftClickedURL () |
The user clicked the left mouse button on this label.
void rightClickedURL (const QString& url) |
The user clicked the right mouse button on this label.
Parameters:
url | The URL for this label. |
void rightClickedURL () |
The user clicked the left mouse button on this label.
void middleClickedURL (const QString& url) |
The user clicked the middle mouse button on this label.
Parameters:
url | The URL for this label. |
void middleClickedURL () |
The user clicked the left mouse button on this label.
void drawContents (QPainter *) |
Draws the text, pixmap, and/or movie
void timerEvent (QTimerEvent *) |
Used to "glow" the text when it is selected.
void m_enterEvent () |
<CODE>emit</CODE>s the enteredURL signal. If glow is on, it sets the selected color.
void m_leaveEvent () |
<CODE>emit</CODE>s the leftURL signal. If glow is on, it sets the normal color.
void leaveEvent (QEvent *event) |
Processes "true" leave events since mouseMoveEvent cannot
void mouseMoveEvent (QMouseEvent *) |
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.
void mousePressEvent (QMouseEvent *) |
<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.
void paintEvent (QPaintEvent*) |
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.