Source-highlight Qt Library
srchiliteqt::TextEditHighlighted Class Reference

A specialized QTextEdit that uses a Qt4SyntaxHighlighter for highlighting its contents. More...

#include <TextEditHighlighted.h>

Collaboration diagram for srchiliteqt::TextEditHighlighted:

Public Slots

void changeHighlightingLanguage (const QString &newLang)
 Changes the highlighting according to the new specified language.
void changeHighlightingStyle (const QString &newStyle)
 Changes the highlighting style according to the new specified style file.
void changeFileName (const QString &fileName)
 If the file name changes, then we check whether we need to change the language definition for highlighting.
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).

Signals

void changedHighlightingLanguage (const QString &newLang)
 This signal is emitted when the highlighting language definition changed.
void changedHighlightingStyle (const QString &newLang)
 This signal is emitted when the highlighting style changed.

Public Member Functions

 TextEditHighlighted (QWidget *parent)
void connectLanguageComboBox (LanguageComboBox *lcb)
 Connects a LanguageComboBox so that, if the language is changed it automatically rehighlights the contents of the textedit.
void connectStyleComboBox (StyleComboBox *lcb)
 Connects a StyleComboBox so that, if the style is changed it automatically rehighlights the contents of the textedit.
srchiliteqt::Qt4SyntaxHighlightergetHighlighter () const
void setHighlighter (const QString &langFile)
 Sets an highlighter for the specified language definition file.
const QString loadFile (const QString &fileName)
 Opens the file specified by fileName.
void changeColors (const QString &fgColor, const QString &bgColor)
 Changes the foreground and background color.

Private Attributes

srchiliteqt::Qt4SyntaxHighlighterhighlighter
 the highlighter object
LanguageComboBoxlanguageComboBox
 the (possible) LanguageComboBox for selecting languages
StyleComboBoxstyleComboBox
 the (possible) StyleComboBox for selecting languages
QString styleFile
 the style file of source-highlight for highlighting (default: "default.style")

Detailed Description

A specialized QTextEdit that uses a Qt4SyntaxHighlighter for highlighting its contents.

If connected to a LanguageComboBox, it automatically refreshes its highlighted contents when the language definition file changes. If connected to a StyleComboBox, it automatically refreshes its highlighted contents when the style changes.

Member Function Documentation

void srchiliteqt::TextEditHighlighted::changeColors ( const QString &  fgColor,
const QString &  bgColor 
)

Changes the foreground and background color.

Parameters
fgColorthe foreground (if empty, the color is not changed)
bgColorthe background (if empty, the color is not changed)
void srchiliteqt::TextEditHighlighted::changedHighlightingLanguage ( const QString &  newLang)
signal

This signal is emitted when the highlighting language definition changed.

Parameters
newLangthe new language definition
void srchiliteqt::TextEditHighlighted::changedHighlightingStyle ( const QString &  newLang)
signal

This signal is emitted when the highlighting style changed.

Parameters
newLangthe new language definition
void srchiliteqt::TextEditHighlighted::changeFileName ( const QString &  fileName)
slot

If the file name changes, then we check whether we need to change the language definition for highlighting.

Parameters
fileNamethe new file name
void srchiliteqt::TextEditHighlighted::changeHighlightingLanguage ( const QString &  newLang)
slot

Changes the highlighting according to the new specified language.

Parameters
newLangthe new language definition
void srchiliteqt::TextEditHighlighted::changeHighlightingStyle ( const QString &  newStyle)
slot

Changes the highlighting style according to the new specified style file.

Parameters
newStylethe new style
void srchiliteqt::TextEditHighlighted::connectLanguageComboBox ( LanguageComboBox lcb)

Connects a LanguageComboBox so that, if the language is changed it automatically rehighlights the contents of the textedit.

Parameters
lcbthe LanguageComboBox
void srchiliteqt::TextEditHighlighted::connectStyleComboBox ( StyleComboBox lcb)

Connects a StyleComboBox so that, if the style is changed it automatically rehighlights the contents of the textedit.

Parameters
lcbthe LanguageComboBox
const QString srchiliteqt::TextEditHighlighted::getLangDefFileFromFileName ( const QString &  filename)
slot

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

This method already catches possible exceptions thrown from the source-highlight library and show them in a message box.

Parameters
filename
Returns
the lang def file name or the empty string if no mapping exists
const QString srchiliteqt::TextEditHighlighted::loadFile ( const QString &  fileName)

Opens the file specified by fileName.

It uses the fileName to detect the source language and automatically selects the corresponding syntax highlighting.

Parameters
fileNamethe name of the file to open (complete path)
Returns
a string representing the error. If successful returns the empty string
void srchiliteqt::TextEditHighlighted::setHighlighter ( const QString &  langFile)

Sets an highlighter for the specified language definition file.

Parameters
langFile

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