kdeui Library API Documentation

kactivelabel.cpp

00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1999 Waldo Bastian (bastian@kde.org) 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; version 2 00007 of the License. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 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 { /*BASE::virtual_hook( id, data );*/ } 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"
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:43:26 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003