#include <Qt3SyntaxHighlighter.h>
Inherits srchiliteqt::GNUSyntaxHighlighter.
Public Member Functions | |
Qt3SyntaxHighlighter (QTextEdit *parent=0) | |
void | init (const std::string &langFile) |
Initializes this highlighter with the specified language definition file. | |
void | formatString (int start, int count, const QFont &font, const QColor &color) |
This function is applied to the syntax highlighter's current text block (i.e. | |
void | formatString (int start, int count, const QFont &font) |
const QString & | getLangFile () const |
srchilite::HighlightStatePtr | getHighlightState (const QString &file) |
Given a language definition file name, returns the corresponding highlight state. | |
void | initHighlighter (const QString &file) |
Given a language definition file name, initializes the Source-highlight's highlighter. | |
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.g., foo.cpp brings to cpp.lang, ChangeLog brings to changelog.lang). | |
srchilite::SourceHighlighter * | getHighlighter () const |
const TextFormatterMap & | getTextFormatterMap (TextFormatterFactory &formatterFactory, const QString &styleFile="default.style") |
Given a TextFormatterFactory, it uses to build the TextFormatterMap, by reading a specified source-highlight style file. | |
srchilite::FormatterManager * | getFormatterManager () const |
void | highlightLine (const QString &line, HighlightStateData *&stateData) |
Highlights the passed line. | |
srchilite::LangDefManager * | getLangDefManager () const |
srchilite::LangMap * | getLangMap () const |
const QString & | getForegroundColor () const |
const QString & | getBackgroundColor () const |
void | setForegroundColor (const QString &f) |
void | setBackgroundColor (const QString &b) |
bool | isReadOnly () const |
void | setReadOnly (bool r) |
Specifies that we highlight readonly contents. | |
bool | isDefaultToMonosapce () const |
void | setDefaultToMonosapce (bool d) |
Whether the highlighter should use monospace font by default if nothing is specified about the font family. | |
Protected Member Functions | |
int | highlightParagraph (const QString &text, int endStateOfLastPara) |
Protected Attributes | |
ParagraphMap | paragraphMap |
used internally to associate HighlightStateData to paragraphs | |
srchilite::FormatterManager * | formatterManager |
This will be used by subclasses to generate the right table of formatters. |
You can use such highlighter with a QTextEdit, and initialize the highlighter with the language definition file, e.g.,
QTextEdit *editor = new QTextEdit; srchiliteqt::Qt3SyntaxHighlighter *highlighter = new srchiliteqt::Qt3SyntaxHighlighter(editor->document()); highlighter->init("java.lang");
void srchiliteqt::Qt3SyntaxHighlighter::formatString | ( | int | start, | |
int | count, | |||
const QFont & | font, | |||
const QColor & | color | |||
) | [inline] |
This function is applied to the syntax highlighter's current text block (i.e.
the text that is passed to the highlightParagraph() method).
The specified font and color are applied to the text from the start position for a length of count characters (if count is 0, nothing is done). The formatting properties set in format are merged at display time with the formatting information stored directly in the document, for example as previously set with QTextCursor's functions.
Note that this helper function will be called by the corresponding TextFormatter, from Source-highglight library code, and relies on the corresponding protected method of QSyntaxHighlighter: setFormat).
const QString& srchiliteqt::GNUSyntaxHighlighter::getBackgroundColor | ( | ) | const [inline, inherited] |
const QString& srchiliteqt::GNUSyntaxHighlighter::getForegroundColor | ( | ) | const [inline, inherited] |
srchilite::FormatterManager* srchiliteqt::GNUSyntaxHighlighter::getFormatterManager | ( | ) | const [inline, inherited] |
srchilite::SourceHighlighter* srchiliteqt::GNUSyntaxHighlighter::getHighlighter | ( | ) | const [inline, inherited] |
srchilite::HighlightStatePtr srchiliteqt::GNUSyntaxHighlighter::getHighlightState | ( | const QString & | file | ) | [inherited] |
Given a language definition file name, returns the corresponding highlight state.
This method is mainly for testing purposes.
file |
srchilite::ParserException |
const QString srchiliteqt::GNUSyntaxHighlighter::getLangDefFileFromFileName | ( | const QString & | filename | ) | [inherited] |
Returns the the lang def file name by using the file name for detecting the syntax of the file (e.g., foo.cpp brings to cpp.lang, ChangeLog brings to changelog.lang).
filename |
srchilite::LangDefManager * srchiliteqt::GNUSyntaxHighlighter::getLangDefManager | ( | ) | const [inherited] |
srchilite::LangMap * srchiliteqt::GNUSyntaxHighlighter::getLangMap | ( | ) | const [inherited] |
const TextFormatterMap & srchiliteqt::GNUSyntaxHighlighter::getTextFormatterMap | ( | TextFormatterFactory & | formatterFactory, | |
const QString & | styleFile = "default.style" | |||
) | [inherited] |
Given a TextFormatterFactory, it uses to build the TextFormatterMap, by reading a specified source-highlight style file.
If the TextFormatterFactory already contains some formatters, then simpy returns its TextFormatterMap, without rebuilding it.
formatterFactory | the formatter factory to create formatters | |
styleFile | the style file name (can be a .style file or a .css file - in this case it must be a css file that source-highlight is able to handle) |
ParserException | in case of parsing error of the style file |
void srchiliteqt::GNUSyntaxHighlighter::highlightLine | ( | const QString & | line, | |
HighlightStateData *& | stateData | |||
) | [inherited] |
Highlights the passed line.
This method assumes that all the fields are already initialized (e.g., the FormatterManager).
The passed HighlightStateData is used to configure the SourceHighlighter with info like the current highlighting state and the state stack. If it is null, we simply ignore it.
This method can modify the bassed pointer and even make it NULL (after deleting it).
line | ||
stateData | the highlight state data to use |
void srchiliteqt::Qt3SyntaxHighlighter::init | ( | const std::string & | langFile | ) |
Initializes this highlighter with the specified language definition file.
langFile |
void srchiliteqt::GNUSyntaxHighlighter::initHighlighter | ( | const QString & | file | ) | [inherited] |
Given a language definition file name, initializes the Source-highlight's highlighter.
file | the lang file of Source-highlight |
srchilite::ParserException |
bool srchiliteqt::GNUSyntaxHighlighter::isReadOnly | ( | ) | const [inline, inherited] |
void srchiliteqt::GNUSyntaxHighlighter::setDefaultToMonosapce | ( | bool | d | ) | [inline, inherited] |
Whether the highlighter should use monospace font by default if nothing is specified about the font family.
d |
void srchiliteqt::GNUSyntaxHighlighter::setReadOnly | ( | bool | r | ) | [inline, inherited] |
Specifies that we highlight readonly contents.
This optimizes the highlighting: being readonly, we must not keep track of the state of the previous line, and this saves time and memory.
r |