-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeeditor.h
94 lines (76 loc) · 2.52 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
#ifndef CODEEDITOR_H
#define CODEEDITOR_H
#include <QPlainTextEdit>
#include <QObject>
#include <QFileInfo>
#include <QCompleter>
#include <QStringListModel>
#include "syntaxhighlighter.h"
#include "assetmanager.h"
class QPaintEvent;
class QResizeEvent;
class QSize;
class QWidget;
class LineNumberArea;
class CodeEditor : public QPlainTextEdit
{
Q_OBJECT
public:
CodeEditor(QWidget *parent = 0);
~CodeEditor();
void lineNumberAreaPaintEvent(QPaintEvent *event);
void footerBarAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
bool loadFile(const QString &);
QFileInfo * getCurrentFileInfo() const;
void load(AssetManager *am);
void save();
void setAutoCompleter(QCompleter *inCompleter);
QCompleter * getCompleter() const;
QString textUnderCursor() const;
void setAutoCompleteModel(QStringList &);
void changeLanguageSupport(QString supportFileName);
void highlightText(QRegExp &);
void resizeFooter(int height);
AssetManager *assetManager;
SyntaxHighlighter *syntaxHighlighter;
QFileInfo *currentFile;
void setFooterHeight(int height);
void replaceSearchMatchedText(const QString &, QRegExp &);
protected:
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
//void keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
void highlightAndSearchCurrentLine();
void updateLineNumberArea(const QRect &, int);
void insertCompletion(const QString &completion);
private:
QWidget *lineNumberArea;
QWidget *footerBarArea;
QCompleter *completer;
QStringListModel * autoCompleteModel;
QStringList * dynamicAutocompleteSuggestions;
int footerHeight;
int tabStop;
void appendCodeLine(QString &line);
};
class LineNumberArea : public QWidget
{
public:
LineNumberArea(CodeEditor *editor) : QWidget(editor) {
codeEditor = editor;
}
QSize sizeHint() const Q_DECL_OVERRIDE {
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE {
codeEditor->lineNumberAreaPaintEvent(event);
}
private:
CodeEditor *codeEditor;
};
#endif