00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
#ifdef HAVE_CONFIG_H
00033
#include <config.h>
00034
#endif
00035
00036
#include "mailsourceviewer.h"
00037
00038
#include <kapplication.h>
00039
#include <kwin.h>
00040
00041
#include <qregexp.h>
00042
#include <qaccel.h>
00043
00044
namespace KMail {
00045
00046
int MailSourceHighlighter::highlightParagraph(
const QString& text,
int ) {
00047
QRegExp regexp(
"^([\\w-]+:\\s)" );
00048
if( regexp.search( text ) != -1 ) {
00049
QFont font = textEdit()->currentFont();
00050 font.setBold(
true );
00051 setFormat( 0, regexp.matchedLength(), font );
00052 }
00053
return 0;
00054 }
00055
00056 MailSourceViewer::MailSourceViewer(
QWidget *parent,
const char *name )
00057 : KTextBrowser( parent, name ), mSourceHighLighter( 0 )
00058 {
00059 setWFlags( WDestructiveClose );
00060
QAccel *accel =
new QAccel(
this,
"browser close-accel" );
00061 accel->connectItem( accel->insertItem( Qt::Key_Escape ),
this , SLOT( close() ));
00062 setWordWrap( KTextBrowser::NoWrap );
00063 KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
00064 }
00065
00066 MailSourceViewer::~MailSourceViewer()
00067 {
00068
delete mSourceHighLighter; mSourceHighLighter = 0;
00069 }
00070
00071
void MailSourceViewer::setText(
const QString& text )
00072 {
00073
delete mSourceHighLighter; mSourceHighLighter = 0;
00074
if ( text.length() > 500000 ) {
00075 setTextFormat( Qt::LogText );
00076 }
else {
00077 setTextFormat( Qt::PlainText );
00078 mSourceHighLighter =
new MailSourceHighlighter(
this );
00079 }
00080 KTextBrowser::setText( text );
00081 }
00082
00083 }