OSDN Git Service

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