2018-01-01 09:22:11 +01:00
|
|
|
#ifndef CODEEDITOR_H
|
|
|
|
#define CODEEDITOR_H
|
|
|
|
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
class QPaintEvent;
|
|
|
|
class QResizeEvent;
|
|
|
|
class QSize;
|
|
|
|
class QWidget;
|
|
|
|
|
|
|
|
class LineNumberArea;
|
|
|
|
|
|
|
|
|
2018-01-01 10:52:51 +01:00
|
|
|
class CodeEditor : public QPlainTextEdit {
|
2018-01-01 09:22:11 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-01-01 10:52:51 +01:00
|
|
|
explicit CodeEditor(QWidget *parent = 0);
|
2018-01-01 09:22:11 +01:00
|
|
|
|
|
|
|
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
|
|
|
int lineNumberAreaWidth();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void updateLineNumberAreaWidth(int newBlockCount);
|
|
|
|
void highlightCurrentLine();
|
|
|
|
void updateLineNumberArea(const QRect &, int);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QWidget *lineNumberArea;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-01-01 10:52:51 +01:00
|
|
|
class LineNumberArea : public QWidget {
|
2018-01-01 09:22:11 +01:00
|
|
|
public:
|
2018-01-01 10:52:51 +01:00
|
|
|
explicit LineNumberArea(CodeEditor *editor) : QWidget(editor) {
|
2018-01-01 09:22:11 +01:00
|
|
|
codeEditor = editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize sizeHint() const override {
|
|
|
|
return QSize(codeEditor->lineNumberAreaWidth(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *event) override {
|
|
|
|
codeEditor->lineNumberAreaPaintEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CodeEditor *codeEditor;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CODEEDITOR_H
|