-
Notifications
You must be signed in to change notification settings - Fork 7
/
codeeditor.h
106 lines (87 loc) · 2.71 KB
/
codeeditor.h
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
#ifndef CODEEDITOR_H
#define CODEEDITOR_H
#include "baseplaintextedit.h"
QT_BEGIN_NAMESPACE
class QPaintEvent;
class QResizeEvent;
class QSize;
class QWidget;
class QCompleter;
QT_END_NAMESPACE
class LineNumberArea;
class CodeEditor : public BasePlainTextEdit
{
Q_OBJECT
public:
CodeEditor(QWidget *parent = nullptr);
~CodeEditor();
void lineNumberAreaPaintEvent(QPaintEvent *event);
void lineNumberAreaMousePressEvent(QMouseEvent *event);
int lineNumberAreaWidth();
QMenu *getContextMenu();
void setCompleter(QCompleter *c);
QCompleter *completer() const;
QString textUnderCursor() const;
void repaintLineNumberArea();
QList<int> bookmarks;
QString getHelpWord();
bool getShowAllChars(){ return showAllChars; };
void setShowAllChars(bool value){ showAllChars = value; };
void setAutoCompletion(bool value) {cAutoCompletion=value;}
void setTabSpaceCount(int value) { tabSpaceCount = value;}
void setTabSpace(bool value) { tabSpace = value;}
protected:
void resizeEvent(QResizeEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
void focusInEvent(QFocusEvent *e) override;
void keyPressEvent(QKeyEvent *event) override;
bool event(QEvent *event) override;
bool eventFilter(QObject *obj, QEvent *event) override;
public slots:
void highlightCurrentLine();
void insertCompletion(const QString &completion);
void setBookmarkOnCurrentLine();
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
void updateLineNumberArea(const QRect &rect, int dy);
private:
QWidget *lineNumberArea;
QCompleter *c = nullptr;
QPixmap bookmarkImage;
int bookmarkAreaWidth;
QString tooltipWord;
bool tooltipShowing;
bool showAllChars;
bool cAutoCompletion;
int tabSpaceCount;
bool tabSpace;
signals:
void bookmarksChanged(quint64 lineNumber, QString text, bool isAdded);
void updateLineNumber(quint64 currentLine, int delta);
void showFindDialog();
void overWriteModeChanged();
void AfterEnterSendLine(QString line);
};
class LineNumberArea : public QWidget
{
public:
LineNumberArea(CodeEditor *editor) : QWidget(editor), codeEditor(editor)
{
}
QSize sizeHint() const override
{
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event) override
{
codeEditor->lineNumberAreaPaintEvent(event);
}
void mousePressEvent(QMouseEvent *event) override
{
codeEditor->lineNumberAreaMousePressEvent(event);
}
private:
CodeEditor *codeEditor;
};
#endif