1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtCore/qobject.h>
46 #include <QtGui/qtextformat.h>
47 #include <QtGui/qglyphrun.h>
55 class QTextObjectPrivate;
57 class QTextDocumentPrivate;
64 class Q_GUI_EXPORT QTextObject : public QObject
69 explicit QTextObject(QTextDocument *doc);
72 void setFormat(const QTextFormat &format);
75 QTextFormat format() const;
76 int formatIndex() const;
78 QTextDocument *document() const;
80 int objectIndex() const;
82 QTextDocumentPrivate *docHandle() const;
85 QTextObject(QTextObjectPrivate &p, QTextDocument *doc);
88 Q_DECLARE_PRIVATE(QTextObject)
89 Q_DISABLE_COPY(QTextObject)
90 friend class QTextDocumentPrivate;
93 class QTextBlockGroupPrivate;
94 class Q_GUI_EXPORT QTextBlockGroup : public QTextObject
99 explicit QTextBlockGroup(QTextDocument *doc);
102 virtual void blockInserted(const QTextBlock &block);
103 virtual void blockRemoved(const QTextBlock &block);
104 virtual void blockFormatChanged(const QTextBlock &block);
106 QList<QTextBlock> blockList() const;
109 QTextBlockGroup(QTextBlockGroupPrivate &p, QTextDocument *doc);
111 Q_DECLARE_PRIVATE(QTextBlockGroup)
112 Q_DISABLE_COPY(QTextBlockGroup)
113 friend class QTextDocumentPrivate;
116 class Q_GUI_EXPORT QTextFrameLayoutData {
118 virtual ~QTextFrameLayoutData();
121 class QTextFramePrivate;
122 class Q_GUI_EXPORT QTextFrame : public QTextObject
127 explicit QTextFrame(QTextDocument *doc);
130 inline void setFrameFormat(const QTextFrameFormat &format);
131 QTextFrameFormat frameFormat() const { return QTextObject::format().toFrameFormat(); }
133 QTextCursor firstCursorPosition() const;
134 QTextCursor lastCursorPosition() const;
135 int firstPosition() const;
136 int lastPosition() const;
138 QTextFrameLayoutData *layoutData() const;
139 void setLayoutData(QTextFrameLayoutData *data);
141 QList<QTextFrame *> childFrames() const;
142 QTextFrame *parentFrame() const;
144 class Q_GUI_EXPORT iterator {
151 friend class QTextFrame;
152 friend class QTextTableCell;
153 friend class QTextDocumentLayoutPrivate;
154 iterator(QTextFrame *frame, int block, int begin, int end);
157 iterator(const iterator &o);
158 iterator &operator=(const iterator &o);
160 QTextFrame *parentFrame() const { return f; }
162 QTextFrame *currentFrame() const;
163 QTextBlock currentBlock() const;
165 bool atEnd() const { return !cf && cb == e; }
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; }
175 friend class iterator;
177 typedef iterator Iterator;
179 iterator begin() const;
180 iterator end() const;
183 QTextFrame(QTextFramePrivate &p, QTextDocument *doc);
185 friend class QTextDocumentPrivate;
186 Q_DECLARE_PRIVATE(QTextFrame)
187 Q_DISABLE_COPY(QTextFrame)
189 Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE);
191 inline void QTextFrame::setFrameFormat(const QTextFrameFormat &aformat)
192 { QTextObject::setFormat(aformat); }
194 class Q_GUI_EXPORT QTextBlockUserData {
196 virtual ~QTextBlockUserData();
199 class Q_GUI_EXPORT QTextBlock
201 friend class QSyntaxHighlighter;
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; }
208 bool isValid() const;
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(); }
214 int position() const;
216 bool contains(int position) const;
218 QTextLayout *layout() const;
220 QTextBlockFormat blockFormat() const;
221 int blockFormatIndex() const;
222 QTextCharFormat charFormat() const;
223 int charFormatIndex() const;
225 Qt::LayoutDirection textDirection() const;
227 QString text() const;
229 const QTextDocument *document() const;
231 QTextList *textList() const;
233 QTextBlockUserData *userData() const;
234 void setUserData(QTextBlockUserData *data);
236 int userState() const;
237 void setUserState(int state);
239 int revision() const;
240 void setRevision(int rev);
242 bool isVisible() const;
243 void setVisible(bool visible);
245 int blockNumber() const;
246 int firstLineNumber() const;
248 void setLineCount(int count);
249 int lineCount() const;
251 class Q_GUI_EXPORT iterator {
252 const QTextDocumentPrivate *p;
256 friend class QTextBlock;
257 iterator(const QTextDocumentPrivate *priv, int begin, int end, int f) : p(priv), b(begin), e(end), n(f) {}
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) {}
262 QTextFragment fragment() const;
264 bool atEnd() const { return n == e; }
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; }
275 typedef iterator Iterator;
277 iterator begin() const;
278 iterator end() const;
280 QTextBlock next() const;
281 QTextBlock previous() const;
283 inline QTextDocumentPrivate *docHandle() const { return p; }
284 inline int fragmentIndex() const { return n; }
287 QTextDocumentPrivate *p;
289 friend class QTextDocumentPrivate;
290 friend class QTextLayout;
293 Q_DECLARE_TYPEINFO(QTextBlock, Q_MOVABLE_TYPE);
294 Q_DECLARE_TYPEINFO(QTextBlock::iterator, Q_MOVABLE_TYPE);
297 class Q_GUI_EXPORT QTextFragment
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; }
305 inline bool isValid() const { return p && n; }
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(); }
311 int position() const;
313 bool contains(int position) const;
315 QTextCharFormat charFormat() const;
316 int charFormatIndex() const;
317 QString text() const;
319 #if !defined(QT_NO_RAWFONT)
320 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
324 const QTextDocumentPrivate *p;
329 Q_DECLARE_TYPEINFO(QTextFragment, Q_MOVABLE_TYPE);
335 #endif // QTEXTOBJECT_H