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
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 paletteChanged();
00048
00049 connect(
this, SIGNAL(
linkClicked(
const QString &)),
00050
this, SLOT(
openLink(
const QString &)));
00051
if (kapp)
00052 {
00053 connect(kapp, SIGNAL(kdisplayPaletteChanged()),
00054
this, SLOT(paletteChanged()));
00055 }
00056 }
00057
00058
void KActiveLabel::paletteChanged()
00059 {
00060
QPalette p = kapp ? kapp->palette() : palette();
00061 p.
setBrush(QColorGroup::Base, p.
brush(QPalette::Normal, QColorGroup::Background));
00062 p.
setColor(QColorGroup::Text, p.
color(QPalette::Normal, QColorGroup::Foreground));
00063 setPalette(p);
00064 }
00065
00066 void KActiveLabel::openLink(
const QString & link)
00067 {
00068
QRegExp whatsthis(
"whatsthis:/*([^/].*)");
00069
if (whatsthis.
exactMatch(link)) {
00070
QWhatsThis::display(whatsthis.
cap(1));
00071
return;
00072 }
00073
00074
QStringList args;
00075 args <<
"exec" << link;
00076 kapp->kdeinitExec(
"kfmclient", args);
00077 }
00078
00079
void KActiveLabel::virtual_hook(
int,
void* )
00080 { }
00081
00082
void KActiveLabel::focusInEvent(
QFocusEvent* fe )
00083 {
00084 QTextBrowser::focusInEvent(fe);
00085
if(fe->
reason() == QFocusEvent::Tab || fe->
reason() == QFocusEvent::Backtab)
00086
selectAll(
true);
00087 }
00088
00089
void KActiveLabel::focusOutEvent(
QFocusEvent* fe )
00090 {
00091 QTextBrowser::focusOutEvent(fe);
00092
if(fe->
reason() == QFocusEvent::Tab || fe->
reason() == QFocusEvent::Backtab)
00093
selectAll(
false);
00094 }
00095
00096
QSize KActiveLabel::minimumSizeHint()
const
00097
{
00098
QSize ms = minimumSize();
00099
if ((ms.
width() > 0) && (ms.
height() > 0))
00100
return ms;
00101
00102
int w = 400;
00103
if (ms.
width() > 0)
00104 w = ms.
width();
00105
00106
QString txt = text();
00107
QSimpleRichText rt(txt, font());
00108 rt.setWidth(w - 2*frameWidth() - 10);
00109 w = 10 + rt.widthUsed() + 2*frameWidth();
00110
if (w < ms.
width())
00111 w = ms.
width();
00112
int h = rt.height() + 2*frameWidth();
00113
if ( h < ms.
height())
00114 h = ms.
height();
00115
00116
return QSize(w, h);
00117 }
00118
00119
QSize KActiveLabel::sizeHint()
const
00120
{
00121
return minimumSizeHint();
00122 }
00123
00124
#include "kactivelabel.moc"