| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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 #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 { /*BASE::virtual_hook( id, data );*/ }
    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         // jump over QTextEdit's key navigation breakage.
    00106         // we're not interested in keyboard navigation within the text
    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"

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:13 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003