00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kactivelabel.h"
00021
00022
#include <kapplication.h>
00023
#include <qregexp.h>
00024
#include <qwhatsthis.h>
00025
#include <qsimplerichtext.h>
00026
#include <kdebug.h>
00027
00028 KActiveLabel::KActiveLabel(
QWidget * parent,
const char * name)
00029 :
QTextBrowser(parent, name)
00030 {
00031 init();
00032 }
00033
00034 KActiveLabel::KActiveLabel(
const QString &text,
QWidget * parent,
const char * name)
00035 :
QTextBrowser(parent, name)
00036 {
00037 init();
00038 setText(text);
00039 }
00040
00041
void KActiveLabel::init()
00042 {
00043 setTextFormat(Qt::RichText);
00044 setVScrollBarMode(QScrollView::AlwaysOff);
00045 setHScrollBarMode(QScrollView::AlwaysOff);
00046 setFrameStyle(QFrame::NoFrame);
00047 setFocusPolicy( QWidget::TabFocus );
00048 paletteChanged();
00049
00050 connect(
this, SIGNAL(linkClicked(
const QString &)),
00051
this, SLOT(openLink(
const QString &)));
00052
if (kapp)
00053 {
00054 connect(kapp, SIGNAL(kdisplayPaletteChanged()),
00055
this, SLOT(paletteChanged()));
00056 }
00057 }
00058
00059
void KActiveLabel::paletteChanged()
00060 {
00061
QPalette p = kapp ? kapp->palette() : palette();
00062 p.
setBrush(QColorGroup::Base, p.
brush(QPalette::Normal, QColorGroup::Background));
00063 p.
setColor(QColorGroup::Text, p.
color(QPalette::Normal, QColorGroup::Foreground));
00064 setPalette(p);
00065 }
00066
00067 void KActiveLabel::openLink(
const QString & link)
00068 {
00069
QRegExp whatsthis(
"whatsthis:/*([^/].*)");
00070
if (whatsthis.
exactMatch(link)) {
00071 QWhatsThis::display(whatsthis.
cap(1));
00072
return;
00073 }
00074
00075
QStringList args;
00076 args <<
"exec" << link;
00077 kapp->kdeinitExec(
"kfmclient", args);
00078 }
00079
00080
void KActiveLabel::virtual_hook(
int,
void* )
00081 { }
00082
00083
void KActiveLabel::focusInEvent(
QFocusEvent* fe )
00084 {
00085 QTextBrowser::focusInEvent(fe);
00086
if(fe->
reason() == QFocusEvent::Tab || fe->
reason() == QFocusEvent::Backtab)
00087
selectAll(
true);
00088 }
00089
00090
void KActiveLabel::focusOutEvent(
QFocusEvent* fe )
00091 {
00092 QTextBrowser::focusOutEvent(fe);
00093
if(fe->
reason() == QFocusEvent::Tab || fe->
reason() == QFocusEvent::Backtab)
00094
selectAll(
false);
00095 }
00096
00097
void KActiveLabel::keyPressEvent(
QKeyEvent *e )
00098 {
00099
switch ( e->
key() )
00100 {
00101
case Key_Down:
00102
case Key_Up:
00103
case Key_Left:
00104
case Key_Right:
00105
00106
00107
QWidget::keyPressEvent( e );
00108
break;
00109
default:
00110
QTextBrowser::keyPressEvent( e );
00111 }
00112 }
00113
00114
QSize KActiveLabel::minimumSizeHint()
const
00115
{
00116
QSize ms = minimumSize();
00117
if ((ms.
width() > 0) && (ms.
height() > 0))
00118
return ms;
00119
00120
int w = 400;
00121
if (ms.
width() > 0)
00122 w = ms.
width();
00123
00124
QString txt = text();
00125
QSimpleRichText rt(txt, font());
00126 rt.
setWidth(w - 2*frameWidth() - 10);
00127 w = 10 + rt.
widthUsed() + 2*frameWidth();
00128
if (w < ms.
width())
00129 w = ms.
width();
00130
int h = rt.
height() + 2*frameWidth();
00131
if ( h < ms.
height())
00132 h = ms.
height();
00133
00134
return QSize(w, h);
00135 }
00136
00137
QSize KActiveLabel::sizeHint()
const
00138
{
00139
return minimumSizeHint();
00140 }
00141
00142
#include "kactivelabel.moc"