2010-04-26 14:02:09 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef BASETEXTDOCUMENTLAYOUT_H
|
|
|
|
|
#define BASETEXTDOCUMENTLAYOUT_H
|
|
|
|
|
|
|
|
|
|
#include "texteditor_global.h"
|
|
|
|
|
|
|
|
|
|
#include "itexteditor.h"
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QTextBlockUserData>
|
|
|
|
|
#include <QtGui/QPlainTextDocumentLayout>
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
|
|
|
|
struct Parenthesis;
|
|
|
|
|
typedef QVector<Parenthesis> Parentheses;
|
|
|
|
|
|
|
|
|
|
struct TEXTEDITOR_EXPORT Parenthesis
|
|
|
|
|
{
|
|
|
|
|
enum Type { Opened, Closed };
|
|
|
|
|
|
|
|
|
|
inline Parenthesis() : type(Opened), pos(-1) {}
|
|
|
|
|
inline Parenthesis(Type t, QChar c, int position)
|
|
|
|
|
: type(t), chr(c), pos(position) {}
|
|
|
|
|
Type type;
|
|
|
|
|
QChar chr;
|
|
|
|
|
int pos;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TEXTEDITOR_EXPORT TextBlockUserData : public QTextBlockUserData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
inline TextBlockUserData()
|
2010-05-20 15:10:26 +02:00
|
|
|
: m_folded(false),
|
|
|
|
|
m_ifdefedOut(false),
|
|
|
|
|
m_foldingIndent(0),
|
|
|
|
|
m_foldingStartIncluded(false),
|
|
|
|
|
m_foldingEndIncluded(false){}
|
2010-04-26 14:02:09 +02:00
|
|
|
~TextBlockUserData();
|
|
|
|
|
|
|
|
|
|
inline TextMarks marks() const { return m_marks; }
|
|
|
|
|
inline void addMark(ITextMark *mark) { m_marks += mark; }
|
|
|
|
|
inline bool removeMark(ITextMark *mark) { return m_marks.removeAll(mark); }
|
|
|
|
|
inline bool hasMark(ITextMark *mark) const { return m_marks.contains(mark); }
|
|
|
|
|
inline void clearMarks() { m_marks.clear(); }
|
|
|
|
|
inline void documentClosing() { Q_FOREACH(ITextMark *tm, m_marks) { tm->documentClosing(); } m_marks.clear();}
|
|
|
|
|
|
2010-05-20 15:10:26 +02:00
|
|
|
inline void setFolded(bool b) { m_folded = b; }
|
|
|
|
|
inline bool folded() const { return m_folded; }
|
2010-04-26 14:02:09 +02:00
|
|
|
|
|
|
|
|
inline void setParentheses(const Parentheses &parentheses) { m_parentheses = parentheses; }
|
|
|
|
|
inline void clearParentheses() { m_parentheses.clear(); }
|
|
|
|
|
inline const Parentheses &parentheses() const { return m_parentheses; }
|
|
|
|
|
inline bool hasParentheses() const { return !m_parentheses.isEmpty(); }
|
|
|
|
|
int braceDepthDelta() const;
|
|
|
|
|
|
|
|
|
|
inline bool setIfdefedOut() { bool result = m_ifdefedOut; m_ifdefedOut = true; return !result; }
|
|
|
|
|
inline bool clearIfdefedOut() { bool result = m_ifdefedOut; m_ifdefedOut = false; return result;}
|
|
|
|
|
inline bool ifdefedOut() const { return m_ifdefedOut; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum MatchType { NoMatch, Match, Mismatch };
|
|
|
|
|
static MatchType checkOpenParenthesis(QTextCursor *cursor, QChar c);
|
|
|
|
|
static MatchType checkClosedParenthesis(QTextCursor *cursor, QChar c);
|
|
|
|
|
static MatchType matchCursorBackward(QTextCursor *cursor);
|
|
|
|
|
static MatchType matchCursorForward(QTextCursor *cursor);
|
|
|
|
|
static bool findPreviousOpenParenthesis(QTextCursor *cursor, bool select = false);
|
|
|
|
|
static bool findNextClosingParenthesis(QTextCursor *cursor, bool select = false);
|
|
|
|
|
|
|
|
|
|
static bool findPreviousBlockOpenParenthesis(QTextCursor *cursor, bool checkStartPosition = false);
|
|
|
|
|
static bool findNextBlockClosingParenthesis(QTextCursor *cursor);
|
|
|
|
|
|
2010-05-20 15:10:26 +02:00
|
|
|
int foldingIndent() const { return m_foldingIndent; }
|
|
|
|
|
void setFoldingIndent(int indent) { m_foldingIndent = indent; }
|
|
|
|
|
void setFoldingStartIncluded(bool included) { m_foldingStartIncluded = included; }
|
|
|
|
|
bool foldingStartIncluded() const { return m_foldingStartIncluded; }
|
|
|
|
|
void setFoldingEndIncluded(bool included) { m_foldingEndIncluded = included; }
|
|
|
|
|
bool foldingEndIncluded() const { return m_foldingEndIncluded; }
|
|
|
|
|
|
2010-04-26 14:02:09 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TextMarks m_marks;
|
2010-05-20 15:10:26 +02:00
|
|
|
uint m_folded : 1;
|
2010-04-26 14:02:09 +02:00
|
|
|
uint m_ifdefedOut : 1;
|
2010-05-20 15:10:26 +02:00
|
|
|
uint m_foldingIndent : 16;
|
|
|
|
|
uint m_foldingStartIncluded : 1;
|
|
|
|
|
uint m_foldingEndIncluded : 1;
|
2010-04-26 14:02:09 +02:00
|
|
|
Parentheses m_parentheses;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2010-04-26 14:06:29 +02:00
|
|
|
class TEXTEDITOR_EXPORT BaseTextDocumentLayout : public QPlainTextDocumentLayout
|
2010-04-26 14:02:09 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2010-04-26 14:06:29 +02:00
|
|
|
BaseTextDocumentLayout(QTextDocument *doc);
|
|
|
|
|
~BaseTextDocumentLayout();
|
2010-04-26 14:02:09 +02:00
|
|
|
|
|
|
|
|
static void setParentheses(const QTextBlock &block, const Parentheses &parentheses);
|
|
|
|
|
static void clearParentheses(const QTextBlock &block) { setParentheses(block, Parentheses());}
|
|
|
|
|
static Parentheses parentheses(const QTextBlock &block);
|
|
|
|
|
static bool hasParentheses(const QTextBlock &block);
|
|
|
|
|
static bool setIfdefedOut(const QTextBlock &block);
|
|
|
|
|
static bool clearIfdefedOut(const QTextBlock &block);
|
|
|
|
|
static bool ifdefedOut(const QTextBlock &block);
|
|
|
|
|
static int braceDepthDelta(const QTextBlock &block);
|
|
|
|
|
static int braceDepth(const QTextBlock &block);
|
|
|
|
|
static void setBraceDepth(QTextBlock &block, int depth);
|
|
|
|
|
static void changeBraceDepth(QTextBlock &block, int delta);
|
2010-05-20 15:10:26 +02:00
|
|
|
static void setFoldingIndent(const QTextBlock &block, int indent);
|
|
|
|
|
static int foldingIndent(const QTextBlock &block);
|
|
|
|
|
static void changeFoldingIndent(QTextBlock &block, int delta);
|
|
|
|
|
static bool canFold(const QTextBlock &block);
|
|
|
|
|
static void doFoldOrUnfold(const QTextBlock& block, bool unfold);
|
|
|
|
|
static bool isFolded(const QTextBlock &block);
|
|
|
|
|
static void setFolded(const QTextBlock &block, bool folded);
|
2010-04-26 14:02:09 +02:00
|
|
|
|
|
|
|
|
static TextBlockUserData *testUserData(const QTextBlock &block) {
|
|
|
|
|
return static_cast<TextBlockUserData*>(block.userData());
|
|
|
|
|
}
|
|
|
|
|
static TextBlockUserData *userData(const QTextBlock &block) {
|
|
|
|
|
TextBlockUserData *data = static_cast<TextBlockUserData*>(block.userData());
|
|
|
|
|
if (!data && block.isValid())
|
|
|
|
|
const_cast<QTextBlock &>(block).setUserData((data = new TextBlockUserData));
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void emitDocumentSizeChanged() { emit documentSizeChanged(documentSize()); }
|
|
|
|
|
int lastSaveRevision;
|
|
|
|
|
bool hasMarks;
|
2010-07-02 13:47:14 +02:00
|
|
|
|
|
|
|
|
int m_requiredWidth;
|
|
|
|
|
void setRequiredWidth(int width);
|
|
|
|
|
|
|
|
|
|
QSizeF documentSize() const;
|
2010-04-26 14:02:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace TextEditor
|
|
|
|
|
|
|
|
|
|
#endif // BASETEXTDOCUMENTLAYOUT_H
|