Theme Editor: Added line numbering in the text editor, thanks to some code from Nokia...
[kugel-rb.git] / utils / themeeditor / codeeditor.h
blobedbe218ec4ba6f84f6de4bf6a39cea45e5464b0b
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>
42 QT_BEGIN_NAMESPACE
43 class QPaintEvent;
44 class QResizeEvent;
45 class QSize;
46 class QWidget;
47 QT_END_NAMESPACE
49 class LineNumberArea;
51 //![codeeditordefinition]
53 class CodeEditor : public QPlainTextEdit
55 Q_OBJECT
57 public:
58 CodeEditor(QWidget *parent = 0);
60 void lineNumberAreaPaintEvent(QPaintEvent *event);
61 int lineNumberAreaWidth();
63 protected:
64 void resizeEvent(QResizeEvent *event);
66 private slots:
67 void updateLineNumberAreaWidth(int newBlockCount);
68 void updateLineNumberArea(const QRect &, int);
70 private:
71 QWidget *lineNumberArea;
74 //![codeeditordefinition]
75 //![extraarea]
77 class LineNumberArea : public QWidget
79 public:
80 LineNumberArea(CodeEditor *editor) : QWidget(editor) {
81 codeEditor = editor;
84 QSize sizeHint() const {
85 return QSize(codeEditor->lineNumberAreaWidth(), 0);
88 protected:
89 void paintEvent(QPaintEvent *event) {
90 codeEditor->lineNumberAreaPaintEvent(event);
93 private:
94 CodeEditor *codeEditor;
97 //![extraarea]
99 #endif