|
|
A label class that supports displaying hyperlinks
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 char*)), SLOT(processMyURL(const char*)));
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 char* url () |
Returns the URL. This will be the same as <CODE>text()</CODE> if setURL is not used.
Returns: the URL.
const char* text () |
Returns the current text.
Returns: the current text.
See also: setText
Reimplemented from QLabel
const QPixmap* pixmap () |
Returns the current pixmap.
Returns: the current pixmap.
See also: setPixmap
Reimplemented from QLabel
QSize sizeHint () |
Returns the recommended size for this label
Reimplemented from QLabel
void setTransparentMode (bool state) |
Enables or disables "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 (currently) not 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 <EM>on</EM>.
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 <EM>off</EM>.
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 <EM>on</EM>
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 <EM>off</EM>.
void setTipText (const char* tip) |
Specifies what text to display when tooltips are turned on. If this is not used, the tip will default to the URL.
See also: setUseTips
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 <EM>on</EM>
void setHighlightedColor (const QColor& highcolor) |
Set the highlight color. This is the default foreground color (non-selected). By default, it is <EM>blue</EM>.
void setHighlightedColor (const char* highcolor) |
This is an overloaded version for convenience.
See also: setHighlightedColor
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 <EM>read</EM>
void setSelectedColor (const char* selcolor) |
This is an overloaded version for convenience.
See also: setSelectedColor
void setBackgroundColor (const QColor& bgcolor) |
Set the background color. By default, it is set to the KDE background color.
Reimplemented from QWidget
void setBackgroundColor (const char* bgcolor) |
This is an overloaded version for convenience.
See also: setBackgroundColor
Reimplemented from QWidget
void setFont (const QFont& font) |
Sets the font for the label.
Reimplemented from QWidget
void setText (const char* text) |
Sets the label contents to <EM>text</EM>
See also: text
Reimplemented from QLabel
void setPixmap (const QPixmap& pixmap) |
Sets the pixmap. Unlike QLabel, this can co-exist with setText. It cannot be used along with setMovie, however.
See also: pixmap
Reimplemented from QLabel
void setAltPixmap (const QPixmap& pixmap) |
Sets 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' with javascript.
See also: altPixmap
void setMovie (const QMovie& movie) |
Sets the movie. Cannot be used with setPixmap
See also: movie
Reimplemented from QLabel
void setURL (const char* url) |
Sets the URL for this label to <EM>url</EM>
See also: url
void enteredURL (const char* 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 char* 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 char* 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 char* 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 char* 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
Reimplemented from QLabel
void timerEvent (QTimerEvent *) |
Used to "glow" the text when it is selected.
Reimplemented from QObject
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
Reimplemented from QWidget
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.
Reimplemented from QWidget
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.
Reimplemented from QWidget
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.
Reimplemented from QFrame