nsbaci 1.0
Loading...
Searching...
No Matches
codeeditor.h
Go to the documentation of this file.
1
9
10#ifndef CODEEDITOR_H
11#define CODEEDITOR_H
12
13#include <QPlainTextEdit>
14#include <QWidget>
15
16class LineNumberArea;
17
18class CodeEditor : public QPlainTextEdit {
19 Q_OBJECT
20
21 public:
22 explicit CodeEditor(QWidget* parent = nullptr);
23
24 void lineNumberAreaPaintEvent(QPaintEvent* event);
25 int lineNumberAreaWidth();
26
28 void setLineNumbersVisible(bool visible);
29 bool lineNumbersVisible() const;
30
33 void setLightTheme(bool light);
34
35 protected:
36 void resizeEvent(QResizeEvent* event) override;
37 void changeEvent(QEvent* event) override;
38
39 private slots:
40 void updateLineNumberAreaWidth(int newBlockCount);
41 void highlightCurrentLine();
42 void updateLineNumberArea(const QRect& rect, int dy);
43
44 private:
45 LineNumberArea* lineNumberArea;
46 bool showLineNumbers = true;
47 bool lightTheme = false;
48};
49
50class LineNumberArea : public QWidget {
51 public:
52 explicit LineNumberArea(CodeEditor* editor)
53 : QWidget(editor), codeEditor(editor) {}
54
55 QSize sizeHint() const override {
56 return QSize(codeEditor->lineNumberAreaWidth(), 0);
57 }
58
59 protected:
60 void paintEvent(QPaintEvent* event) override {
61 codeEditor->lineNumberAreaPaintEvent(event);
62 }
63
64 private:
65 CodeEditor* codeEditor;
66};
67
68#endif // CODEEDITOR_H
Definition codeeditor.h:18
void setLightTheme(bool light)
Set whether to use light theme colors for line numbers and highlights.
Definition codeeditor.cpp:38
void setLineNumbersVisible(bool visible)
Show or hide the line number gutter.
Definition codeeditor.cpp:30
Definition codeeditor.h:50