-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeeditor.h
More file actions
50 lines (41 loc) · 1.17 KB
/
codeeditor.h
File metadata and controls
50 lines (41 loc) · 1.17 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
/***********************************************
gSafe document editor
Author:
(C) 2026 Deák Péter (hyper80@gmail.com)
*/
#pragma once
#include <QPlainTextEdit>
#include <QWidget>
#include <QSize>
class QPaintEvent;
class QResizeEvent;
class QRect;
class QKeyEvent;
class LineNumberArea;
class CodeEditor : public QPlainTextEdit
{
Q_OBJECT
public:
explicit CodeEditor(QWidget *parent = nullptr);
void keyPressEvent(QKeyEvent *e) override;
int lineNumberAreaWidth();
void lineNumberAreaPaintEvent(QPaintEvent *event);
protected:
void resizeEvent(QResizeEvent *event) override;
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
void updateLineNumberArea(const QRect &rect, int dy);
private:
void highlightCurrentLine();
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;
};