57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#ifndef CODEEDITOR_H
|
|
#define CODEEDITOR_H
|
|
|
|
#include <QPlainTextEdit>
|
|
#include <QObject>
|
|
|
|
class QPaintEvent;
|
|
class QResizeEvent;
|
|
class QSize;
|
|
class QWidget;
|
|
|
|
class LineNumberArea;
|
|
|
|
|
|
class CodeEditor : public QPlainTextEdit {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit CodeEditor(QWidget *parent = 0);
|
|
|
|
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;
|
|
};
|
|
|
|
|
|
class LineNumberArea : public QWidget {
|
|
public:
|
|
explicit 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);
|
|
}
|
|
|
|
private:
|
|
CodeEditor *codeEditor;
|
|
};
|
|
|
|
#endif // CODEEDITOR_H
|