kactivelabel.cpp Source File (kdeui Library)

| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | 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 <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 { /*BASE::virtual_hook( id, data );*/ }
    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.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:56:11 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001