QtGui/qtextobject.h Source File

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;
57 class QTextDocumentPrivate;
58 class QTextCursor;
59 class QTextBlock;
60 class QTextFragment;
61 class QTextLayout;
62 class QTextList;
63 
64 class Q_GUI_EXPORT QTextObject : public QObject
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:
85  QTextObject(QTextObjectPrivate &p, QTextDocument *doc);
86 
87 private:
88  Q_DECLARE_PRIVATE(QTextObject)
89  Q_DISABLE_COPY(QTextObject)
90  friend class QTextDocumentPrivate;
91 };
92 
93 class QTextBlockGroupPrivate;
94 class Q_GUI_EXPORT QTextBlockGroup : public QTextObject
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:
111  Q_DECLARE_PRIVATE(QTextBlockGroup)
112  Q_DISABLE_COPY(QTextBlockGroup)
113  friend class QTextDocumentPrivate;
114 };
115 
116 class Q_GUI_EXPORT QTextFrameLayoutData {
117 public:
118  virtual ~QTextFrameLayoutData();
119 };
120 
121 class QTextFramePrivate;
122 class Q_GUI_EXPORT QTextFrame : public QTextObject
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 
144  class Q_GUI_EXPORT iterator {
145  QTextFrame *f;
146  int b;
147  int e;
148  QTextFrame *cf;
149  int cb;
150 
151  friend class QTextFrame;
152  friend class QTextTableCell;
153  friend class QTextDocumentLayoutPrivate;
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:
183  QTextFrame(QTextFramePrivate &p, QTextDocument *doc);
184 private:
185  friend class QTextDocumentPrivate;
186  Q_DECLARE_PRIVATE(QTextFrame)
187  Q_DISABLE_COPY(QTextFrame)
188 };
189 Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE);
190 
191 inline void QTextFrame::setFrameFormat(const QTextFrameFormat &aformat)
192 { QTextObject::setFormat(aformat); }
193 
194 class Q_GUI_EXPORT QTextBlockUserData {
195 public:
196  virtual ~QTextBlockUserData();
197 };
198 
199 class Q_GUI_EXPORT QTextBlock
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 
251  class Q_GUI_EXPORT iterator {
252  const QTextDocumentPrivate *p;
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 
293 Q_DECLARE_TYPEINFO(QTextBlock, Q_MOVABLE_TYPE);
295 
296 
297 class Q_GUI_EXPORT QTextFragment
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:
324  const QTextDocumentPrivate *p;
325  int n;
326  int ne;
327 };
328 
329 Q_DECLARE_TYPEINFO(QTextFragment, Q_MOVABLE_TYPE);
330 
332 
334 
335 #endif // QTEXTOBJECT_H
int position() const
void setFormat(const QTextFormat &format)
#define QT_END_NAMESPACE
Definition: qglobal.h:128
iterator Iterator
Definition: qtextobject.h:275
QTextFormat format() const
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
QObjectUserData * userData(uint id) const
LayoutDirection
Definition: qnamespace.h:1580
iterator operator++(int)
Definition: qtextobject.h:269
QTextBlock previous() const
bool operator==(const QTextBlock &o) const
Definition: qtextobject.h:210
QTextFragment(const QTextFragment &o)
Definition: qtextobject.h:302
iterator operator--(int)
Definition: qtextobject.h:172
#define inline
Definition: image.h:2490
bool operator!=(const iterator &o) const
Definition: qtextobject.h:267
QTextBlock(QTextDocumentPrivate *priv, int b)
Definition: qtextobject.h:203
Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE)
QTextFrame * parentFrame() const
Definition: qtextobject.h:160
iterator begin() const
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
QTextFrameFormat frameFormat() const
Definition: qtextobject.h:131
bool operator==(const iterator &o) const
Definition: qtextobject.h:266
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: GLee.h:880
friend class QTextDocumentPrivate
Definition: qtextobject.h:289
QTextBlock next() const
GLenum GLsizei GLenum format
Definition: GLee.h:873
bool operator!=(const QTextFragment &o) const
Definition: qtextobject.h:308
bool operator!=(const iterator &o) const
Definition: qtextobject.h:168
bool operator<(const QTextBlock &o) const
Definition: qtextobject.h:212
bool operator==(const iterator &o) const
Definition: qtextobject.h:167
QTextBlock(const QTextBlock &o)
Definition: qtextobject.h:205
iterator operator--(int)
Definition: qtextobject.h:271
QTextDocument * document() const
QTextFragment & operator=(const QTextFragment &o)
Definition: qtextobject.h:303
bool isValid() const
Definition: qtextobject.h:305
GLuint GLuint GLsizei count
Definition: GLee.h:872
GLenum GLsizei n
Definition: GLee.h:3432
bool atEnd() const
Definition: qtextobject.h:264
GLuint GLsizei GLsizei * length
Definition: GLee.h:1713
#define Q_OBJECT
Definition: qobjectdefs.h:157
iterator(const iterator &o)
Definition: qtextobject.h:260
GLubyte GLubyte b
Definition: GLee.h:5404
QTextBlock & operator=(const QTextBlock &o)
Definition: qtextobject.h:206
iterator Iterator
Definition: qtextobject.h:177
bool operator!=(const QTextBlock &o) const
Definition: qtextobject.h:211
GLuint GLuint end
Definition: GLee.h:872
int position() const
GLfloat GLfloat p
Definition: GLee.h:5416
QTextDocumentPrivate * docHandle() const
Definition: qtextobject.h:283
QTextFrameFormat toFrameFormat() const
bool operator<(const QTextFragment &o) const
Definition: qtextobject.h:309
bool atEnd() const
Definition: qtextobject.h:165
void setUserData(uint id, QObjectUserData *data)
bool operator==(const QTextFragment &o) const
Definition: qtextobject.h:307
#define QT_END_HEADER
Definition: qglobal.h:142
GLclampf f
Definition: GLee.h:9303
bool isValid() const
Definition: qtextobject.h:208
QTextFragment(const QTextDocumentPrivate *priv, int f, int fe)
Definition: qtextobject.h:300
int fragmentIndex() const
Definition: qtextobject.h:284
iterator operator++(int)
Definition: qtextobject.h:170