Source-highlight Qt Library
srchiliteqt::GNUSyntaxHighlighter Class Reference

An abstract class using GNU Source-highlight library to perform syntax highlighting. More...

#include <GNUSyntaxHighlighter.h>

Inheritance diagram for srchiliteqt::GNUSyntaxHighlighter:

Public Member Functions

const QString & getLangFile () const
 
srchilite::HighlightStatePtr getHighlightState (const QString &file)
 Given a language definition file name, returns the corresponding highlight state. More...
 
void initHighlighter (const QString &file)
 Given a language definition file name, initializes the Source-highlight's highlighter. More...
 
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). More...
 
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. More...
 
srchilite::FormatterManager * getFormatterManager () const
 
void highlightLine (const QString &line, HighlightStateData *&stateData)
 Highlights the passed line. More...
 
srchilite::LangDefManager * getLangDefManager () const
 
srchilite::LangMap * getLangMap () const
 
srchilite::LangMap * getOutLangMap () 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. More...
 
bool isDefaultToMonospace () const
 
void setDefaultToMonospace (bool d)
 Whether the highlighter should use monospace font by default if nothing is specified about the font family. More...
 

Protected Attributes

srchilite::FormatterManager * formatterManager
 This will be used by subclasses to generate the right table of formatters.
 

Private Attributes

QString langFile
 the lang file used by this highlighter
 
srchilite::SourceHighlighter * sourceHighlighter
 the GNU Source-highlighter used for the actual highlighting
 
srchilite::FormatterParams formatterParams
 this is crucial to get the starting position of the string to highlight within the whole line
 
QString foregroundColor
 the color string for foreground
 
QString backgroundColor
 the color string for background
 
bool readOnly
 whether we highlight read only contents
 
bool defaultToMonospace
 whether to default font to monospace (default true)
 

Detailed Description

An abstract class using GNU Source-highlight library to perform syntax highlighting.

You must use one of the concrete classes, depending on the version of Qt that you're using, e.g., Qt4SyntaxHighlighter or Qt3SyntaxHighlighter.

Member Function Documentation

const QString& srchiliteqt::GNUSyntaxHighlighter::getBackgroundColor ( ) const
inline
Returns
the background color string (can be empty)
const QString& srchiliteqt::GNUSyntaxHighlighter::getForegroundColor ( ) const
inline
Returns
the foreground color string (can be empty)
srchilite::FormatterManager* srchiliteqt::GNUSyntaxHighlighter::getFormatterManager ( ) const
inline
Returns
the Source-highlight FormatterManager
srchilite::SourceHighlighter* srchiliteqt::GNUSyntaxHighlighter::getHighlighter ( ) const
inline
Returns
the Source-highlight SourceHighlighter (can be null)
srchilite::HighlightStatePtr srchiliteqt::GNUSyntaxHighlighter::getHighlightState ( const QString &  file)

Given a language definition file name, returns the corresponding highlight state.

This method is mainly for testing purposes.

Parameters
file
Returns
the corresponding highlight state
Exceptions
srchilite::ParserException
const QString srchiliteqt::GNUSyntaxHighlighter::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).

Parameters
filename
Returns
the lang def file name or the empty string if no mapping exists
srchilite::LangDefManager * srchiliteqt::GNUSyntaxHighlighter::getLangDefManager ( ) const
Returns
the LangDefManager object used by this highlighter
srchilite::LangMap * srchiliteqt::GNUSyntaxHighlighter::getLangMap ( ) const
Returns
the LangMap dealing with language definition files.
srchilite::LangMap * srchiliteqt::GNUSyntaxHighlighter::getOutLangMap ( ) const
Returns
the LangMap dealing with output language definition files.
const TextFormatterMap & srchiliteqt::GNUSyntaxHighlighter::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.

If the TextFormatterFactory already contains some formatters, then simpy returns its TextFormatterMap, without rebuilding it.

Parameters
formatterFactorythe formatter factory to create formatters
styleFilethe 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)
Returns
the TextFormatterMap
Exceptions
ParserExceptionin case of parsing error of the style file
void srchiliteqt::GNUSyntaxHighlighter::highlightLine ( const QString &  line,
HighlightStateData *&  stateData 
)

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).

Parameters
line
stateDatathe highlight state data to use
Returns
in case after highlighting the stack changed we return either the original stateData (after updating) or a new HighlightStateData (again with the updated information)
void srchiliteqt::GNUSyntaxHighlighter::initHighlighter ( const QString &  file)

Given a language definition file name, initializes the Source-highlight's highlighter.

Parameters
filethe lang file of Source-highlight
Exceptions
srchilite::ParserException
bool srchiliteqt::GNUSyntaxHighlighter::isReadOnly ( ) const
inline
Returns
whether we must highlight readonly contents
void srchiliteqt::GNUSyntaxHighlighter::setDefaultToMonospace ( bool  d)
inline

Whether the highlighter should use monospace font by default if nothing is specified about the font family.

Parameters
d
void srchiliteqt::GNUSyntaxHighlighter::setReadOnly ( bool  r)
inline

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.

Parameters
r

The documentation for this class was generated from the following files: