kactivelabel.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <kapplication.h>
00021 #include <qsimplerichtext.h>
00022
00023 #include "kactivelabel.h"
00024
00025 KActiveLabel::KActiveLabel(QWidget * parent, const char * name)
00026 : QTextBrowser(parent, name)
00027 {
00028 init();
00029 }
00030
00031 KActiveLabel::KActiveLabel(const QString &text, QWidget * parent, const char * name)
00032 : QTextBrowser(parent, name)
00033 {
00034 init();
00035 setText(text);
00036 }
00037
00038 void KActiveLabel::init()
00039 {
00040 setTextFormat(Qt::RichText);
00041 setVScrollBarMode(QScrollView::AlwaysOff);
00042 setHScrollBarMode(QScrollView::AlwaysOff);
00043 setFrameStyle(QFrame::NoFrame);
00044 paletteChanged();
00045
00046 connect(this, SIGNAL(linkClicked(const QString &)),
00047 this, SLOT(openLink(const QString &)));
00048 if (kapp)
00049 {
00050 connect(kapp, SIGNAL(kdisplayPaletteChanged()),
00051 this, SLOT(paletteChanged()));
00052 }
00053 }
00054
00055 void KActiveLabel::paletteChanged()
00056 {
00057 QPalette p = kapp ? kapp->palette() : palette();
00058 p.setBrush(QColorGroup::Base, p.brush(QPalette::Normal, QColorGroup::Background));
00059 p.setColor(QColorGroup::Text, p.color(QPalette::Normal, QColorGroup::Foreground));
00060 setPalette(p);
00061 }
00062
00063 void KActiveLabel::openLink(const QString & link)
00064 {
00065 QStringList args;
00066 args << "exec" << link;
00067 kapp->kdeinitExec("kfmclient", args);
00068 }
00069
00070 void KActiveLabel::virtual_hook( int, void* )
00071 { }
00072
00073 void KActiveLabel::focusInEvent( QFocusEvent* fe )
00074 {
00075 QTextBrowser::focusInEvent(fe);
00076 if(fe->reason() == QFocusEvent::Tab || fe->reason() == QFocusEvent::Backtab)
00077 selectAll(true);
00078 }
00079
00080 void KActiveLabel::focusOutEvent( QFocusEvent* fe )
00081 {
00082 QTextBrowser::focusOutEvent(fe);
00083 if(fe->reason() == QFocusEvent::Tab || fe->reason() == QFocusEvent::Backtab)
00084 selectAll(false);
00085 }
00086
00087 QSize KActiveLabel::minimumSizeHint() const
00088 {
00089 QSize ms = minimumSize();
00090 if ((ms.width() > 0) && (ms.height() > 0))
00091 return ms;
00092
00093 int w = 400;
00094 if (ms.width() > 0)
00095 w = ms.width();
00096
00097 QString txt = text();
00098 QSimpleRichText rt(txt, font());
00099 rt.setWidth(w - 2*frameWidth() - 10);
00100 w = 10 + rt.widthUsed() + 2*frameWidth();
00101 if (w < ms.width())
00102 w = ms.width();
00103 int h = rt.height() + 2*frameWidth();
00104 if ( h < ms.height())
00105 h = ms.height();
00106
00107 return QSize(w, h);
00108 }
00109
00110 QSize KActiveLabel::sizeHint() const
00111 {
00112 return minimumSizeHint();
00113 }
00114
00115 #include "kactivelabel.moc"
This file is part of the documentation for kdelibs Version 3.1.4.