00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef QT4SYNTAXHIGHLIGHTER_H_
00010 #define QT4SYNTAXHIGHLIGHTER_H_
00011
00012 #include <QSyntaxHighlighter>
00013 #include <QTextDocument>
00014 #include <QTextCharFormat>
00015 #include <QMap>
00016
00017 #include "GNUSyntaxHighlighter.h"
00018 #include "Qt4TextFormatter.h"
00019
00020 namespace srchiliteqt {
00021
00023 typedef QMap<QString, Qt4TextFormatter *> Qt4TextFormatterMap;
00024
00026 typedef QMapIterator<QString, Qt4TextFormatter *> Qt4TextFormatterMapIterator;
00027
00041 class Qt4SyntaxHighlighter: public QSyntaxHighlighter,
00042 public GNUSyntaxHighlighter {
00043
00045 QString currentStyleFile;
00046
00047 protected:
00051 void highlightBlock(const QString &text);
00052
00059 void setFormatters(const TextFormatterMap &formatterMap);
00060
00061 public:
00062 Qt4SyntaxHighlighter(QTextDocument *doc = 0);
00063 virtual ~Qt4SyntaxHighlighter();
00064
00072 void init(const QString &langFile, const QString &styleFile =
00073 "default.style");
00074
00082 bool initFromFileName(const QString &fileName);
00083
00099 void formatString(int start, int count, const QTextCharFormat & format) {
00100 setFormat(start, count, format);
00101 }
00102
00112 void setFormattingStyle(const QString &styleFile);
00113
00115 const QString getFormattingStyle() const {
00116 return currentStyleFile;
00117 }
00118
00136 const srchilite::FormatterMap &getFormatterMap() const {
00137 return formatterManager->getFormatterMap();
00138 }
00139
00146 Qt4TextFormatterMap getQt4TextFormatterMap();
00147 };
00148
00149 }
00150
00151 #endif