summaryrefslogtreecommitdiff
path: root/utils/themeeditor/gui/codeeditor.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/gui/codeeditor.h')
-rw-r--r--utils/themeeditor/gui/codeeditor.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/utils/themeeditor/gui/codeeditor.h b/utils/themeeditor/gui/codeeditor.h
new file mode 100644
index 0000000000..1771e31051
--- /dev/null
+++ b/utils/themeeditor/gui/codeeditor.h
@@ -0,0 +1,106 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
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
12 *
13 ****************************************************************************
14 ****************************************************************************
15**
16** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
17** All rights reserved.
18** Contact: Nokia Corporation (qt-info@nokia.com)
19**
20** This file is part of the examples of the Qt Toolkit.
21**
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.
29**
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.
33**
34****************************************************************************/
35
36#ifndef CODEEDITOR_H
37#define CODEEDITOR_H
38
39#include <QPlainTextEdit>
40#include <QObject>
41
42QT_BEGIN_NAMESPACE
43class QPaintEvent;
44class QResizeEvent;
45class QSize;
46class QWidget;
47QT_END_NAMESPACE
48
49class LineNumberArea;
50
51//![codeeditordefinition]
52
53class CodeEditor : public QPlainTextEdit
54{
55 Q_OBJECT
56
57public:
58 CodeEditor(QWidget *parent = 0);
59
60 void lineNumberAreaPaintEvent(QPaintEvent *event);
61 int lineNumberAreaWidth();
62 void addError(int line){ errors.append(line); }
63 void clearErrors(){ errors.clear(); }
64 void setErrorColor(QColor color){ errorColor = color; }
65 bool isError(int line){ return errors.contains(line); }
66 bool hasErrors(){ return !errors.isEmpty(); }
67
68protected:
69 void resizeEvent(QResizeEvent *event);
70
71private slots:
72 void updateLineNumberAreaWidth(int newBlockCount);
73 void updateLineNumberArea(const QRect &, int);
74
75private:
76 QWidget *lineNumberArea;
77 QList<int> errors;
78 QColor errorColor;
79};
80
81//![codeeditordefinition]
82//![extraarea]
83
84class LineNumberArea : public QWidget
85{
86public:
87 LineNumberArea(CodeEditor *editor) : QWidget(editor) {
88 codeEditor = editor;
89 }
90
91 QSize sizeHint() const {
92 return QSize(codeEditor->lineNumberAreaWidth(), 0);
93 }
94
95protected:
96 void paintEvent(QPaintEvent *event) {
97 codeEditor->lineNumberAreaPaintEvent(event);
98 }
99
100private:
101 CodeEditor *codeEditor;
102};
103
104//![extraarea]
105
106#endif