1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/* This file is part of the KDE libraries
Copyright (C) 1999 Waldo Bastian ([email protected])
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 <tdeapplication.h>
#include <tqregexp.h>
#include <tqwhatsthis.h>
#include <tqsimplerichtext.h>
#include <kdebug.h>
KActiveLabel::KActiveLabel(TQWidget * parent, const char * name)
: TQTextBrowser(parent, name)
{
init();
}
KActiveLabel::KActiveLabel(const TQString &text, TQWidget * parent, const char * name)
: TQTextBrowser(parent, name)
{
init();
setText(text);
}
void KActiveLabel::init()
{
setTextFormat(TQt::RichText);
setVScrollBarMode(TQScrollView::AlwaysOff);
setHScrollBarMode(TQScrollView::AlwaysOff);
setFrameStyle(TQFrame::NoFrame);
setFocusPolicy( TQWidget::TabFocus );
paletteChanged();
connect(this, TQT_SIGNAL(linkClicked(const TQString &)),
this, TQT_SLOT(openLink(const TQString &)));
if (kapp)
{
connect(kapp, TQT_SIGNAL(tdedisplayPaletteChanged()),
this, TQT_SLOT(paletteChanged()));
}
}
void KActiveLabel::paletteChanged()
{
TQPalette p = kapp ? kapp->palette() : palette();
p.setBrush(TQColorGroup::Base, p.brush(TQPalette::Active, TQColorGroup::Background));
p.setColor(TQColorGroup::Text, p.color(TQPalette::Active, TQColorGroup::Foreground));
setPalette(p);
}
void KActiveLabel::openLink(const TQString & link)
{
TQRegExp whatsthis("whatsthis:/*([^/].*)");
if (whatsthis.exactMatch(link)) {
TQWhatsThis::display(whatsthis.cap(1));
return;
}
TQStringList args;
args << "exec" << link;
kapp->tdeinitExec("kfmclient", args);
}
void KActiveLabel::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
void KActiveLabel::focusInEvent( TQFocusEvent* fe )
{
TQTextBrowser::focusInEvent(fe);
if(fe->reason() == TQFocusEvent::Tab || fe->reason() == TQFocusEvent::Backtab)
selectAll(true);
}
void KActiveLabel::focusOutEvent( TQFocusEvent* fe )
{
TQTextBrowser::focusOutEvent(fe);
if(fe->reason() == TQFocusEvent::Tab || fe->reason() == TQFocusEvent::Backtab)
selectAll(false);
}
void KActiveLabel::keyPressEvent( TQKeyEvent *e )
{
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
TQWidget::keyPressEvent( e );
break;
default:
TQTextBrowser::keyPressEvent( e );
}
}
TQSize KActiveLabel::minimumSizeHint() const
{
TQSize ms = minimumSize();
if ((ms.width() > 0) && (ms.height() > 0))
return ms;
int w = 400;
if (ms.width() > 0)
w = ms.width();
TQString txt = text();
TQSimpleRichText rt(txt, font());
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();
return TQSize(w, h);
}
TQSize KActiveLabel::sizeHint() const
{
return minimumSizeHint();
}
#include "kactivelabel.moc"
|