Source-highlight Qt Library
Qt4SyntaxHighlighter.h
1 /*
2  * Copyright (C) 2008-2010 Lorenzo Bettini, http://www.lorenzobettini.it
3  * License: See COPYING file that comes with this distribution
4  */
5 
6 #ifndef QT4SYNTAXHIGHLIGHTER_H_
7 #define QT4SYNTAXHIGHLIGHTER_H_
8 
9 #include <QSyntaxHighlighter>
10 #include <QTextDocument>
11 #include <QTextCharFormat>
12 #include <QMap>
13 
14 #include "GNUSyntaxHighlighter.h"
15 #include "Qt4TextFormatter.h"
16 
17 namespace srchiliteqt {
18 
20 typedef QMap<QString, Qt4TextFormatter *> Qt4TextFormatterMap;
21 
23 typedef QMapIterator<QString, Qt4TextFormatter *> Qt4TextFormatterMapIterator;
24 
38 class Qt4SyntaxHighlighter: public QSyntaxHighlighter,
39  public GNUSyntaxHighlighter {
40 
43 
44 protected:
48  void highlightBlock(const QString &text);
49 
56  void setFormatters(const TextFormatterMap &formatterMap);
57 
58 public:
59  Qt4SyntaxHighlighter(QTextDocument *doc = 0);
60  virtual ~Qt4SyntaxHighlighter();
61 
69  void init(const QString &langFile, const QString &styleFile =
70  "default.style");
71 
79  bool initFromFileName(const QString &fileName);
80 
96  void formatString(int start, int count, const QTextCharFormat & format) {
97  setFormat(start, count, format);
98  }
99 
109  void setFormattingStyle(const QString &styleFile);
110 
112  const QString getFormattingStyle() const {
113  return currentStyleFile;
114  }
115 
133  const srchilite::FormatterMap &getFormatterMap() const {
134  return formatterManager->getFormatterMap();
135  }
136 
143  Qt4TextFormatterMap getQt4TextFormatterMap();
144 };
145 
146 }
147 
148 #endif /* QT4SYNTAXHIGHLIGHTER_H_ */