Qt 4.8
qtextobject.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 QTEXTOBJECT_H
43 #define QTEXTOBJECT_H
44 
45 #include <QtCore/qobject.h>
46 #include <QtGui/qtextformat.h>
47 #include <QtGui/qglyphrun.h>
48 
50 
52 
53 QT_MODULE(Gui)
54 
55 class QTextObjectPrivate;
56 class QTextDocument;
58 class QTextCursor;
59 class QTextBlock;
60 class QTextFragment;
61 class QTextLayout;
62 class QTextList;
63 
65 {
66  Q_OBJECT
67 
68 protected:
69  explicit QTextObject(QTextDocument *doc);
70  ~QTextObject();
71 
72  void setFormat(const QTextFormat &format);
73 
74 public:
75  QTextFormat format() const;
76  int formatIndex() const;
77 
78  QTextDocument *document() const;
79 
80  int objectIndex() const;
81 
82  QTextDocumentPrivate *docHandle() const;
83 
84 protected:
86 
87 private:
91 };
92 
95 {
96  Q_OBJECT
97 
98 protected:
99  explicit QTextBlockGroup(QTextDocument *doc);
100  ~QTextBlockGroup();
101 
102  virtual void blockInserted(const QTextBlock &block);
103  virtual void blockRemoved(const QTextBlock &block);
104  virtual void blockFormatChanged(const QTextBlock &block);
105 
106  QList<QTextBlock> blockList() const;
107 
108 protected:
109  QTextBlockGroup(QTextBlockGroupPrivate &p, QTextDocument *doc);
110 private:
113  friend class QTextDocumentPrivate;
114 };
115 
117 public:
118  virtual ~QTextFrameLayoutData();
119 };
120 
121 class QTextFramePrivate;
123 {
124  Q_OBJECT
125 
126 public:
127  explicit QTextFrame(QTextDocument *doc);
128  ~QTextFrame();
129 
130  inline void setFrameFormat(const QTextFrameFormat &format);
132 
133  QTextCursor firstCursorPosition() const;
134  QTextCursor lastCursorPosition() const;
135  int firstPosition() const;
136  int lastPosition() const;
137 
138  QTextFrameLayoutData *layoutData() const;
139  void setLayoutData(QTextFrameLayoutData *data);
140 
141  QList<QTextFrame *> childFrames() const;
142  QTextFrame *parentFrame() const;
143 
146  int b;
147  int e;
149  int cb;
150 
151  friend class QTextFrame;
152  friend class QTextTableCell;
154  iterator(QTextFrame *frame, int block, int begin, int end);
155  public:
156  iterator();
157  iterator(const iterator &o);
158  iterator &operator=(const iterator &o);
159 
160  QTextFrame *parentFrame() const { return f; }
161 
162  QTextFrame *currentFrame() const;
163  QTextBlock currentBlock() const;
164 
165  bool atEnd() const { return !cf && cb == e; }
166 
167  inline bool operator==(const iterator &o) const { return f == o.f && cf == o.cf && cb == o.cb; }
168  inline bool operator!=(const iterator &o) const { return f != o.f || cf != o.cf || cb != o.cb; }
169  iterator &operator++();
170  inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
171  iterator &operator--();
172  inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
173  };
174 
175  friend class iterator;
176  // more Qt
178 
179  iterator begin() const;
180  iterator end() const;
181 
182 protected:
184 private:
185  friend class QTextDocumentPrivate;
188 };
190 
191 inline void QTextFrame::setFrameFormat(const QTextFrameFormat &aformat)
192 { QTextObject::setFormat(aformat); }
193 
195 public:
196  virtual ~QTextBlockUserData();
197 };
198 
200 {
201  friend class QSyntaxHighlighter;
202 public:
203  inline QTextBlock(QTextDocumentPrivate *priv, int b) : p(priv), n(b) {}
204  inline QTextBlock() : p(0), n(0) {}
205  inline QTextBlock(const QTextBlock &o) : p(o.p), n(o.n) {}
206  inline QTextBlock &operator=(const QTextBlock &o) { p = o.p; n = o.n; return *this; }
207 
208  inline bool isValid() const { return p != 0 && n != 0; }
209 
210  inline bool operator==(const QTextBlock &o) const { return p == o.p && n == o.n; }
211  inline bool operator!=(const QTextBlock &o) const { return p != o.p || n != o.n; }
212  inline bool operator<(const QTextBlock &o) const { return position() < o.position(); }
213 
214  int position() const;
215  int length() const;
216  bool contains(int position) const;
217 
218  QTextLayout *layout() const;
219  void clearLayout();
220  QTextBlockFormat blockFormat() const;
221  int blockFormatIndex() const;
222  QTextCharFormat charFormat() const;
223  int charFormatIndex() const;
224 
225  Qt::LayoutDirection textDirection() const;
226 
227  QString text() const;
228 
229  const QTextDocument *document() const;
230 
231  QTextList *textList() const;
232 
233  QTextBlockUserData *userData() const;
235 
236  int userState() const;
237  void setUserState(int state);
238 
239  int revision() const;
240  void setRevision(int rev);
241 
242  bool isVisible() const;
243  void setVisible(bool visible);
244 
245  int blockNumber() const;
246  int firstLineNumber() const;
247 
248  void setLineCount(int count);
249  int lineCount() const;
250 
253  int b;
254  int e;
255  int n;
256  friend class QTextBlock;
257  iterator(const QTextDocumentPrivate *priv, int begin, int end, int f) : p(priv), b(begin), e(end), n(f) {}
258  public:
259  iterator() : p(0), b(0), e(0), n(0) {}
260  iterator(const iterator &o) : p(o.p), b(o.b), e(o.e), n(o.n) {}
261 
262  QTextFragment fragment() const;
263 
264  bool atEnd() const { return n == e; }
265 
266  inline bool operator==(const iterator &o) const { return p == o.p && n == o.n; }
267  inline bool operator!=(const iterator &o) const { return p != o.p || n != o.n; }
268  iterator &operator++();
269  inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
270  iterator &operator--();
271  inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
272  };
273 
274  // more Qt
276 
277  iterator begin() const;
278  iterator end() const;
279 
280  QTextBlock next() const;
281  QTextBlock previous() const;
282 
283  inline QTextDocumentPrivate *docHandle() const { return p; }
284  inline int fragmentIndex() const { return n; }
285 
286 private:
288  int n;
289  friend class QTextDocumentPrivate;
290  friend class QTextLayout;
291 };
292 
295 
296 
298 {
299 public:
300  inline QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) : p(priv), n(f), ne(fe) {}
301  inline QTextFragment() : p(0), n(0), ne(0) {}
302  inline QTextFragment(const QTextFragment &o) : p(o.p), n(o.n), ne(o.ne) {}
303  inline QTextFragment &operator=(const QTextFragment &o) { p = o.p; n = o.n; ne = o.ne; return *this; }
304 
305  inline bool isValid() const { return p && n; }
306 
307  inline bool operator==(const QTextFragment &o) const { return p == o.p && n == o.n; }
308  inline bool operator!=(const QTextFragment &o) const { return p != o.p || n != o.n; }
309  inline bool operator<(const QTextFragment &o) const { return position() < o.position(); }
310 
311  int position() const;
312  int length() const;
313  bool contains(int position) const;
314 
315  QTextCharFormat charFormat() const;
316  int charFormatIndex() const;
317  QString text() const;
318 
319 #if !defined(QT_NO_RAWFONT)
320  QList<QGlyphRun> glyphRuns() const;
321 #endif
322 
323 private:
325  int n;
326  int ne;
327 };
328 
330 
332 
334 
335 #endif // QTEXTOBJECT_H
QTextDocumentPrivate * p
Definition: qtextobject.h:287
QTextFragment(const QTextFragment &o)
Copies the content (text and format) of the other text fragment to this text fragment.
Definition: qtextobject.h:302
iterator operator++(int)
The postfix ++ operator (i++) advances the iterator to the next item in the text block and returns an...
Definition: qtextobject.h:269
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int fragmentIndex() const
Definition: qtextobject.h:284
#define QT_MODULE(x)
Definition: qglobal.h:2783
bool operator!=(const iterator &o) const
Retuns true if the iterator is different from the other iterator; otherwise returns false...
Definition: qtextobject.h:168
QTextFragment & operator=(const QTextFragment &o)
Assigns the content (text and format) of the other text fragment to this text fragment.
Definition: qtextobject.h:303
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
QTextDocument * document() const
Returns the QTextDocument on which this syntax highlighter is installed.
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
bool atEnd() const
Returns true if the current item is the last item in the text block.
Definition: qtextobject.h:264
void setUserData(uint id, QObjectUserData *data)
Definition: qobject.cpp:4003
QObjectUserData * userData(uint id) const
Definition: qobject.cpp:4016
iterator operator--(int)
The postfix ā€“ operator (iā€“) makes the preceding item current and returns an iterator to the old cur...
Definition: qtextobject.h:271
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
iterator Iterator
Qt-style synonym for QTextFrame::iterator.
Definition: qtextobject.h:177
iterator begin() const
Returns a text block iterator pointing to the beginning of the text block.
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
const QTextDocumentPrivate * p
Definition: qtextobject.h:252
The QString class provides a Unicode character string.
Definition: qstring.h:83
iterator(const QTextDocumentPrivate *priv, int begin, int end, int f)
Definition: qtextobject.h:257
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool operator!=(const iterator &o) const
Retuns true if this iterator is different from the other iterator; otherwise returns false...
Definition: qtextobject.h:267
bool operator==(const QTextBlock &o) const
Returns true if this text block is the same as the other text block.
Definition: qtextobject.h:210
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
int position() const
Returns the index of the block&#39;s first character within the document.
QTextFrameFormat toFrameFormat() const
Returns this format as a frame format.
Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE)
QTextBlock previous() const
Returns the text block in the document before this block, or an empty text block if this is the first...
bool isValid() const
Returns true if this is a valid text fragment (i.
Definition: qtextobject.h:305
bool operator<(const QTextFragment &o) const
Returns true if this text fragment appears earlier in the document than the other text fragment; othe...
Definition: qtextobject.h:309
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
iterator(const iterator &o)
Copy constructor.
Definition: qtextobject.h:260
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
bool operator==(const iterator &o) const
Retuns true if this iterator is the same as the other iterator; otherwise returns false...
Definition: qtextobject.h:266
const char * layout
LayoutDirection
Definition: qnamespace.h:1580
QTextBlock & operator=(const QTextBlock &o)
Assigns the other text block to this text block.
Definition: qtextobject.h:206
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
static const char * data(const QByteArray &arr)
iterator operator--(int)
The postfix ā€“ operator (iā€“) makes the preceding item in the current frame, and returns an iterator ...
Definition: qtextobject.h:172
bool operator<(const QTextBlock &o) const
Returns true if this text block occurs before the other text block in the document.
Definition: qtextobject.h:212
The QTextFragment class holds a piece of text in a QTextDocument with a single QTextCharFormat.
Definition: qtextobject.h:297
The QTextBlock::iterator class provides an iterator for reading the contents of a QTextBlock...
Definition: qtextobject.h:251
#define Q_OBJECT
Definition: qobjectdefs.h:157
The iterator class provides an iterator for reading the contents of a QTextFrame. ...
Definition: qtextobject.h:144
The QTextBlockUserData class is used to associate custom data with blocks of text.
Definition: qtextobject.h:194
QTextFormat format() const
Returns the text object&#39;s format.
int position() const
Returns the position of this text fragment in the document.
const QTextDocumentPrivate * p
Definition: qtextobject.h:324
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
QTextFragment(const QTextDocumentPrivate *priv, int f, int fe)
Definition: qtextobject.h:300
iterator Iterator
Qt-style synonym for QTextBlock::iterator.
Definition: qtextobject.h:275
void setFormat(const QTextFormat &format)
Sets the text object&#39;s format.
The QTextBlockGroup class provides a container for text blocks within a QTextDocument.
Definition: qtextobject.h:94
The QSyntaxHighlighter class allows you to define syntax highlighting rules, and in addition you can ...
bool operator!=(const QTextBlock &o) const
Returns true if this text block is different from the other text block.
Definition: qtextobject.h:211
bool operator!=(const QTextFragment &o) const
Returns true if this text fragment is different (at a different position) from the other text fragmen...
Definition: qtextobject.h:308
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
Definition: qtextformat.h:727
The QTextTableCell class represents the properties of a cell in a QTextTable.
Definition: qtexttable.h:59
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
iterator operator++(int)
The postfix ++ operator (i++) advances the iterator to the next item in the text frame, and returns an iterator to the old item.
Definition: qtextobject.h:170
static const QMetaObjectPrivate * priv(const uint *data)
bool operator==(const QTextFragment &o) const
Returns true if this text fragment is the same (at the same position) as the other text fragment; oth...
Definition: qtextobject.h:307
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
Definition: qtextobject.h:208
The QTextList class provides a decorated list of items in a QTextDocument.
Definition: qtextlist.h:57
QTextFrame * parentFrame() const
Returns the parent frame of the current frame.
Definition: qtextobject.h:160
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
bool atEnd() const
Returns true if the current item is the last item in the text frame.
Definition: qtextobject.h:165
QTextBlock(QTextDocumentPrivate *priv, int b)
Definition: qtextobject.h:203
QTextDocumentPrivate * docHandle() const
Definition: qtextobject.h:283
QTextBlock(const QTextBlock &o)
Copies the other text block&#39;s attributes to this text block.
Definition: qtextobject.h:205
#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
#define QT_END_HEADER
Definition: qglobal.h:137
QTextFragment()
Creates a new empty text fragment.
Definition: qtextobject.h:301
bool operator==(const iterator &o) const
Retuns true if the iterator is the same as the other iterator; otherwise returns false.
Definition: qtextobject.h:167
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame&#39;s format.
Definition: qtextobject.h:191
QTextFrameFormat frameFormat() const
Returns the frame&#39;s format.
Definition: qtextobject.h:131
iterator()
Constructs an iterator for this text block.
Definition: qtextobject.h:259
#define text
Definition: qobjectdefs.h:80