• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

cantor/src/lib

  • Cantor
  • DefaultHighlighter
Public Slots | Signals | Public Member Functions | Protected Member Functions | List of all members
Cantor::DefaultHighlighter Class Reference

#include <defaulthighlighter.h>

Inheritance diagram for Cantor::DefaultHighlighter:
Inheritance graph
[legend]

Public Slots

void positionChanged (QTextCursor)
 

Signals

void rulesChanged ()
 

Public Member Functions

 DefaultHighlighter (QObject *parent)
 
 ~DefaultHighlighter ()
 
void setTextItem (QGraphicsTextItem *item)
 

Protected Member Functions

template<class Container >
void addFunctions (const Container &functions)
 
template<class Container >
void addKeywords (const Container &keywords)
 
void addPair (const QChar &openSymbol, const QChar &closeSymbol)
 
void addRule (const QString &word, const QTextCharFormat &format)
 
void addRule (const QRegExp &regexp, const QTextCharFormat &format)
 
template<class Container >
void addRules (const Container &conditions, const QTextCharFormat &format)
 
template<class Container >
void addVariables (const Container &variables)
 
QTextCharFormat commentFormat () const
 
QTextCharFormat errorFormat () const
 
QTextCharFormat functionFormat () const
 
virtual void highlightBlock (const QString &text)
 
void highlightPairs (const QString &text)
 
void highlightRegExps (const QString &text)
 
void highlightWords (const QString &text)
 
QTextCharFormat keywordFormat () const
 
QTextCharFormat matchingPairFormat () const
 
QTextCharFormat mismatchingPairFormat () const
 
virtual QString nonSeparatingCharacters () const
 
QTextCharFormat numberFormat () const
 
QTextCharFormat objectFormat () const
 
QTextCharFormat operatorFormat () const
 
void removeRule (const QString &word)
 
void removeRule (const QRegExp &regexp)
 
template<class Container >
void removeRules (const Container &conditions)
 
bool skipHighlighting (const QString &text)
 
QTextCharFormat stringFormat () const
 
QTextCharFormat variableFormat () const
 

Detailed Description

The DefaultHighlighter is an implementation QSyntaxHighlighter.

It covers most common cases of syntax highlighting for Cantor's command entries.

When creating a custom highlighter, for example for a new backend, you should use the provided functions addPairs(), addRule() and/or addRules().

If you need more specific functionality, subclass highlightBlock(). Usually it's a good idea to also call DefaultHighlighter's implementation from it.

Author
Alexander Rieder

Definition at line 47 of file defaulthighlighter.h.

Constructor & Destructor Documentation

DefaultHighlighter::DefaultHighlighter ( QObject *  parent)

Definition at line 82 of file defaulthighlighter.cpp.

DefaultHighlighter::~DefaultHighlighter ( )

Definition at line 98 of file defaulthighlighter.cpp.

Member Function Documentation

template<class Container >
void Cantor::DefaultHighlighter::addFunctions ( const Container &  functions)
protected

Convenience method, equivalent to.

addRules(functions, functionFormat())

Definition at line 195 of file defaulthighlighter.h.

template<class Container >
void Cantor::DefaultHighlighter::addKeywords ( const Container &  keywords)
protected

Convenience method, equivalent to.

addRules(keywords, keywordFormat())

Definition at line 201 of file defaulthighlighter.h.

void DefaultHighlighter::addPair ( const QChar &  openSymbol,
const QChar &  closeSymbol 
)
protected

Call this to add a pair of symbols for highlighting.

The default implementation of the class already adds (), {} and [], so no need to add those. For example, if you wanted to highlight angle-brackets, you would use:

addPair('<', '>');
Parameters
openSymbolthe opening symbol of the pair
closeSymbolthe closing symbol of the pair
See also
highlightPairs

Definition at line 137 of file defaulthighlighter.cpp.

void DefaultHighlighter::addRule ( const QString &  word,
const QTextCharFormat &  format 
)
protected

Highlights all instances of the word in the text with the specified format.

Parameters
wordthe word to highlight
formatthe format to be used for displaying the word

Definition at line 380 of file defaulthighlighter.cpp.

void DefaultHighlighter::addRule ( const QRegExp &  regexp,
const QTextCharFormat &  format 
)
protected

Highlights all parts of the text matched by the regular expression regexp in the text with the specified format.

Parameters
regexpthe regular expression used to look for matches
formatthe format used to display the matching parts of the text

Definition at line 386 of file defaulthighlighter.cpp.

template<class Container >
void Cantor::DefaultHighlighter::addRules ( const Container &  conditions,
const QTextCharFormat &  format 
)
protected

Convenience method, highlights all items in conditions with the specified format.

QStringList greenWords;
greenWords << "tree" << "forest" << "grass";
addRules(greenWords, greenWordFormat);
Parameters
conditionsany Qt container of QRegExp or QString.

Definition at line 184 of file defaulthighlighter.h.

template<class Container >
void Cantor::DefaultHighlighter::addVariables ( const Container &  variables)
protected

Convenience method, equivalent to.

addRules(variables, variableFormat())

Definition at line 207 of file defaulthighlighter.h.

QTextCharFormat DefaultHighlighter::commentFormat ( ) const
protected

Definition at line 293 of file defaulthighlighter.cpp.

QTextCharFormat DefaultHighlighter::errorFormat ( ) const
protected

Definition at line 288 of file defaulthighlighter.cpp.

QTextCharFormat DefaultHighlighter::functionFormat ( ) const
protected

Definition at line 258 of file defaulthighlighter.cpp.

void DefaultHighlighter::highlightBlock ( const QString &  text)
protectedvirtual

This method is called by Cantor's KTextEdit and is where all the highlighting must take place.

The default implementation calls highlightPairs(), highlightWords() and highlightRegExps().

Definition at line 123 of file defaulthighlighter.cpp.

void DefaultHighlighter::highlightPairs ( const QString &  text)
protected

Highlight pairs added with addPair()

See also
addPair

Definition at line 144 of file defaulthighlighter.cpp.

void DefaultHighlighter::highlightRegExps ( const QString &  text)
protected

Highlights all matches from regular expressions added with addRule()

See also
addRule, addRules

Definition at line 245 of file defaulthighlighter.cpp.

void DefaultHighlighter::highlightWords ( const QString &  text)
protected

Highlights words added with addRule()

See also
addRule, addRules

Definition at line 189 of file defaulthighlighter.cpp.

QTextCharFormat DefaultHighlighter::keywordFormat ( ) const
protected

Definition at line 273 of file defaulthighlighter.cpp.

QTextCharFormat DefaultHighlighter::matchingPairFormat ( ) const
protected

Definition at line 303 of file defaulthighlighter.cpp.

QTextCharFormat DefaultHighlighter::mismatchingPairFormat ( ) const
protected

Definition at line 308 of file defaulthighlighter.cpp.

QString DefaultHighlighter::nonSeparatingCharacters ( ) const
protectedvirtual

Returns a string that contains a regular expression that matches for characters thar are allowed inside words for this backend.

For example, maxima or scilab allow % at the beginning of variable names

Definition at line 410 of file defaulthighlighter.cpp.

QTextCharFormat DefaultHighlighter::numberFormat ( ) const
protected

Definition at line 278 of file defaulthighlighter.cpp.

QTextCharFormat DefaultHighlighter::objectFormat ( ) const
protected

Definition at line 268 of file defaulthighlighter.cpp.

QTextCharFormat DefaultHighlighter::operatorFormat ( ) const
protected

Definition at line 283 of file defaulthighlighter.cpp.

void DefaultHighlighter::positionChanged ( QTextCursor  cursor)
slot

Called when the cursor moved.

Rehighlights accordingly.

Definition at line 350 of file defaulthighlighter.cpp.

void DefaultHighlighter::removeRule ( const QString &  word)
protected

Removes any rules previously added for the word word.

Definition at line 395 of file defaulthighlighter.cpp.

void DefaultHighlighter::removeRule ( const QRegExp &  regexp)
protected

Removes any rules previously added for the regular expression regexp.

Definition at line 402 of file defaulthighlighter.cpp.

template<class Container >
void Cantor::DefaultHighlighter::removeRules ( const Container &  conditions)
protected

Convenience method, removes all rules with conditions from conditions.

See also
removeRule, addRules

Definition at line 213 of file defaulthighlighter.h.

void Cantor::DefaultHighlighter::rulesChanged ( )
signal
void DefaultHighlighter::setTextItem ( QGraphicsTextItem *  item)

Change the item beeing highlighted.

Definition at line 103 of file defaulthighlighter.cpp.

bool DefaultHighlighter::skipHighlighting ( const QString &  text)
protected

Definition at line 118 of file defaulthighlighter.cpp.

QTextCharFormat DefaultHighlighter::stringFormat ( ) const
protected

Definition at line 298 of file defaulthighlighter.cpp.

QTextCharFormat DefaultHighlighter::variableFormat ( ) const
protected

Definition at line 263 of file defaulthighlighter.cpp.


The documentation for this class was generated from the following files:
  • defaulthighlighter.h
  • defaulthighlighter.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

cantor/src/lib

Skip menu "cantor/src/lib"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal