umbrello 26.07.70-c53146a Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

codetextedit.h
Go to the documentation of this file.
1/*
2 CodeTextEdit: Text edit widget with line numbers and highlighted current line.
3 SPDX-FileCopyrightText: 2010 Nokia Corporation and /or its subsidiary(-ies) <qt-info@nokia.com>
4 Code based on examples of the Qt Toolkit under BSD license,
5 <http://doc.qt.nokia.com/4.6/widgets-codeeditor.html>.
6 SPDX-FileCopyrightText: 2010 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
9*/
10
11#ifndef CODETEXTEDIT_H
12#define CODETEXTEDIT_H
13
14#include <QObject>
15#include <QPlainTextEdit>
16
17 class QPaintEvent;
18 class QResizeEvent;
19 class QSize;
20 class QWidget;
21
22 class CodeTextHighlighter;
23 class LineNumberArea;
24
25 class CodeTextEdit : public QPlainTextEdit
26{
27 Q_OBJECT
28
29 public:
30 explicit CodeTextEdit(QWidget *parent = nullptr);
31
32 void lineNumberAreaPaintEvent(QPaintEvent *event);
33 int lineNumberAreaWidth();
34
35 protected:
36 void resizeEvent(QResizeEvent *event);
37
38 private Q_SLOTS:
39 void updateLineNumberAreaWidth(int newBlockCount);
40 void highlightCurrentLine();
41 void updateLineNumberArea(const QRect &, int);
42
43 private:
44 QWidget *m_lineNumberArea;
45 CodeTextHighlighter *m_highlighter;
46};
47
48
49 class LineNumberArea : public QWidget
50{
51 public:
52 explicit LineNumberArea(CodeTextEdit *editor) : QWidget(editor) {
53 m_codeEditor = editor;
54 }
55
56 QSize sizeHint() const {
57 return QSize(m_codeEditor->lineNumberAreaWidth(), 0);
58 }
59
60 protected:
61 void paintEvent(QPaintEvent *event) {
62 m_codeEditor->lineNumberAreaPaintEvent(event);
63 }
64
65 private:
66 CodeTextEdit *m_codeEditor;
67};
68
69#endif // CODETEXTBOX_H
CodeTextEdit
Definition: codetextedit.h:26
CodeTextEdit::lineNumberAreaPaintEvent
void lineNumberAreaPaintEvent(QPaintEvent *event)
Definition: codetextedit.cpp:117
CodeTextEdit::highlightCurrentLine
void highlightCurrentLine()
Definition: codetextedit.cpp:95
CodeTextEdit::m_highlighter
CodeTextHighlighter * m_highlighter
Definition: codetextedit.h:45
CodeTextEdit::updateLineNumberArea
void updateLineNumberArea(const QRect &, int)
Definition: codetextedit.cpp:67
CodeTextEdit::resizeEvent
void resizeEvent(QResizeEvent *event)
Definition: codetextedit.cpp:84
CodeTextEdit::m_lineNumberArea
QWidget * m_lineNumberArea
Definition: codetextedit.h:44
CodeTextEdit::lineNumberAreaWidth
int lineNumberAreaWidth()
Definition: codetextedit.cpp:39
CodeTextEdit::updateLineNumberAreaWidth
void updateLineNumberAreaWidth(int newBlockCount)
Definition: codetextedit.cpp:58
CodeTextHighlighter
Definition: codetexthighlighter.h:22
LineNumberArea
Definition: codetextedit.h:50
LineNumberArea::sizeHint
QSize sizeHint() const
Definition: codetextedit.h:56
LineNumberArea::m_codeEditor
CodeTextEdit * m_codeEditor
Definition: codetextedit.h:66
LineNumberArea::paintEvent
void paintEvent(QPaintEvent *event)
Definition: codetextedit.h:61
LineNumberArea::LineNumberArea
LineNumberArea(CodeTextEdit *editor)
Definition: codetextedit.h:52