1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QTEXTDOCUMENT_H
43 #define QTEXTDOCUMENT_H
45 #include <QtCore/qobject.h>
46 #include <QtCore/qsize.h>
47 #include <QtCore/qrect.h>
48 #include <QtGui/qfont.h>
55 class QTextFormatCollection;
56 class QTextListFormat;
59 class QPagedPaintDevice;
60 class QAbstractTextDocumentLayout;
73 template<typename T> class QVector;
77 enum HitTestAccuracy { ExactHit, FuzzyHit };
82 WhiteSpaceModeUndefined = -1
85 Q_GUI_EXPORT bool mightBeRichText(const QString&);
86 Q_GUI_EXPORT QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode = WhiteSpacePre);
88 #ifndef QT_NO_TEXTCODEC
89 Q_GUI_EXPORT QTextCodec *codecForHtml(const QByteArray &ba);
93 class Q_GUI_EXPORT QAbstractUndoItem
96 virtual ~QAbstractUndoItem() = 0;
97 virtual void undo() = 0;
98 virtual void redo() = 0;
101 inline QAbstractUndoItem::~QAbstractUndoItem()
105 class QTextDocumentPrivate;
107 class Q_GUI_EXPORT QTextDocument : public QObject
111 Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
112 Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
113 Q_PROPERTY(QSizeF pageSize READ pageSize WRITE setPageSize)
114 Q_PROPERTY(QFont defaultFont READ defaultFont WRITE setDefaultFont)
115 Q_PROPERTY(bool useDesignMetrics READ useDesignMetrics WRITE setUseDesignMetrics)
116 Q_PROPERTY(QSizeF size READ size)
117 Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth)
118 Q_PROPERTY(int blockCount READ blockCount)
119 Q_PROPERTY(qreal indentWidth READ indentWidth WRITE setIndentWidth)
120 #ifndef QT_NO_CSSPARSER
121 Q_PROPERTY(QString defaultStyleSheet READ defaultStyleSheet WRITE setDefaultStyleSheet)
123 Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
124 Q_PROPERTY(qreal documentMargin READ documentMargin WRITE setDocumentMargin)
125 QDOC_PROPERTY(QTextOption defaultTextOption READ defaultTextOption WRITE setDefaultTextOption)
128 explicit QTextDocument(QObject *parent = 0);
129 explicit QTextDocument(const QString &text, QObject *parent = 0);
132 QTextDocument *clone(QObject *parent = 0) const;
134 bool isEmpty() const;
135 virtual void clear();
137 void setUndoRedoEnabled(bool enable);
138 bool isUndoRedoEnabled() const;
140 bool isUndoAvailable() const;
141 bool isRedoAvailable() const;
143 int availableUndoSteps() const;
144 int availableRedoSteps() const;
146 int revision() const;
148 void setDocumentLayout(QAbstractTextDocumentLayout *layout);
149 QAbstractTextDocumentLayout *documentLayout() const;
151 enum MetaInformation {
155 void setMetaInformation(MetaInformation info, const QString &);
156 QString metaInformation(MetaInformation info) const;
158 #ifndef QT_NO_TEXTHTMLPARSER
159 QString toHtml(const QByteArray &encoding = QByteArray()) const;
160 void setHtml(const QString &html);
163 QString toPlainText() const;
164 void setPlainText(const QString &text);
166 QChar characterAt(int pos) const;
170 FindBackward = 0x00001,
171 FindCaseSensitively = 0x00002,
172 FindWholeWords = 0x00004
174 Q_DECLARE_FLAGS(FindFlags, FindFlag)
176 QTextCursor find(const QString &subString, int from = 0, FindFlags options = 0) const;
177 QTextCursor find(const QString &subString, const QTextCursor &from, FindFlags options = 0) const;
179 QTextCursor find(const QRegExp &expr, int from = 0, FindFlags options = 0) const;
180 QTextCursor find(const QRegExp &expr, const QTextCursor &from, FindFlags options = 0) const;
182 QTextFrame *frameAt(int pos) const;
183 QTextFrame *rootFrame() const;
185 QTextObject *object(int objectIndex) const;
186 QTextObject *objectForFormat(const QTextFormat &) const;
188 QTextBlock findBlock(int pos) const;
189 QTextBlock findBlockByNumber(int blockNumber) const;
190 QTextBlock findBlockByLineNumber(int blockNumber) const;
191 QTextBlock begin() const;
192 QTextBlock end() const;
194 QTextBlock firstBlock() const;
195 QTextBlock lastBlock() const;
197 void setPageSize(const QSizeF &size);
198 QSizeF pageSize() const;
200 void setDefaultFont(const QFont &font);
201 QFont defaultFont() const;
203 int pageCount() const;
205 bool isModified() const;
207 void print(QPagedPaintDevice *printer) const;
212 StyleSheetResource = 3,
217 QVariant resource(int type, const QUrl &name) const;
218 void addResource(int type, const QUrl &name, const QVariant &resource);
220 QVector<QTextFormat> allFormats() const;
222 void markContentsDirty(int from, int length);
224 void setUseDesignMetrics(bool b);
225 bool useDesignMetrics() const;
227 void drawContents(QPainter *painter, const QRectF &rect = QRectF());
229 void setTextWidth(qreal width);
230 qreal textWidth() const;
232 qreal idealWidth() const;
234 qreal indentWidth() const;
235 void setIndentWidth(qreal width);
237 qreal documentMargin() const;
238 void setDocumentMargin(qreal margin);
243 int blockCount() const;
244 int lineCount() const;
245 int characterCount() const;
247 #ifndef QT_NO_CSSPARSER
248 void setDefaultStyleSheet(const QString &sheet);
249 QString defaultStyleSheet() const;
252 void undo(QTextCursor *cursor);
253 void redo(QTextCursor *cursor);
258 UndoAndRedoStacks = UndoStack | RedoStack
260 void clearUndoRedoStacks(Stacks historyToClear = UndoAndRedoStacks);
262 int maximumBlockCount() const;
263 void setMaximumBlockCount(int maximum);
265 QTextOption defaultTextOption() const;
266 void setDefaultTextOption(const QTextOption &option);
268 Qt::CursorMoveStyle defaultCursorMoveStyle() const;
269 void setDefaultCursorMoveStyle(Qt::CursorMoveStyle style);
272 void contentsChange(int from, int charsRemoves, int charsAdded);
273 void contentsChanged();
274 void undoAvailable(bool);
275 void redoAvailable(bool);
276 void undoCommandAdded();
277 void modificationChanged(bool m);
278 void cursorPositionChanged(const QTextCursor &cursor);
279 void blockCountChanged(int newBlockCount);
281 void documentLayoutChanged();
286 void appendUndoItem(QAbstractUndoItem *);
287 void setModified(bool m = true);
290 virtual QTextObject *createObject(const QTextFormat &f);
291 virtual QVariant loadResource(int type, const QUrl &name);
293 QTextDocument(QTextDocumentPrivate &dd, QObject *parent);
295 QTextDocumentPrivate *docHandle() const;
297 Q_DISABLE_COPY(QTextDocument)
298 Q_DECLARE_PRIVATE(QTextDocument)
299 friend class QTextObjectPrivate;
302 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextDocument::FindFlags)
308 #endif // QTEXTDOCUMENT_H