1 /* -*- mode: C++; c-file-style: "gnu" -*-
3 * This file is part of KMail, the KDE mail client.
5 * Copyright (c) 2002-2003 Carsten Pfeiffer <pfeiffer@kde.org>
6 * Copyright (c) 2003 Zack Rusin <zack@kde.org>
8 * KMail is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License, version 2, as
10 * published by the Free Software Foundation.
12 * KMail is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * In addition, as a special exception, the copyright holders give
22 * permission to link the code of this program with any edition of
23 * the Qt library by Trolltech AS, Norway (or with modified versions
24 * of Qt that use the same license as Qt), and distribute linked
25 * combinations including the two. You must obey the GNU General
26 * Public License in all respects for all of the code used other than
27 * Qt. If you modify this file, you may extend this exception to
28 * your version of the file, but you are not obligated to do so. If
29 * you do not wish to do so, delete this exception statement from
32 #ifndef MAILSOURCEVIEWER_H
33 #define MAILSOURCEVIEWER_H
35 #include <QSyntaxHighlighter>
37 #include <QPlainTextEdit>
43 namespace MessageViewer
{
44 class FindBarSourceView
;
47 * A tiny little class to use for displaying raw messages, textual
50 * Auto-deletes itself when closed.
52 * @author Carsten Pfeiffer <pfeiffer@kde.org>
54 class MailSourceViewTextBrowser
;
55 class MailSourceHighlighter
: public QSyntaxHighlighter
58 MailSourceHighlighter( QTextDocument
* textdocument
)
59 : QSyntaxHighlighter( textdocument
)
62 virtual void highlightBlock ( const QString
& text
);
65 class HTMLSourceHighlighter
: public QSyntaxHighlighter
68 HTMLSourceHighlighter( QTextDocument
* textdocument
)
69 : QSyntaxHighlighter( textdocument
)
72 virtual void highlightBlock ( const QString
& text
);
75 class MailSourceViewTextBrowserWidget
: public QWidget
79 explicit MailSourceViewTextBrowserWidget( QWidget
*parent
= 0 );
81 void setText( const QString
& text
);
82 void setPlainText( const QString
& text
);
83 MessageViewer::MailSourceViewTextBrowser
*textBrowser() const;
87 MailSourceViewTextBrowser
*mTextBrowser
;
88 FindBarSourceView
*mFindBar
;
91 class MailSourceViewTextBrowser
: public QPlainTextEdit
95 explicit MailSourceViewTextBrowser( QWidget
*parent
= 0 );
97 virtual void contextMenuEvent( QContextMenuEvent
*event
);
104 namespace HTMLPrettyFormatter
106 // Best to be really verbose about this one...
107 const QRegExp
htmlTagRegExp( "<"
108 "(/)?" //Captures the / if this is an end tag.
109 "(\\w+)" //Captures TagName
110 "(?:" //Groups tag contents
111 "(?:\\s+" //Groups attributes
112 "(?:\\w+)" //Attribute name
113 "(?:" //groups =value portion.
115 "(?:" //Groups attribute "value" portion.
116 "\\\"(?:[^\\\"]*)\\\"" // attVal='double quoted'
117 "|'(?:[^']*)'" // attVal='single quoted'
118 "|(?:[^'"">\\s]+)" // attVal=urlnospaces
120 ")?" //end optional att value portion.
121 ")+\\s*" //One or more attribute pairs
122 "|\\s*" //Some white space.
124 "(/)?>" //Captures the "/" if this is a complete tag.
127 const QString
reformat( const QString
&src
);
130 class MailSourceViewer
: public KDialog
134 MailSourceViewer( QWidget
*parent
= 0 );
137 void setRawSource( const QString
&source
);
138 void setDisplayedSource( const QString
&source
);
140 KTabWidget
*mTabWidget
;
141 MailSourceViewTextBrowserWidget
*mRawBrowser
;
142 FindBarSourceView
*mFindBar
;
144 MailSourceViewTextBrowserWidget
*mHtmlBrowser
;
145 HTMLSourceHighlighter
*mHtmlSourceHighLighter
;
147 MailSourceHighlighter
*mRawSourceHighLighter
;
151 #endif // MAILSOURCEVIEWER_H