2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-07-09 14:47:18 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-07-09 14:47:18 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-07-09 14:47:18 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-07-09 14:47:18 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-07-09 14:47:18 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-07-09 14:47:18 +02:00
|
|
|
|
|
|
|
|
#ifndef TEXTEDITOR_SYNTAXHIGHLIGHTER_H
|
|
|
|
|
#define TEXTEDITOR_SYNTAXHIGHLIGHTER_H
|
|
|
|
|
|
|
|
|
|
#include "texteditor_global.h"
|
2013-08-13 12:57:31 +02:00
|
|
|
#include <texteditor/texteditorconstants.h>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QTextLayout>
|
2010-07-09 14:47:18 +02:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QTextDocument;
|
|
|
|
|
class QSyntaxHighlighterPrivate;
|
|
|
|
|
class QTextCharFormat;
|
|
|
|
|
class QFont;
|
|
|
|
|
class QColor;
|
|
|
|
|
class QTextBlockUserData;
|
|
|
|
|
class QTextEdit;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
2013-08-13 12:57:31 +02:00
|
|
|
class FontSettings;
|
2010-07-09 14:47:18 +02:00
|
|
|
class SyntaxHighlighterPrivate;
|
|
|
|
|
|
|
|
|
|
class TEXTEDITOR_EXPORT SyntaxHighlighter : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_DECLARE_PRIVATE(SyntaxHighlighter)
|
|
|
|
|
public:
|
2014-08-27 13:38:02 +02:00
|
|
|
SyntaxHighlighter(QObject *parent = 0);
|
2010-07-09 14:47:18 +02:00
|
|
|
SyntaxHighlighter(QTextDocument *parent);
|
|
|
|
|
SyntaxHighlighter(QTextEdit *parent);
|
|
|
|
|
virtual ~SyntaxHighlighter();
|
|
|
|
|
|
|
|
|
|
void setDocument(QTextDocument *doc);
|
|
|
|
|
QTextDocument *document() const;
|
|
|
|
|
|
2013-02-26 11:17:13 +01:00
|
|
|
void setExtraAdditionalFormats(const QTextBlock& block, QList<QTextLayout::FormatRange> &formats);
|
2010-07-13 14:37:31 +02:00
|
|
|
|
2012-11-15 16:57:11 +01:00
|
|
|
static QList<QColor> generateColors(int n, const QColor &background);
|
|
|
|
|
|
2013-08-13 12:57:31 +02:00
|
|
|
// Don't call in constructors of derived classes
|
|
|
|
|
virtual void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
2010-07-09 14:47:18 +02:00
|
|
|
public Q_SLOTS:
|
|
|
|
|
void rehighlight();
|
|
|
|
|
void rehighlightBlock(const QTextBlock &block);
|
|
|
|
|
|
|
|
|
|
protected:
|
2013-08-13 12:57:31 +02:00
|
|
|
void setTextFormatCategories(const QVector<TextEditor::TextStyle> &categories);
|
|
|
|
|
QTextCharFormat formatForCategory(int categoryIndex) const;
|
2010-07-09 14:47:18 +02:00
|
|
|
virtual void highlightBlock(const QString &text) = 0;
|
|
|
|
|
|
|
|
|
|
void setFormat(int start, int count, const QTextCharFormat &format);
|
|
|
|
|
void setFormat(int start, int count, const QColor &color);
|
|
|
|
|
void setFormat(int start, int count, const QFont &font);
|
|
|
|
|
QTextCharFormat format(int pos) const;
|
|
|
|
|
|
2010-09-30 09:12:59 +02:00
|
|
|
void applyFormatToSpaces(const QString &text, const QTextCharFormat &format);
|
|
|
|
|
|
2010-07-09 14:47:18 +02:00
|
|
|
int previousBlockState() const;
|
|
|
|
|
int currentBlockState() const;
|
|
|
|
|
void setCurrentBlockState(int newState);
|
|
|
|
|
|
|
|
|
|
void setCurrentBlockUserData(QTextBlockUserData *data);
|
|
|
|
|
QTextBlockUserData *currentBlockUserData() const;
|
|
|
|
|
|
|
|
|
|
QTextBlock currentBlock() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Q_PRIVATE_SLOT(d_ptr, void _q_reformatBlocks(int from, int charsRemoved, int charsAdded))
|
|
|
|
|
Q_PRIVATE_SLOT(d_ptr, void _q_delayedRehighlight())
|
|
|
|
|
|
|
|
|
|
QScopedPointer<SyntaxHighlighterPrivate> d_ptr;
|
|
|
|
|
};
|
|
|
|
|
|
2011-02-04 09:52:39 +01:00
|
|
|
} // namespace TextEditor
|
2010-07-09 14:47:18 +02:00
|
|
|
|
|
|
|
|
#endif // TEXTEDITOR_SYNTAXHIGHLIGHTER_H
|