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

cantor/src/lib

  • sources
  • kde-4.14
  • kdeedu
  • cantor
  • src
  • lib
defaulthighlighter.h
Go to the documentation of this file.
1 /*
2  This program is free software; you can redistribute it and/or
3  modify it under the terms of the GNU General Public License
4  as published by the Free Software Foundation; either version 2
5  of the License, or (at your option) any later version.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin Street, Fifth Floor,
15  Boston, MA 02110-1301, USA.
16 
17  ---
18  Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
19  */
20 
21 #ifndef DEFAULTHIGHLIGHTER_H
22 #define DEFAULTHIGHLIGHTER_H
23 
24 #include "cantor_export.h"
25 
26 #include <QtGui/QSyntaxHighlighter>
27 
28 class QGraphicsTextItem;
29 
30 namespace Cantor
31 {
32 class DefaultHighlighterPrivate;
33 
47 class CANTOR_EXPORT DefaultHighlighter : public QSyntaxHighlighter
48 {
49  Q_OBJECT
50  public:
51  DefaultHighlighter(QObject* parent);
52  ~DefaultHighlighter();
53 
57  void setTextItem(QGraphicsTextItem* item);
58 
59  public slots:
63  void positionChanged(QTextCursor);
64 
65  protected:
71  virtual void highlightBlock(const QString& text);
72 
73  bool skipHighlighting(const QString& text);
74 
75  QTextCharFormat functionFormat() const;
76  QTextCharFormat variableFormat() const;
77  QTextCharFormat objectFormat() const;
78  QTextCharFormat keywordFormat() const;
79  QTextCharFormat numberFormat() const;
80  QTextCharFormat operatorFormat() const;
81  QTextCharFormat errorFormat() const;
82  QTextCharFormat commentFormat() const;
83  QTextCharFormat stringFormat() const;
84  QTextCharFormat matchingPairFormat() const;
85  QTextCharFormat mismatchingPairFormat() const;
86 
98  void addPair(const QChar& openSymbol, const QChar& closeSymbol);
104  void addRule(const QString& word, const QTextCharFormat& format);
111  void addRule(const QRegExp& regexp, const QTextCharFormat& format);
112 
122  template <class Container> void addRules(const Container& conditions, const QTextCharFormat& format);
126  template <class Container> void addFunctions(const Container& functions);
130  template <class Container> void addVariables(const Container& variables);
134  template <class Container> void addKeywords(const Container& keywords);
135 
139  void removeRule(const QString& word);
143  void removeRule(const QRegExp& regexp);
148  template <class Container> void removeRules(const Container& conditions);
149 
154  void highlightPairs(const QString& text);
159  void highlightWords(const QString& text);
164  void highlightRegExps(const QString& text);
165 
170  virtual QString nonSeparatingCharacters() const;
171 
172  private slots:
173  void updateFormats();
174 
175  signals:
176  void rulesChanged();
177 
178  private:
179  DefaultHighlighterPrivate* d;
180 };
181 
182 
183 template <class Container>
184 void DefaultHighlighter::addRules(const Container& conditions, const QTextCharFormat& format)
185 {
186  typename Container::const_iterator i = conditions.constBegin();
187  typename Container::const_iterator end = conditions.constEnd();
188  for (;i != end; ++i)
189  {
190  addRule(*i, format);
191  }
192 }
193 
194 template <class Container>
195 void DefaultHighlighter::addFunctions(const Container& functions)
196 {
197  addRules(functions, functionFormat());
198 }
199 
200 template <class Container>
201 void DefaultHighlighter::addKeywords(const Container& keywords)
202 {
203  addRules(keywords, keywordFormat());
204 }
205 
206 template <class Container>
207 void DefaultHighlighter::addVariables(const Container& variables)
208 {
209  addRules(variables, variableFormat());
210 }
211 
212 template <class Container>
213 void DefaultHighlighter::removeRules(const Container& conditions)
214 {
215  typename Container::const_iterator i = conditions.constBegin();
216  typename Container::const_iterator end = conditions.constEnd();
217  for (;i != end; ++i)
218  {
219  removeRule(*i);
220  }
221 }
222 
223 }
224 
225 #endif
Cantor::DefaultHighlighter::keywordFormat
QTextCharFormat keywordFormat() const
Definition: defaulthighlighter.cpp:273
CANTOR_EXPORT
#define CANTOR_EXPORT
Definition: cantor_export.h:33
QTextCursor
QChar
Cantor::DefaultHighlighter::addVariables
void addVariables(const Container &variables)
Convenience method, equivalent to.
Definition: defaulthighlighter.h:207
Cantor::DefaultHighlighter::variableFormat
QTextCharFormat variableFormat() const
Definition: defaulthighlighter.cpp:263
QSyntaxHighlighter
Cantor::DefaultHighlighter::addRules
void addRules(const Container &conditions, const QTextCharFormat &format)
Convenience method, highlights all items in conditions with the specified format. ...
Definition: defaulthighlighter.h:184
QRegExp
Cantor::DefaultHighlighter::addFunctions
void addFunctions(const Container &functions)
Convenience method, equivalent to.
Definition: defaulthighlighter.h:195
Cantor::DefaultHighlighter
The DefaultHighlighter is an implementation QSyntaxHighlighter.
Definition: defaulthighlighter.h:47
Cantor::DefaultHighlighter::removeRules
void removeRules(const Container &conditions)
Convenience method, removes all rules with conditions from conditions.
Definition: defaulthighlighter.h:213
QObject
QGraphicsTextItem
QString
Cantor::DefaultHighlighter::functionFormat
QTextCharFormat functionFormat() const
Definition: defaulthighlighter.cpp:258
QTextCharFormat
Cantor::DefaultHighlighter::addRule
void addRule(const QString &word, const QTextCharFormat &format)
Highlights all instances of the word in the text with the specified format.
Definition: defaulthighlighter.cpp:380
Cantor::DefaultHighlighter::removeRule
void removeRule(const QString &word)
Removes any rules previously added for the word word.
Definition: defaulthighlighter.cpp:395
cantor_export.h
Cantor::DefaultHighlighter::addKeywords
void addKeywords(const Container &keywords)
Convenience method, equivalent to.
Definition: defaulthighlighter.h:201
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:33 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
  • 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