umbrello  2.31.90
Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology
codetextedit.h
Go to the documentation of this file.
1 /*
2  CodeTextEdit: Text edit widget with line numbers and highlighted current line.
3  Copyright 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  Copyright 2010 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of
11  the License or (at your option) version 3 or any later version
12  accepted by the membership of KDE e.V. (or its successor approved
13  by the membership of KDE e.V.), which shall act as a proxy
14  defined in Section 14 of version 3 of the license.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #ifndef CODETEXTEDIT_H
26 #define CODETEXTEDIT_H
27 
28 #include <QObject>
29 #include <QPlainTextEdit>
30 
31 class QPaintEvent;
32 class QResizeEvent;
33 class QSize;
34 class QWidget;
35 
37 class LineNumberArea;
38 
39 class CodeTextEdit : public QPlainTextEdit
40 {
41  Q_OBJECT
42 
43 public:
44  explicit CodeTextEdit(QWidget *parent = 0);
45 
46  void lineNumberAreaPaintEvent(QPaintEvent *event);
47  int lineNumberAreaWidth();
48 
49 protected:
50  void resizeEvent(QResizeEvent *event);
51 
52 private slots:
53  void updateLineNumberAreaWidth(int newBlockCount);
54  void highlightCurrentLine();
55  void updateLineNumberArea(const QRect &, int);
56 
57 private:
58  QWidget *m_lineNumberArea;
60 };
61 
62 
63 class LineNumberArea : public QWidget
64 {
65 public:
66  explicit LineNumberArea(CodeTextEdit *editor) : QWidget(editor) {
67  m_codeEditor = editor;
68  }
69 
70  QSize sizeHint() const {
71  return QSize(m_codeEditor->lineNumberAreaWidth(), 0);
72  }
73 
74 protected:
75  void paintEvent(QPaintEvent *event) {
77  }
78 
79 private:
81 };
82 
83 #endif // CODETEXTBOX_H
Definition: codetextedit.h:40
void lineNumberAreaPaintEvent(QPaintEvent *event)
Definition: codetextedit.cpp:131
CodeTextEdit(QWidget *parent=0)
Definition: codetextedit.cpp:35
void highlightCurrentLine()
Definition: codetextedit.cpp:109
CodeTextHighlighter * m_highlighter
Definition: codetextedit.h:59
void updateLineNumberArea(const QRect &, int)
Definition: codetextedit.cpp:81
void resizeEvent(QResizeEvent *event)
Definition: codetextedit.cpp:98
QWidget * m_lineNumberArea
Definition: codetextedit.h:58
int lineNumberAreaWidth()
Definition: codetextedit.cpp:53
void updateLineNumberAreaWidth(int newBlockCount)
Definition: codetextedit.cpp:72
Definition: codetexthighlighter.h:35
Definition: codetextedit.h:64
QSize sizeHint() const
Definition: codetextedit.h:70
CodeTextEdit * m_codeEditor
Definition: codetextedit.h:80
void paintEvent(QPaintEvent *event)
Definition: codetextedit.h:75
LineNumberArea(CodeTextEdit *editor)
Definition: codetextedit.h:66