1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
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
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
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);
frameFormat()131 QTextFrameFormat frameFormat() const { return QTextObject::format().toFrameFormat(); }
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
parentFrame()160 QTextFrame *parentFrame() const { return f; }
161
162 QTextFrame *currentFrame() const;
163 QTextBlock currentBlock() const;
164
atEnd()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
177 typedef iterator Iterator;
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
setFrameFormat(const QTextFrameFormat & aformat)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:
QTextBlock(QTextDocumentPrivate * priv,int b)203 inline QTextBlock(QTextDocumentPrivate *priv, int b) : p(priv), n(b) {}
QTextBlock()204 inline QTextBlock() : p(0), n(0) {}
QTextBlock(const QTextBlock & o)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
isValid()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;
234 void setUserData(QTextBlockUserData *data);
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;
iterator(const QTextDocumentPrivate * priv,int begin,int end,int f)257 iterator(const QTextDocumentPrivate *priv, int begin, int end, int f) : p(priv), b(begin), e(end), n(f) {}
258 public:
iterator()259 iterator() : p(0), b(0), e(0), n(0) {}
iterator(const iterator & o)260 iterator(const iterator &o) : p(o.p), b(o.b), e(o.e), n(o.n) {}
261
262 QTextFragment fragment() const;
263
atEnd()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
275 typedef iterator Iterator;
276
277 iterator begin() const;
278 iterator end() const;
279
280 QTextBlock next() const;
281 QTextBlock previous() const;
282
docHandle()283 inline QTextDocumentPrivate *docHandle() const { return p; }
fragmentIndex()284 inline int fragmentIndex() const { return n; }
285
286 private:
287 QTextDocumentPrivate *p;
288 int n;
289 friend class QTextDocumentPrivate;
290 friend class QTextLayout;
291 };
292
293 Q_DECLARE_TYPEINFO(QTextBlock, Q_MOVABLE_TYPE);
294 Q_DECLARE_TYPEINFO(QTextBlock::iterator, Q_MOVABLE_TYPE);
295
296
297 class Q_GUI_EXPORT QTextFragment
298 {
299 public:
QTextFragment(const QTextDocumentPrivate * priv,int f,int fe)300 inline QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) : p(priv), n(f), ne(fe) {}
QTextFragment()301 inline QTextFragment() : p(0), n(0), ne(0) {}
QTextFragment(const QTextFragment & o)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
isValid()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
331 QT_END_NAMESPACE
332
333 QT_END_HEADER
334
335 #endif // QTEXTOBJECT_H
336