QSS Solver GUI  4.5.3
codeeditor.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  This file is part of QSS Solver.
4 
5  QSS Solver is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  QSS Solver is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
17 
18  ******************************************************************************/
19 
20 /****************************************************************************
21  **
22  ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
23  ** All rights reserved.
24  ** Contact: Nokia Corporation (qt-info@nokia.com)
25  **
26  ** This file is part of the examples of the Qt Toolkit.
27  **
28  ** $QT_BEGIN_LICENSE:LGPL$
29  ** Commercial Usage
30  ** Licensees holding valid Qt Commercial licenses may use this file in
31  ** accordance with the Qt Commercial License Agreement provided with the
32  ** Software or, alternatively, in accordance with the terms contained in
33  ** a written agreement between you and Nokia.
34  **
35  ** GNU Lesser General Public License Usage
36  ** Alternatively, this file may be used under the terms of the GNU Lesser
37  ** General Public License version 2.1 as published by the Free Software
38  ** Foundation and appearing in the file LICENSE.LGPL included in the
39  ** packaging of this file. Please review the following information to
40  ** ensure the GNU Lesser General Public License version 2.1 requirements
41  ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
42  **
43  ** In addition, as a special exception, Nokia gives you certain additional
44  ** rights. These rights are described in the Nokia Qt LGPL Exception
45  ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
46  **
47  ** GNU General Public License Usage
48  ** Alternatively, this file may be used under the terms of the GNU
49  ** General Public License version 3.0 as published by the Free Software
50  ** Foundation and appearing in the file LICENSE.GPL included in the
51  ** packaging of this file. Please review the following information to
52  ** ensure the GNU General Public License version 3.0 requirements will be
53  ** met: http://www.gnu.org/copyleft/gpl.html.
54  **
55  ** If you have questions regarding the use of this file, please contact
56  ** Nokia at qt-info@nokia.com.
57  ** $QT_END_LICENSE$
58  **
59  ****************************************************************************/
60 
61 #ifndef CODEEDITOR_H_
62 #define CODEEDITOR_H_
63 
64 #include <QPlainTextEdit>
65 #include <QObject>
66 
67 class QPaintEvent;
68 class QResizeEvent;
69 class QSize;
70 class QWidget;
71 
75 class LineNumberArea;
76 
80 class CodeEditor : public QPlainTextEdit {
81  Q_OBJECT
82 
83  public:
88  CodeEditor(QWidget *parent = 0);
93  void lineNumberAreaPaintEvent(QPaintEvent *event);
98  int lineNumberAreaWidth();
99 
100  protected:
105  void resizeEvent(QResizeEvent *event);
106 
107  private slots:
108  void updateLineNumberAreaWidth(int newBlockCount);
109  void highlightCurrentLine();
110  void updateLineNumberArea(const QRect &, int);
111 
112  private:
113  QWidget *lineNumberArea;
114 };
115 
119 class LineNumberArea : public QWidget {
120  public:
125  LineNumberArea(CodeEditor *editor) : QWidget(editor) { codeEditor = editor; }
130  QSize sizeHint() const { return QSize(codeEditor->lineNumberAreaWidth(), 0); }
131 
132  protected:
133  void paintEvent(QPaintEvent *event) { codeEditor->lineNumberAreaPaintEvent(event); }
134 
135  private:
137 };
138 
139 #endif /* CODEEDITOR_H_ */
LineNumberArea::LineNumberArea
LineNumberArea(CodeEditor *editor)
Definition: codeeditor.hpp:125
CodeEditor::lineNumberAreaWidth
int lineNumberAreaWidth()
Definition: codeeditor.cpp:77
LineNumberArea::paintEvent
void paintEvent(QPaintEvent *event)
Definition: codeeditor.hpp:133
CodeEditor::resizeEvent
void resizeEvent(QResizeEvent *event)
Definition: codeeditor.cpp:106
LineNumberArea
Definition: codeeditor.hpp:119
LineNumberArea::sizeHint
QSize sizeHint() const
Definition: codeeditor.hpp:130
CodeEditor::lineNumberAreaPaintEvent
void lineNumberAreaPaintEvent(QPaintEvent *event)
Definition: codeeditor.cpp:130
CodeEditor::updateLineNumberArea
void updateLineNumberArea(const QRect &, int)
Definition: codeeditor.cpp:93
CodeEditor::updateLineNumberAreaWidth
void updateLineNumberAreaWidth(int newBlockCount)
Definition: codeeditor.cpp:91
CodeEditor
Definition: codeeditor.hpp:80
CodeEditor::CodeEditor
CodeEditor(QWidget *parent=0)
Definition: codeeditor.cpp:65
CodeEditor::lineNumberArea
QWidget * lineNumberArea
Definition: codeeditor.hpp:113
CodeEditor::highlightCurrentLine
void highlightCurrentLine()
Definition: codeeditor.cpp:113
LineNumberArea::codeEditor
CodeEditor * codeEditor
Definition: codeeditor.hpp:136