You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
3.8 KiB
143 lines
3.8 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; version 2
|
||
|
of the License.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kactivelabel.h"
|
||
|
|
||
|
#include <kapplication.h>
|
||
15 years ago
|
#include <tqregexp.h>
|
||
|
#include <tqwhatsthis.h>
|
||
|
#include <tqsimplerichtext.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
|
||
15 years ago
|
KActiveLabel::KActiveLabel(TQWidget * parent, const char * name)
|
||
|
: TQTextBrowser(parent, name)
|
||
15 years ago
|
{
|
||
|
init();
|
||
|
}
|
||
|
|
||
15 years ago
|
KActiveLabel::KActiveLabel(const TQString &text, TQWidget * parent, const char * name)
|
||
|
: TQTextBrowser(parent, name)
|
||
15 years ago
|
{
|
||
|
init();
|
||
|
setText(text);
|
||
|
}
|
||
|
|
||
|
void KActiveLabel::init()
|
||
|
{
|
||
14 years ago
|
setTextFormat(TQt::RichText);
|
||
15 years ago
|
setVScrollBarMode(TQScrollView::AlwaysOff);
|
||
|
setHScrollBarMode(TQScrollView::AlwaysOff);
|
||
|
setFrameStyle(TQFrame::NoFrame);
|
||
14 years ago
|
setFocusPolicy( TQ_TabFocus );
|
||
15 years ago
|
paletteChanged();
|
||
|
|
||
15 years ago
|
connect(this, TQT_SIGNAL(linkClicked(const TQString &)),
|
||
|
this, TQT_SLOT(openLink(const TQString &)));
|
||
15 years ago
|
if (kapp)
|
||
|
{
|
||
15 years ago
|
connect(kapp, TQT_SIGNAL(kdisplayPaletteChanged()),
|
||
|
this, TQT_SLOT(paletteChanged()));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void KActiveLabel::paletteChanged()
|
||
|
{
|
||
15 years ago
|
TQPalette p = kapp ? kapp->palette() : palette();
|
||
|
p.setBrush(TQColorGroup::Base, p.brush(TQPalette::Normal, TQColorGroup::Background));
|
||
|
p.setColor(TQColorGroup::Text, p.color(TQPalette::Normal, TQColorGroup::Foreground));
|
||
15 years ago
|
setPalette(p);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KActiveLabel::openLink(const TQString & link)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQRegExp whatsthis("whatsthis:/*([^/].*)");
|
||
15 years ago
|
if (whatsthis.exactMatch(link)) {
|
||
15 years ago
|
TQWhatsThis::display(whatsthis.cap(1));
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList args;
|
||
15 years ago
|
args << "exec" << link;
|
||
13 years ago
|
kapp->tdeinitExec("kfmclient", args);
|
||
15 years ago
|
}
|
||
|
|
||
|
void KActiveLabel::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
15 years ago
|
void KActiveLabel::focusInEvent( TQFocusEvent* fe )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQTextBrowser::focusInEvent(fe);
|
||
|
if(fe->reason() == TQFocusEvent::Tab || fe->reason() == TQFocusEvent::Backtab)
|
||
15 years ago
|
selectAll(true);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KActiveLabel::focusOutEvent( TQFocusEvent* fe )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQTextBrowser::focusOutEvent(fe);
|
||
|
if(fe->reason() == TQFocusEvent::Tab || fe->reason() == TQFocusEvent::Backtab)
|
||
15 years ago
|
selectAll(false);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KActiveLabel::keyPressEvent( TQKeyEvent *e )
|
||
15 years ago
|
{
|
||
|
switch ( e->key() )
|
||
|
{
|
||
|
case Key_Down:
|
||
|
case Key_Up:
|
||
|
case Key_Left:
|
||
|
case Key_Right:
|
||
|
// jump over QTextEdit's key navigation breakage.
|
||
|
// we're not interested in keyboard navigation within the text
|
||
15 years ago
|
TQWidget::keyPressEvent( e );
|
||
15 years ago
|
break;
|
||
|
default:
|
||
15 years ago
|
TQTextBrowser::keyPressEvent( e );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQSize KActiveLabel::tqminimumSizeHint() const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQSize ms = tqminimumSize();
|
||
15 years ago
|
if ((ms.width() > 0) && (ms.height() > 0))
|
||
|
return ms;
|
||
|
|
||
|
int w = 400;
|
||
|
if (ms.width() > 0)
|
||
|
w = ms.width();
|
||
|
|
||
15 years ago
|
TQString txt = text();
|
||
|
TQSimpleRichText rt(txt, font());
|
||
15 years ago
|
rt.setWidth(w - 2*frameWidth() - 10);
|
||
|
w = 10 + rt.widthUsed() + 2*frameWidth();
|
||
|
if (w < ms.width())
|
||
|
w = ms.width();
|
||
|
int h = rt.height() + 2*frameWidth();
|
||
|
if ( h < ms.height())
|
||
|
h = ms.height();
|
||
|
|
||
15 years ago
|
return TQSize(w, h);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQSize KActiveLabel::tqsizeHint() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return tqminimumSizeHint();
|
||
15 years ago
|
}
|
||
|
|
||
|
#include "kactivelabel.moc"
|