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_ */
void setFormattingStyle(const QString &styleFile)
Sets the styleFile for highlighting.
Definition: Qt4SyntaxHighlighter.cpp:82
Definition: ColorDialog.cpp:12
QString currentStyleFile
the current style file for highlighting
Definition: Qt4SyntaxHighlighter.h:42
srchilite::FormatterManager * formatterManager
This will be used by subclasses to generate the right table of formatters.
Definition: GNUSyntaxHighlighter.h:55
void highlightBlock(const QString &text)
The implementation of the virtual pure method of QSyntaxHighlighter.
Definition: Qt4SyntaxHighlighter.cpp:172
void init(const QString &langFile, const QString &styleFile="default.style")
Initializes this highlighter with the specified language definition file.
Definition: Qt4SyntaxHighlighter.cpp:63
Qt4TextFormatterMap getQt4TextFormatterMap()
Returns the formatter map of this highlighter.
Definition: Qt4SyntaxHighlighter.cpp:126
QString langFile
the lang file used by this highlighter
Definition: GNUSyntaxHighlighter.h:28
const srchilite::FormatterMap & getFormatterMap() const
Returns the formatter map, i.e., for each language element we have a formatter.
Definition: Qt4SyntaxHighlighter.h:133
void setFormatters(const TextFormatterMap &formatterMap)
Creates formatters (and use them to initialize the formatter manager), by using the passed TextFormat...
Definition: Qt4SyntaxHighlighter.cpp:103
const QString getFormattingStyle() const
Definition: Qt4SyntaxHighlighter.h:112
An implementation of QSyntaxHighlighter using GNU Source-highlight library (by relying on GNUSyntaxHi...
Definition: Qt4SyntaxHighlighter.h:38
An abstract class using GNU Source-highlight library to perform syntax highlighting.
Definition: GNUSyntaxHighlighter.h:26
void formatString(int start, int count, const QTextCharFormat &format)
This function is applied to the syntax highlighter's current text block (i.e.
Definition: Qt4SyntaxHighlighter.h:96
bool initFromFileName(const QString &fileName)
Initializes this highlighter by using the file name for detecting the syntax of the file (e...
Definition: Qt4SyntaxHighlighter.cpp:164