-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwingcodeedit.h
More file actions
326 lines (251 loc) · 9.14 KB
/
wingcodeedit.h
File metadata and controls
326 lines (251 loc) · 9.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/****************************************************************************
**
** Copyright (C) 2025-2028 WingSummer
**
** This file may be used under the terms of the GNU General Public License
** version 3 as published by the Free Software Foundation.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the GNU General Public License version 3
** along with this program. If not, see <https://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef WINGCODEEDIT_H
#define WINGCODEEDIT_H
#include "wingsignaturetooltip.h"
#include <KSyntaxHighlighting/Theme>
#include <QPlainTextEdit>
#include <QTextBlock>
namespace KSyntaxHighlighting {
class Repository;
class Definition;
class Theme;
} // namespace KSyntaxHighlighting
class WingSyntaxHighlighter;
class WingCompleter;
class WingLineMargin;
class QPrinter;
class WingCodeEdit : public QPlainTextEdit {
Q_OBJECT
friend class WingLineMargin;
friend class WingSquiggleInfoModel;
public:
enum class IndentationMode { IndentSpaces, IndentTabs, IndentMixed };
Q_ENUM(IndentationMode)
struct SearchParams {
QString searchText;
bool caseSensitive = false;
bool wholeWord = false;
bool regex = false;
};
public:
enum class SeverityLevel { Hint, Information, Warning, Error };
private:
enum class WingCodeEditConfig {
ShowLineNumbers = (1U << 0),
AutoIndent = (1U << 1),
MatchBraces = (1U << 2),
HighlightCurLine = (1U << 3),
IndentGuides = (1U << 4),
LongLineEdge = (1U << 5),
ShowFolding = (1U << 6),
ShowSymbolMark = (1U << 7),
AutoCloseChar = (1U << 8)
};
Q_DECLARE_FLAGS(WingCodeEditConfigs, WingCodeEditConfig)
public:
explicit WingCodeEdit(QWidget *parent = nullptr);
public:
void deleteSelection();
void deleteLines();
int lineMarginWidth() const;
int symbolMarkSize() const;
int realSymbolMarkSizeWithPadding() const;
bool showLineNumbers() const;
bool showFolding() const;
bool showSymbolMark() const;
bool showWhitespace() const;
bool scrollPastEndOfFile() const;
bool highlightCurrentLine() const;
int tabWidth() const;
int indentWidth() const;
IndentationMode indentationMode() const;
int textColumn(const QString &block, int positionInBlock) const;
void moveCursorTo(int line, int column = 0);
void moveLines(QTextCursor::MoveOperation op);
void smartHome(QTextCursor::MoveMode mode);
void smartEnd(QTextCursor::MoveMode mode);
void setAutoIndent(bool ai);
bool autoIndent() const;
bool showLongLineEdge() const;
int longLineWidth() const;
bool showIndentGuides() const;
bool wordWrap() const;
bool autoCloseChar() const;
bool isCurrentLineFolded() const;
QTextCursor textSearch(const QTextCursor &start, const SearchParams ¶ms,
bool matchFirst, bool reverse = false,
QRegularExpressionMatch *regexMatch = nullptr);
void setLiveSearch(const SearchParams ¶ms);
void clearLiveSearch();
void setMatchBraces(bool match);
bool matchBraces() const;
static KSyntaxHighlighting::Repository &syntaxRepo();
static const KSyntaxHighlighting::Definition &nullSyntax();
void setDefaultFont(const QFont &font);
QString themeName() const;
QString syntaxName() const;
QFont defaultFont() const;
WingCompleter *completer() const;
WingSyntaxHighlighter *highlighter() const;
KSyntaxHighlighting::Theme theme() const;
QString symbolMark(int line) const;
bool isHelpTooltipVisible() const;
void setHighlighter(WingSyntaxHighlighter *newHighlighter);
public:
/**
* @brief squiggle Puts a underline squiggle under text ranges in Editor
* @param level defines the color of the underline depending upon the
* severity
* @param tooltipMessage The tooltip hover message to show when over
* selection.
* @note QPair<int, int>: first -> Line number in 1-based indexing
* second -> Character number in 0-based indexing
*/
void addSquiggle(SeverityLevel level, const QPair<int, int> &start,
const QPair<int, int> &stop,
const QString &tooltipMessage);
void highlightAllSquiggle();
/**
* @brief clearSquiggle, Clears complete squiggle from editor
*/
void clearSquiggle();
signals:
void symbolMarkLineMarginClicked(int line);
void squiggleItemChanged();
void themeChanged();
public slots:
void setShowLineNumbers(bool show);
void setShowFolding(bool show);
void setShowSymbolMark(bool show);
void setShowLongLineEdge(bool show);
void setLongLineWidth(int pos);
void setShowIndentGuides(bool show);
void setWordWrap(bool wrap);
void setAutoCloseChar(bool b);
void setShowWhitespace(bool show);
void setScrollPastEndOfFile(bool scroll);
void setHighlightCurrentLine(bool show);
void setTabWidth(int width);
void setIndentWidth(int width);
void setIndentationMode(WingCodeEdit::IndentationMode mode);
void setCompleter(WingCompleter *completer);
void setDefaultTheme();
void setTheme(const KSyntaxHighlighting::Theme &theme);
void setSyntax(const KSyntaxHighlighting::Definition &syntax);
void addSymbolMark(int line, const QString &id);
void removeSymbolMark(int line);
void ensureLineVisible(int lineNumber);
void showHelpTooltip(const QList<WingSignatureTooltip::Signature> &sigs,
qsizetype index = 0);
void hideHelpTooltip();
private:
QString cursorNextChar(const QTextCursor &cursor);
QString cursorPrevChar(const QTextCursor &cursor);
QString textUnderCursor() const;
private:
bool isAutoCloseChar(const QString &ch) const;
bool isPairedCloseChar(const QString &ch) const;
QString getPairedBeginChar(const QString &ch) const;
QString getPairedCloseChar(const QString &ch) const;
QTextBlock getCursorPositionBlock(int position) const;
protected:
bool event(QEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void wheelEvent(QWheelEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void focusInEvent(QFocusEvent *e) override;
void insertFromMimeData(const QMimeData *source) override;
protected:
bool processCompletionBegin(QKeyEvent *e);
bool processCompletionEnd(QKeyEvent *e);
void processDefaultKeyPressEvent(QKeyEvent *e);
private:
bool processKeyShortcut(QKeyEvent *e);
struct SquiggleInformation {
SquiggleInformation(SeverityLevel level, const QPair<int, int> &start,
const QPair<int, int> &stop, const QString &text)
: level(level), start(start), stop(stop), tooltip(text) {}
SeverityLevel level;
QPair<int, int> start;
QPair<int, int> stop;
QString tooltip;
};
void highlightSquiggle(const SquiggleInformation &info);
protected:
virtual void highlightOccurrences();
protected slots:
virtual void onCompletion(const QModelIndex &index);
public slots:
void cutLines();
void copyLines();
void indentSelection();
void outdentSelection();
void foldCurrentLine();
void unfoldCurrentLine();
void foldAll();
void unfoldAll();
void zoomIn(); // Hides QPlainTextEdit::zoomIn(int = 1)
void zoomOut(); // Hides QPlainTextEdit::zoomOut(int = 1)
void zoomReset();
void printDocument(QPrinter *printer);
private slots:
void updateMargins();
void repaintMargins();
void updateLineNumbers(const QRect &rect, int dy);
void updateCursor();
void updateTabMetrics();
void updateTextMetrics();
void updateLiveSearch();
protected slots:
void updateExtraSelections();
private:
WingCompleter *m_completer;
WingLineMargin *m_lineMargin;
WingSyntaxHighlighter *m_highlighter;
WingSignatureTooltip *m_sighlp;
// color caches
QColor m_lineMarginBg, m_lineMarginFg;
QColor m_codeFoldingBg, m_codeFoldingFg;
QColor m_cursorLineBg, m_cursorLineNum;
QColor m_longLineBg, m_longLineEdge, m_longLineCursorBg;
QColor m_indentGuideFg;
QColor m_searchBg;
QColor m_braceMatchBg;
QColor m_errorBg;
QColor m_warnBg;
QColor m_textSelBg;
QColor m_errorFg;
QColor m_warnFg;
QColor m_infoFg;
QVector<SquiggleInformation> m_squiggles;
int m_tabCharSize, m_indentWidth;
int m_longLineMarker;
WingCodeEditConfigs m_config;
IndentationMode m_indentationMode;
int m_originalFontSize;
QColor m_editorBg;
QPixmap m_foldOpen, m_foldClosed;
SearchParams m_liveSearch;
QList<QTextEdit::ExtraSelection> m_braceMatch;
QList<QTextEdit::ExtraSelection> m_searchResults;
QList<QTextEdit::ExtraSelection> m_squigglesExtraSelections,
m_squigglesLineExtraSelections;
void updateScrollBars();
protected:
QList<QTextEdit::ExtraSelection> m_occurrencesExtraSelections;
};
#endif // WINGCODEEDIT_H