Qt 4.8
qtextdocument.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
51 
53 
54 QT_MODULE(Gui)
55 
57 class QTextListFormat;
58 class QRect;
59 class QPainter;
60 class QPrinter;
62 class QPoint;
63 class QTextObject;
64 class QTextFormat;
65 class QTextFrame;
66 class QTextBlock;
67 class QTextCodec;
68 class QUrl;
69 class QVariant;
70 class QRectF;
71 class QTextOption;
72 class QTextCursor;
73 
74 template<typename T> class QVector;
75 
76 namespace Qt
77 {
84  };
85 
87  Q_GUI_EXPORT QString escape(const QString& plain);
89 
90 #ifndef QT_NO_TEXTCODEC
92 #endif
93 }
94 
96 {
97 public:
98  virtual ~QAbstractUndoItem() = 0;
99  virtual void undo() = 0;
100  virtual void redo() = 0;
101 };
102 
104 {
105 }
106 
108 
110 {
111  Q_OBJECT
112 
114  bool modified;
122 #ifndef QT_NO_CSSPARSER
124 #endif
127  QDOC_PROPERTY(QTextOption defaultTextOption READ defaultTextOption WRITE setDefaultTextOption)
128 
129 public:
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 availableUndoSteps() const;
146  int availableRedoSteps() const;
147 
148  int revision() const;
149 
150  void setDocumentLayout(QAbstractTextDocumentLayout *layout);
151  QAbstractTextDocumentLayout *documentLayout() const;
152 
155  DocumentUrl
156  };
157  void setMetaInformation(MetaInformation info, const QString &);
158  QString metaInformation(MetaInformation info) const;
159 
160 #ifndef QT_NO_TEXTHTMLPARSER
161  QString toHtml(const QByteArray &encoding = QByteArray()) const;
162  void setHtml(const QString &html);
163 #endif
164 
165  QString toPlainText() const;
166  void setPlainText(const QString &text);
167 
168  QChar characterAt(int pos) const;
169 
170  enum FindFlag
171  {
172  FindBackward = 0x00001,
173  FindCaseSensitively = 0x00002,
174  FindWholeWords = 0x00004
175  };
176  Q_DECLARE_FLAGS(FindFlags, FindFlag)
177 
178  QTextCursor find(const QString &subString, int from = 0, FindFlags options = 0) const;
179  QTextCursor find(const QString &subString, const QTextCursor &from, FindFlags options = 0) const;
180 
181  QTextCursor find(const QRegExp &expr, int from = 0, FindFlags options = 0) const;
182  QTextCursor find(const QRegExp &expr, const QTextCursor &from, FindFlags options = 0) const;
183 
184  QTextFrame *frameAt(int pos) const;
185  QTextFrame *rootFrame() const;
186 
187  QTextObject *object(int objectIndex) const;
188  QTextObject *objectForFormat(const QTextFormat &) const;
189 
190  QTextBlock findBlock(int pos) const;
191  QTextBlock findBlockByNumber(int blockNumber) const;
192  QTextBlock findBlockByLineNumber(int blockNumber) const;
193  QTextBlock begin() const;
194  QTextBlock end() const;
195 
196  QTextBlock firstBlock() const;
197  QTextBlock lastBlock() const;
198 
199  void setPageSize(const QSizeF &size);
200  QSizeF pageSize() const;
201 
202  void setDefaultFont(const QFont &font);
203  QFont defaultFont() const;
204 
205  int pageCount() const;
206 
207  bool isModified() const;
208 
209 #ifndef QT_NO_PRINTER
210  void print(QPrinter *printer) const;
211 #endif
212 
214  HtmlResource = 1,
215  ImageResource = 2,
216  StyleSheetResource = 3,
217 
218  UserResource = 100
219  };
220 
221  QVariant resource(int type, const QUrl &name) const;
222  void addResource(int type, const QUrl &name, const QVariant &resource);
223 
224  QVector<QTextFormat> allFormats() const;
225 
226  void markContentsDirty(int from, int length);
227 
228  void setUseDesignMetrics(bool b);
229  bool useDesignMetrics() const;
230 
231  void drawContents(QPainter *painter, const QRectF &rect = QRectF());
232 
233  void setTextWidth(qreal width);
234  qreal textWidth() const;
235 
236  qreal idealWidth() const;
237 
238  qreal indentWidth() const;
239  void setIndentWidth(qreal width);
240 
241  qreal documentMargin() const;
242  void setDocumentMargin(qreal margin);
243 
244  void adjustSize();
245  QSizeF size() const;
246 
247  int blockCount() const;
248  int lineCount() const;
249  int characterCount() const;
250 
251 #ifndef QT_NO_CSSPARSER
252  void setDefaultStyleSheet(const QString &sheet);
253  QString defaultStyleSheet() const;
254 #endif
255 
256  void undo(QTextCursor *cursor);
257  void redo(QTextCursor *cursor);
258 
259  enum Stacks {
260  UndoStack = 0x01,
261  RedoStack = 0x02,
262  UndoAndRedoStacks = UndoStack | RedoStack
263  };
264  void clearUndoRedoStacks(Stacks historyToClear = UndoAndRedoStacks);
265 
266  int maximumBlockCount() const;
267  void setMaximumBlockCount(int maximum);
268 
269  QTextOption defaultTextOption() const;
270  void setDefaultTextOption(const QTextOption &option);
271 
272  Qt::CursorMoveStyle defaultCursorMoveStyle() const;
273  void setDefaultCursorMoveStyle(Qt::CursorMoveStyle style);
274 
275 Q_SIGNALS:
276  void contentsChange(int from, int charsRemoves, int charsAdded);
277  void contentsChanged();
278  void undoAvailable(bool);
279  void redoAvailable(bool);
280  void undoCommandAdded();
281  void modificationChanged(bool m);
282  void cursorPositionChanged(const QTextCursor &cursor);
283  void blockCountChanged(int newBlockCount);
284 
285  void documentLayoutChanged();
286 
287 public Q_SLOTS:
288  void undo();
289  void redo();
290  void appendUndoItem(QAbstractUndoItem *);
291  void setModified(bool m = true);
292 
293 protected:
294  virtual QTextObject *createObject(const QTextFormat &f);
295  virtual QVariant loadResource(int type, const QUrl &name);
296 
298 public:
299  QTextDocumentPrivate *docHandle() const;
300 private:
304 };
305 
307 
309 
311 
312 #endif // QTEXTDOCUMENT_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QSizeF pageSize
the page size that should be used for laying out the document
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642
static mach_timebase_info_data_t info
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QDOC_PROPERTY(text)
Definition: qglobal.h:2503
Q_GUI_EXPORT QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode=WhiteSpacePre)
Converts the plain text string plain to an HTML-formatted paragraph while preserving most of its look...
#define QT_MODULE(x)
Definition: qglobal.h:2783
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
int blockCount
Returns the number of text blocks in the document.
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
int maximumBlockCount
Specifies the limit for blocks in the document.
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
HitTestAccuracy
Definition: qtextdocument.h:78
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFont defaultFont
the default font used to display the document&#39;s text
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
ResourceType
This enum describes the types of resources that can be loaded by QTextDocument&#39;s loadResource() funct...
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static bool isEmpty(const char *str)
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
The QTextFormat class provides formatting information for a QTextDocument.
Definition: qtextformat.h:129
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
const char * name
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
const char * layout
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
QSizeF size
Returns the actual size of the document.
bool modified
whether the document has been modified by the user
bool undoRedoEnabled
whether undo/redo are enabled for this document
#define Q_OBJECT
Definition: qobjectdefs.h:157
Q_GUI_EXPORT QString escape(const QString &plain)
Converts the plain text string plain to a HTML string with HTML metacharacters <, >...
MetaInformation
This enum describes the different types of meta information that can be added to a document...
QString defaultStyleSheet
The default style sheet is applied to all newly HTML formatted text that is inserted into the documen...
FindFlag
This enum describes the options available to QTextDocument&#39;s find function.
CursorMoveStyle
This enum describes the movement style available to text cursors.
Definition: qnamespace.h:1790
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
WhiteSpaceMode
Definition: qtextdocument.h:79
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
qreal documentMargin
The margin around the document.
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
virtual ~QAbstractUndoItem()=0
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62
#define class
The QTextObject class is a base class for different kinds of objects that can group parts of a QTextD...
Definition: qtextobject.h:64
static const KeyPair *const end
qreal indentWidth
Returns the width used for text list and text block indenting.
#define QT_END_HEADER
Definition: qglobal.h:137
#define text
Definition: qobjectdefs.h:80
bool useDesignMetrics
whether the document uses design metrics of fonts to improve the accuracy of text layout ...
static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo, const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd)
qreal textWidth
The text width specifies the preferred width for text in the document.
Q_GUI_EXPORT QTextCodec * codecForHtml(const QByteArray &ba)
This function is defined in the <QTextDocument> header file.
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...