Theme Editor: Made auto-complete functional and enabled it by default. Added a small...
[kugel-rb.git] / utils / themeeditor / gui / codeeditor.h
blob21f1c561cf420129c61baaeb5a7d2823eb5382c0
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
36 #ifndef CODEEDITOR_H
37 #define CODEEDITOR_H
39 #include <QPlainTextEdit>
40 #include <QObject>
41 #include <QSettings>
43 #include "syntaxcompleter.h"
45 QT_BEGIN_NAMESPACE
46 class QPaintEvent;
47 class QResizeEvent;
48 class QSize;
49 class QWidget;
50 QT_END_NAMESPACE
52 class LineNumberArea;
54 //![codeeditordefinition]
56 class CodeEditor : public QPlainTextEdit
58 Q_OBJECT
60 public:
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(); }
72 protected:
73 void resizeEvent(QResizeEvent *event);
74 void keyPressEvent(QKeyEvent *event);
76 private slots:
77 void updateLineNumberAreaWidth(int newBlockCount);
78 void updateLineNumberArea(const QRect &, int);
79 void cursorMoved();
80 void insertTag();
82 private:
83 QWidget *lineNumberArea;
84 QList<int> errors;
85 QColor errorColor;
86 SyntaxCompleter completer;
87 QSettings settings;
89 int tagBegin;
90 int tagEnd;
91 int docLength;
94 //![codeeditordefinition]
95 //![extraarea]
97 class LineNumberArea : public QWidget
99 public:
100 LineNumberArea(CodeEditor *editor) : QWidget(editor) {
101 codeEditor = editor;
104 QSize sizeHint() const {
105 return QSize(codeEditor->lineNumberAreaWidth(), 0);
108 protected:
109 void paintEvent(QPaintEvent *event) {
110 codeEditor->lineNumberAreaPaintEvent(event);
113 private:
114 CodeEditor *codeEditor;
117 //![extraarea]
119 #endif