source: trunk/src/gui/text/qtextdocument.h@ 371

Last change on this file since 371 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 8.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QTEXTDOCUMENT_H
43#define QTEXTDOCUMENT_H
44
45#include <QtCore/qobject.h>
46#include <QtCore/qsize.h>
47#include <QtCore/qrect.h>
48#include <QtGui/qfont.h>
49
50QT_BEGIN_HEADER
51
52QT_BEGIN_NAMESPACE
53
54QT_MODULE(Gui)
55
56class QTextFormatCollection;
57class QTextListFormat;
58class QRect;
59class QPainter;
60class QPrinter;
61class QAbstractTextDocumentLayout;
62class QPoint;
63class QTextCursor;
64class QTextObject;
65class QTextFormat;
66class QTextFrame;
67class QTextBlock;
68class QTextCodec;
69class QUrl;
70class QVariant;
71class QRectF;
72class QTextOption;
73
74template<typename T> class QVector;
75
76namespace Qt
77{
78 enum HitTestAccuracy { ExactHit, FuzzyHit };
79 enum WhiteSpaceMode {
80 WhiteSpaceNormal,
81 WhiteSpacePre,
82 WhiteSpaceNoWrap,
83 WhiteSpaceModeUndefined = -1
84 };
85
86 Q_GUI_EXPORT bool mightBeRichText(const QString&);
87 Q_GUI_EXPORT QString escape(const QString& plain);
88 Q_GUI_EXPORT QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode = WhiteSpacePre);
89
90#ifndef QT_NO_TEXTCODEC
91 Q_GUI_EXPORT QTextCodec *codecForHtml(const QByteArray &ba);
92#endif
93}
94
95class Q_GUI_EXPORT QAbstractUndoItem
96{
97public:
98 virtual ~QAbstractUndoItem() = 0;
99 virtual void undo() = 0;
100 virtual void redo() = 0;
101};
102
103inline QAbstractUndoItem::~QAbstractUndoItem()
104{
105}
106
107class QTextDocumentPrivate;
108
109class Q_GUI_EXPORT QTextDocument : public QObject
110{
111 Q_OBJECT
112
113 Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
114 Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
115 Q_PROPERTY(QSizeF pageSize READ pageSize WRITE setPageSize)
116 Q_PROPERTY(QFont defaultFont READ defaultFont WRITE setDefaultFont)
117 Q_PROPERTY(bool useDesignMetrics READ useDesignMetrics WRITE setUseDesignMetrics)
118 Q_PROPERTY(QSizeF size READ size)
119 Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth)
120 Q_PROPERTY(int blockCount READ blockCount)
121 Q_PROPERTY(qreal indentWidth READ indentWidth WRITE setIndentWidth)
122#ifndef QT_NO_CSSPARSER
123 Q_PROPERTY(QString defaultStyleSheet READ defaultStyleSheet WRITE setDefaultStyleSheet)
124#endif
125 Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
126 Q_PROPERTY(qreal documentMargin READ documentMargin WRITE setDocumentMargin)
127 QDOC_PROPERTY(QTextOption defaultTextOption READ defaultTextOption WRITE setDefaultTextOption)
128
129public:
130 explicit QTextDocument(QObject *parent = 0);
131 explicit QTextDocument(const QString &text, QObject *parent = 0);
132 ~QTextDocument();
133
134 QTextDocument *clone(QObject *parent = 0) const;
135
136 bool isEmpty() const;
137 virtual void clear();
138
139 void setUndoRedoEnabled(bool enable);
140 bool isUndoRedoEnabled() const;
141
142 bool isUndoAvailable() const;
143 bool isRedoAvailable() const;
144
145 int revision() const;
146
147 void setDocumentLayout(QAbstractTextDocumentLayout *layout);
148 QAbstractTextDocumentLayout *documentLayout() const;
149
150 enum MetaInformation {
151 DocumentTitle,
152 DocumentUrl
153 };
154 void setMetaInformation(MetaInformation info, const QString &);
155 QString metaInformation(MetaInformation info) const;
156
157#ifndef QT_NO_TEXTHTMLPARSER
158 QString toHtml(const QByteArray &encoding = QByteArray()) const;
159 void setHtml(const QString &html);
160#endif
161
162 QString toPlainText() const;
163 void setPlainText(const QString &text);
164
165 QChar characterAt(int pos) const;
166
167 enum FindFlag
168 {
169 FindBackward = 0x00001,
170 FindCaseSensitively = 0x00002,
171 FindWholeWords = 0x00004
172 };
173 Q_DECLARE_FLAGS(FindFlags, FindFlag)
174
175 QTextCursor find(const QString &subString, int from = 0, FindFlags options = 0) const;
176 QTextCursor find(const QString &subString, const QTextCursor &from, FindFlags options = 0) const;
177
178 QTextCursor find(const QRegExp &expr, int from = 0, FindFlags options = 0) const;
179 QTextCursor find(const QRegExp &expr, const QTextCursor &from, FindFlags options = 0) const;
180
181 QTextFrame *frameAt(int pos) const;
182 QTextFrame *rootFrame() const;
183
184 QTextObject *object(int objectIndex) const;
185 QTextObject *objectForFormat(const QTextFormat &) const;
186
187 QTextBlock findBlock(int pos) const;
188 QTextBlock findBlockByNumber(int blockNumber) const;
189 QTextBlock findBlockByLineNumber(int blockNumber) const;
190 QTextBlock begin() const;
191 QTextBlock end() const;
192
193 QTextBlock firstBlock() const;
194 QTextBlock lastBlock() const;
195
196 void setPageSize(const QSizeF &size);
197 QSizeF pageSize() const;
198
199 void setDefaultFont(const QFont &font);
200 QFont defaultFont() const;
201
202 int pageCount() const;
203
204 bool isModified() const;
205
206#ifndef QT_NO_PRINTER
207 void print(QPrinter *printer) const;
208#endif
209
210 enum ResourceType {
211 HtmlResource = 1,
212 ImageResource = 2,
213 StyleSheetResource = 3,
214
215 UserResource = 100
216 };
217
218 QVariant resource(int type, const QUrl &name) const;
219 void addResource(int type, const QUrl &name, const QVariant &resource);
220
221 QVector<QTextFormat> allFormats() const;
222
223 void markContentsDirty(int from, int length);
224
225 void setUseDesignMetrics(bool b);
226 bool useDesignMetrics() const;
227
228 void drawContents(QPainter *painter, const QRectF &rect = QRectF());
229
230 void setTextWidth(qreal width);
231 qreal textWidth() const;
232
233 qreal idealWidth() const;
234
235 qreal indentWidth() const;
236 void setIndentWidth(qreal width);
237
238 qreal documentMargin() const;
239 void setDocumentMargin(qreal margin);
240
241 void adjustSize();
242 QSizeF size() const;
243
244 int blockCount() const;
245 int lineCount() const;
246 int characterCount() const;
247
248#ifndef QT_NO_CSSPARSER
249 void setDefaultStyleSheet(const QString &sheet);
250 QString defaultStyleSheet() const;
251#endif
252
253 void undo(QTextCursor *cursor);
254 void redo(QTextCursor *cursor);
255
256 int maximumBlockCount() const;
257 void setMaximumBlockCount(int maximum);
258
259 QTextOption defaultTextOption() const;
260 void setDefaultTextOption(const QTextOption &option);
261
262Q_SIGNALS:
263 void contentsChange(int from, int charsRemoves, int charsAdded);
264 void contentsChanged();
265 void undoAvailable(bool);
266 void redoAvailable(bool);
267 void undoCommandAdded();
268 void modificationChanged(bool m);
269 void cursorPositionChanged(const QTextCursor &cursor);
270 void blockCountChanged(int newBlockCount);
271
272 void documentLayoutChanged();
273
274public Q_SLOTS:
275 void undo();
276 void redo();
277 void appendUndoItem(QAbstractUndoItem *);
278 void setModified(bool m = true);
279
280protected:
281 virtual QTextObject *createObject(const QTextFormat &f);
282 virtual QVariant loadResource(int type, const QUrl &name);
283
284 QTextDocument(QTextDocumentPrivate &dd, QObject *parent);
285public:
286 QTextDocumentPrivate *docHandle() const;
287private:
288 Q_DISABLE_COPY(QTextDocument)
289 Q_DECLARE_PRIVATE(QTextDocument)
290 friend class QTextObjectPrivate;
291};
292
293Q_DECLARE_OPERATORS_FOR_FLAGS(QTextDocument::FindFlags)
294
295QT_END_NAMESPACE
296
297QT_END_HEADER
298
299#endif // QTEXTDOCUMENT_H
Note: See TracBrowser for help on using the repository browser.