Changeset View
Changeset View
Standalone View
Standalone View
src/lib/defaulthighlighter.h
Show All 24 Lines | |||||
25 | 25 | | |||
26 | #include <QSyntaxHighlighter> | 26 | #include <QSyntaxHighlighter> | ||
27 | 27 | | |||
28 | class QGraphicsTextItem; | 28 | class QGraphicsTextItem; | ||
29 | 29 | | |||
30 | namespace Cantor | 30 | namespace Cantor | ||
31 | { | 31 | { | ||
32 | class DefaultHighlighterPrivate; | 32 | class DefaultHighlighterPrivate; | ||
33 | class Session; | ||||
33 | 34 | | |||
34 | /** | 35 | /** | ||
35 | * The DefaultHighlighter is an implementation QSyntaxHighlighter. | 36 | * The DefaultHighlighter is an implementation QSyntaxHighlighter. | ||
36 | * It covers most common cases of syntax highlighting for Cantor's command entries. | 37 | * It covers most common cases of syntax highlighting for Cantor's command entries. | ||
37 | * | 38 | * | ||
38 | * When creating a custom highlighter, for example for a new backend, you should use | 39 | * When creating a custom highlighter, for example for a new backend, you should use | ||
39 | * the provided functions addPairs(), addRule() and/or addRules(). | 40 | * the provided functions addPairs(), addRule() and/or addRules(). | ||
40 | * | 41 | * | ||
41 | * If you need more specific functionality, subclass highlightBlock(). Usually it's a good idea to also call | 42 | * If you need more specific functionality, subclass highlightBlock(). Usually it's a good idea to also call | ||
42 | * DefaultHighlighter's implementation from it. | 43 | * DefaultHighlighter's implementation from it. | ||
43 | * | 44 | * | ||
44 | * @author Alexander Rieder | 45 | * @author Alexander Rieder | ||
45 | */ | 46 | */ | ||
46 | 47 | | |||
47 | class CANTOR_EXPORT DefaultHighlighter : public QSyntaxHighlighter | 48 | class CANTOR_EXPORT DefaultHighlighter : public QSyntaxHighlighter | ||
48 | { | 49 | { | ||
49 | Q_OBJECT | 50 | Q_OBJECT | ||
50 | public: | 51 | public: | ||
51 | explicit DefaultHighlighter(QObject* parent); | 52 | explicit DefaultHighlighter(QObject* parent); | ||
53 | explicit DefaultHighlighter(QObject* parent, Session* session); | ||||
52 | ~DefaultHighlighter() override; | 54 | ~DefaultHighlighter() override; | ||
53 | 55 | | |||
54 | /** | 56 | /** | ||
55 | * Change the item being highlighted. | 57 | * Change the item being highlighted. | ||
56 | */ | 58 | */ | ||
57 | void setTextItem(QGraphicsTextItem* item); | 59 | void setTextItem(QGraphicsTextItem* item); | ||
58 | 60 | | |||
59 | public Q_SLOTS: | 61 | public Q_SLOTS: | ||
60 | /** | 62 | /** | ||
61 | * Called when the cursor moved. Rehighlights accordingly. | 63 | * Called when the cursor moved. Rehighlights accordingly. | ||
62 | */ | 64 | */ | ||
63 | void positionChanged(const QTextCursor&); | 65 | void positionChanged(const QTextCursor&); | ||
64 | 66 | | |||
67 | protected Q_SLOTS: | ||||
68 | /** | ||||
69 | * Convenience method, equivalent to @code addRules(functions, functionFormat()) @endcode | ||||
70 | */ | ||||
71 | void addFunctions(const QStringList& functions); | ||||
72 | /** | ||||
73 | * Convenience method, equivalent to @code addRules(variables, variableFormat()) @endcode | ||||
74 | */ | ||||
75 | void addVariables(const QStringList& variables); | ||||
76 | /** | ||||
77 | * Removes any rules previously added for the word @p word | ||||
78 | */ | ||||
79 | void removeRule(const QString& word); | ||||
80 | /** | ||||
81 | * Convenience method, removes all rules with conditions from @p conditions | ||||
82 | * @sa removeRule, addRules | ||||
83 | */ | ||||
84 | void removeRules(const QStringList& conditions); | ||||
85 | | ||||
65 | protected: | 86 | protected: | ||
66 | /** | 87 | /** | ||
67 | * This method is called by Cantor's KTextEdit and is where all the highlighting must take place. | 88 | * This method is called by Cantor's KTextEdit and is where all the highlighting must take place. | ||
68 | * The default implementation calls highlightPairs(), highlightWords() and highlightRegExps(). | 89 | * The default implementation calls highlightPairs(), highlightWords() and highlightRegExps(). | ||
69 | * | 90 | * | ||
70 | */ | 91 | */ | ||
71 | void highlightBlock(const QString& text) override; | 92 | void highlightBlock(const QString& text) override; | ||
72 | 93 | | |||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
117 | * greenWords << "tree" << "forest" << "grass"; | 138 | * greenWords << "tree" << "forest" << "grass"; | ||
118 | * addRules(greenWords, greenWordFormat); | 139 | * addRules(greenWords, greenWordFormat); | ||
119 | * @endcode | 140 | * @endcode | ||
120 | * @param conditions any Qt container of QRegExp or QString. | 141 | * @param conditions any Qt container of QRegExp or QString. | ||
121 | * @param format the format used to display the matching parts of the text | 142 | * @param format the format used to display the matching parts of the text | ||
122 | */ | 143 | */ | ||
123 | void addRules(const QStringList& conditions, const QTextCharFormat& format); | 144 | void addRules(const QStringList& conditions, const QTextCharFormat& format); | ||
124 | /** | 145 | /** | ||
125 | * Convenience method, equivalent to @code addRules(functions, functionFormat()) @endcode | | |||
126 | */ | | |||
127 | void addFunctions(const QStringList& functions); | | |||
128 | /** | | |||
129 | * Convenience method, equivalent to @code addRules(variables, variableFormat()) @endcode | | |||
130 | */ | | |||
131 | void addVariables(const QStringList& variables); | | |||
132 | /** | | |||
133 | * Convenience method, equivalent to @code addRules(keywords, keywordFormat()) @endcode | 146 | * Convenience method, equivalent to @code addRules(keywords, keywordFormat()) @endcode | ||
134 | */ | 147 | */ | ||
135 | void addKeywords(const QStringList& keywords); | 148 | void addKeywords(const QStringList& keywords); | ||
136 | | ||||
137 | /** | | |||
138 | * Removes any rules previously added for the word @p word | | |||
139 | */ | | |||
140 | void removeRule(const QString& word); | | |||
141 | /** | 149 | /** | ||
142 | * Removes any rules previously added for the regular expression @p regexp | 150 | * Removes any rules previously added for the regular expression @p regexp | ||
143 | */ | 151 | */ | ||
144 | void removeRule(const QRegExp& regexp); | 152 | void removeRule(const QRegExp& regexp); | ||
145 | /** | | |||
146 | * Convenience method, removes all rules with conditions from @p conditions | | |||
147 | * @sa removeRule, addRules | | |||
148 | */ | | |||
149 | void removeRules(const QStringList& conditions); | | |||
150 | 153 | | |||
151 | /** | 154 | /** | ||
152 | * Highlight pairs added with addPair() | 155 | * Highlight pairs added with addPair() | ||
153 | * @sa addPair | 156 | * @sa addPair | ||
154 | */ | 157 | */ | ||
155 | void highlightPairs(const QString& text); | 158 | void highlightPairs(const QString& text); | ||
156 | /** | 159 | /** | ||
157 | * Highlights words added with addRule() | 160 | * Highlights words added with addRule() | ||
Show All 27 Lines |