Source-highlight Qt Library
GNUSyntaxHighlighter.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 GNUSYNTAXHIGHLIGHTER_H_
7 #define GNUSYNTAXHIGHLIGHTER_H_
8 
9 #include <srchilite/highlightstate.h>
10 #include <srchilite/formattermanager.h>
11 #include <srchilite/sourcehighlighter.h>
12 #include <srchilite/formatterparams.h>
13 #include <srchilite/langdefmanager.h>
14 #include <srchilite/langmap.h>
15 
16 #include "TextFormatterFactory.h"
17 #include "HighlightStateData.h"
18 
19 namespace srchiliteqt {
20 
28  QString langFile;
29 
31  srchilite::SourceHighlighter *sourceHighlighter;
32 
37  srchilite::FormatterParams formatterParams;
38 
40  QString foregroundColor;
41 
43  QString backgroundColor;
44 
46  bool readOnly;
47 
50 
51 protected:
55  srchilite::FormatterManager *formatterManager;
56 
57 public:
59  virtual ~GNUSyntaxHighlighter();
60 
61  const QString &getLangFile() const { return langFile; }
62 
70  srchilite::HighlightStatePtr getHighlightState(const QString &file);
71 
78  void initHighlighter(const QString &file);
79 
88  const QString getLangDefFileFromFileName(const QString &filename);
89 
93  srchilite::SourceHighlighter *getHighlighter() const {
94  return sourceHighlighter;
95  }
96 
110  const TextFormatterMap &getTextFormatterMap(
111  TextFormatterFactory &formatterFactory,
112  const QString &styleFile = "default.style");
113 
117  srchilite::FormatterManager *getFormatterManager() const {
118  return formatterManager;
119  }
120 
139  void highlightLine(const QString &line, HighlightStateData *&stateData);
140 
144  srchilite::LangDefManager *getLangDefManager() const;
145 
149  srchilite::LangMap *getLangMap() const;
150 
154  srchilite::LangMap *getOutLangMap() const;
155 
159  const QString &getForegroundColor() const {
160  return foregroundColor;
161  }
162 
166  const QString &getBackgroundColor() const {
167  return backgroundColor;
168  }
169 
170  void setForegroundColor(const QString &f) {
171  foregroundColor = f;
172  }
173 
174  void setBackgroundColor(const QString &b) {
175  backgroundColor = b;
176  }
177 
181  bool isReadOnly() const {
182  return readOnly;
183  }
184 
192  void setReadOnly(bool r) {
193  readOnly = r;
194  }
195 
196  bool isDefaultToMonospace() const {
197  return defaultToMonospace;
198  }
199 
206  void setDefaultToMonospace(bool d) {
207  defaultToMonospace = d;
208  }
209 };
210 
211 }
212 
213 #endif /* GNUSYNTAXHIGHLIGHTER_H_ */
void setDefaultToMonospace(bool d)
Whether the highlighter should use monospace font by default if nothing is specified about the font f...
Definition: GNUSyntaxHighlighter.h:206
Definition: ColorDialog.cpp:12
srchilite::SourceHighlighter * sourceHighlighter
the GNU Source-highlighter used for the actual highlighting
Definition: GNUSyntaxHighlighter.h:31
srchilite::LangMap * getOutLangMap() const
Definition: GNUSyntaxHighlighter.cpp:50
srchilite::SourceHighlighter * getHighlighter() const
Definition: GNUSyntaxHighlighter.h:93
const QString & getBackgroundColor() const
Definition: GNUSyntaxHighlighter.h:166
const QString getLangDefFileFromFileName(const QString &filename)
Returns the the lang def file name by using the file name for detecting the syntax of the file (e...
Definition: GNUSyntaxHighlighter.cpp:76
void initHighlighter(const QString &file)
Given a language definition file name, initializes the Source-highlight&#39;s highlighter.
Definition: GNUSyntaxHighlighter.cpp:61
srchilite::HighlightStatePtr getHighlightState(const QString &file)
Given a language definition file name, returns the corresponding highlight state. ...
Definition: GNUSyntaxHighlighter.cpp:56
bool isReadOnly() const
Definition: GNUSyntaxHighlighter.h:181
srchilite::FormatterManager * formatterManager
This will be used by subclasses to generate the right table of formatters.
Definition: GNUSyntaxHighlighter.h:55
QString foregroundColor
the color string for foreground
Definition: GNUSyntaxHighlighter.h:40
srchilite::FormatterManager * getFormatterManager() const
Definition: GNUSyntaxHighlighter.h:117
Specialization of FormatterFactory to create TextFormatter objects to format text in a TextEdit...
Definition: TextFormatterFactory.h:26
void setReadOnly(bool r)
Specifies that we highlight readonly contents.
Definition: GNUSyntaxHighlighter.h:192
QString langFile
the lang file used by this highlighter
Definition: GNUSyntaxHighlighter.h:28
QString backgroundColor
the color string for background
Definition: GNUSyntaxHighlighter.h:43
Utility class to deal with current highlighting state (and stack of states)
Definition: HighlightStateData.h:16
srchilite::LangMap * getLangMap() const
Definition: GNUSyntaxHighlighter.cpp:44
bool readOnly
whether we highlight read only contents
Definition: GNUSyntaxHighlighter.h:46
const QString & getForegroundColor() const
Definition: GNUSyntaxHighlighter.h:159
void highlightLine(const QString &line, HighlightStateData *&stateData)
Highlights the passed line.
Definition: GNUSyntaxHighlighter.cpp:110
An abstract class using GNU Source-highlight library to perform syntax highlighting.
Definition: GNUSyntaxHighlighter.h:26
srchilite::FormatterParams formatterParams
this is crucial to get the starting position of the string to highlight within the whole line ...
Definition: GNUSyntaxHighlighter.h:37
const TextFormatterMap & getTextFormatterMap(TextFormatterFactory &formatterFactory, const QString &styleFile="default.style")
Given a TextFormatterFactory, it uses to build the TextFormatterMap, by reading a specified source-hi...
Definition: GNUSyntaxHighlighter.cpp:81
srchilite::LangDefManager * getLangDefManager() const
Definition: GNUSyntaxHighlighter.cpp:40
bool defaultToMonospace
whether to default font to monospace (default true)
Definition: GNUSyntaxHighlighter.h:49