OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / texteditor / syntaxhighlighter.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef TEXTEDITOR_SYNTAXHIGHLIGHTER_H
43 #define TEXTEDITOR_SYNTAXHIGHLIGHTER_H
44
45 #include "texteditor_global.h"
46 #include <QtCore/qglobal.h>
47 #include <QtCore/qobject.h>
48 #include <QtGui/qtextobject.h>
49 #include <QtGui/QTextLayout>
50
51 QT_BEGIN_NAMESPACE
52 class QTextDocument;
53 class QSyntaxHighlighterPrivate;
54 class QTextCharFormat;
55 class QFont;
56 class QColor;
57 class QTextBlockUserData;
58 class QTextEdit;
59 QT_END_NAMESPACE
60
61 namespace TextEditor {
62
63 class SyntaxHighlighterPrivate;
64
65 class TEXTEDITOR_EXPORT SyntaxHighlighter : public QObject
66 {
67     Q_OBJECT
68     Q_DECLARE_PRIVATE(SyntaxHighlighter)
69 public:
70     SyntaxHighlighter(QObject *parent);
71     SyntaxHighlighter(QTextDocument *parent);
72     SyntaxHighlighter(QTextEdit *parent);
73     virtual ~SyntaxHighlighter();
74
75     void setDocument(QTextDocument *doc);
76     QTextDocument *document() const;
77
78     void setExtraAdditionalFormats(const QTextBlock& block, const QList<QTextLayout::FormatRange> &formats);
79
80 public Q_SLOTS:
81     void rehighlight();
82     void rehighlightBlock(const QTextBlock &block);
83
84 protected:
85     virtual void highlightBlock(const QString &text) = 0;
86
87     void setFormat(int start, int count, const QTextCharFormat &format);
88     void setFormat(int start, int count, const QColor &color);
89     void setFormat(int start, int count, const QFont &font);
90     QTextCharFormat format(int pos) const;
91
92     void applyFormatToSpaces(const QString &text, const QTextCharFormat &format);
93
94     int previousBlockState() const;
95     int currentBlockState() const;
96     void setCurrentBlockState(int newState);
97
98     void setCurrentBlockUserData(QTextBlockUserData *data);
99     QTextBlockUserData *currentBlockUserData() const;
100
101     QTextBlock currentBlock() const;
102
103 private:
104     Q_DISABLE_COPY(SyntaxHighlighter)
105     Q_PRIVATE_SLOT(d_ptr, void _q_reformatBlocks(int from, int charsRemoved, int charsAdded))
106     Q_PRIVATE_SLOT(d_ptr, void _q_delayedRehighlight())
107
108     QScopedPointer<SyntaxHighlighterPrivate> d_ptr;
109 };
110
111 } // end of namespace TextEditor
112
113 #endif // TEXTEDITOR_SYNTAXHIGHLIGHTER_H