1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * This file has been copied from Nokia's Qt Examples, with minor modifications
11 * made available under the LGPL version 2.1, as the original file was licensed
13 ****************************************************************************
14 ****************************************************************************
16 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
17 ** All rights reserved.
18 ** Contact: Nokia Corporation (qt-info@nokia.com)
20 ** This file is part of the examples of the Qt Toolkit.
22 ** GNU Lesser General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU Lesser
24 ** General Public License version 2.1 as published by the Free Software
25 ** Foundation and appearing in the file LICENSE.LGPL included in the
26 ** packaging of this file. Please review the following information to
27 ** ensure the GNU Lesser General Public License version 2.1 requirements
28 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
30 ** In addition, as a special exception, Nokia gives you certain additional
31 ** rights. These rights are described in the Nokia Qt LGPL Exception
32 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
34 ****************************************************************************/
39 #include <QPlainTextEdit>
43 #include "syntaxcompleter.h"
54 //![codeeditordefinition]
56 class CodeEditor
: public QPlainTextEdit
61 CodeEditor(QWidget
*parent
= 0);
62 virtual ~CodeEditor(){ }
64 void lineNumberAreaPaintEvent(QPaintEvent
*event
);
65 int lineNumberAreaWidth();
66 void addError(int line
){ errors
.append(line
); }
67 void clearErrors(){ errors
.clear(); }
68 void setErrorColor(QColor color
){ errorColor
= color
; }
69 bool isError(int line
){ return errors
.contains(line
); }
70 bool hasErrors(){ return !errors
.isEmpty(); }
73 void resizeEvent(QResizeEvent
*event
);
74 void keyPressEvent(QKeyEvent
*event
);
77 void updateLineNumberAreaWidth(int newBlockCount
);
78 void updateLineNumberArea(const QRect
&, int);
83 QWidget
*lineNumberArea
;
86 SyntaxCompleter completer
;
94 //![codeeditordefinition]
97 class LineNumberArea
: public QWidget
100 LineNumberArea(CodeEditor
*editor
) : QWidget(editor
) {
104 QSize
sizeHint() const {
105 return QSize(codeEditor
->lineNumberAreaWidth(), 0);
109 void paintEvent(QPaintEvent
*event
) {
110 codeEditor
->lineNumberAreaPaintEvent(event
);
114 CodeEditor
*codeEditor
;