1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** 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>
54 class QTextObjectPrivate;
56 class QTextDocumentPrivate;
63 class Q_GUI_EXPORT QTextObject : public QObject
68 explicit QTextObject(QTextDocument *doc);
71 void setFormat(const QTextFormat &format);
74 QTextFormat format() const;
75 int formatIndex() const;
77 QTextDocument *document() const;
79 int objectIndex() const;
81 QTextDocumentPrivate *docHandle() const;
84 QTextObject(QTextObjectPrivate &p, QTextDocument *doc);
87 Q_DECLARE_PRIVATE(QTextObject)
88 Q_DISABLE_COPY(QTextObject)
89 friend class QTextDocumentPrivate;
92 class QTextBlockGroupPrivate;
93 class Q_GUI_EXPORT QTextBlockGroup : public QTextObject
98 explicit QTextBlockGroup(QTextDocument *doc);
101 virtual void blockInserted(const QTextBlock &block);
102 virtual void blockRemoved(const QTextBlock &block);
103 virtual void blockFormatChanged(const QTextBlock &block);
105 QList<QTextBlock> blockList() const;
108 QTextBlockGroup(QTextBlockGroupPrivate &p, QTextDocument *doc);
110 Q_DECLARE_PRIVATE(QTextBlockGroup)
111 Q_DISABLE_COPY(QTextBlockGroup)
112 friend class QTextDocumentPrivate;
115 class Q_GUI_EXPORT QTextFrameLayoutData {
117 virtual ~QTextFrameLayoutData();
120 class QTextFramePrivate;
121 class Q_GUI_EXPORT QTextFrame : public QTextObject
126 explicit QTextFrame(QTextDocument *doc);
129 inline void setFrameFormat(const QTextFrameFormat &format);
130 QTextFrameFormat frameFormat() const { return QTextObject::format().toFrameFormat(); }
132 QTextCursor firstCursorPosition() const;
133 QTextCursor lastCursorPosition() const;
134 int firstPosition() const;
135 int lastPosition() const;
137 QTextFrameLayoutData *layoutData() const;
138 void setLayoutData(QTextFrameLayoutData *data);
140 QList<QTextFrame *> childFrames() const;
141 QTextFrame *parentFrame() const;
143 class Q_GUI_EXPORT iterator {
150 friend class QTextFrame;
151 friend class QTextTableCell;
152 friend class QTextDocumentLayoutPrivate;
153 iterator(QTextFrame *frame, int block, int begin, int end);
156 iterator(const iterator &o);
157 iterator &operator=(const iterator &o);
159 QTextFrame *parentFrame() const { return f; }
161 QTextFrame *currentFrame() const;
162 QTextBlock currentBlock() const;
164 bool atEnd() const { return !cf && cb == e; }
166 inline bool operator==(const iterator &o) const { return f == o.f && cf == o.cf && cb == o.cb; }
167 inline bool operator!=(const iterator &o) const { return f != o.f || cf != o.cf || cb != o.cb; }
168 iterator &operator++();
169 inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
170 iterator &operator--();
171 inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
174 friend class iterator;
176 typedef iterator Iterator;
178 iterator begin() const;
179 iterator end() const;
182 QTextFrame(QTextFramePrivate &p, QTextDocument *doc);
184 friend class QTextDocumentPrivate;
185 Q_DECLARE_PRIVATE(QTextFrame)
186 Q_DISABLE_COPY(QTextFrame)
188 Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE);
190 inline void QTextFrame::setFrameFormat(const QTextFrameFormat &aformat)
191 { QTextObject::setFormat(aformat); }
193 class Q_GUI_EXPORT QTextBlockUserData {
195 virtual ~QTextBlockUserData();
198 class Q_GUI_EXPORT QTextBlock
200 friend class QSyntaxHighlighter;
202 inline QTextBlock(QTextDocumentPrivate *priv, int b) : p(priv), n(b) {}
203 inline QTextBlock() : p(0), n(0) {}
204 inline QTextBlock(const QTextBlock &o) : p(o.p), n(o.n) {}
205 inline QTextBlock &operator=(const QTextBlock &o) { p = o.p; n = o.n; return *this; }
207 bool isValid() const;
209 inline bool operator==(const QTextBlock &o) const { return p == o.p && n == o.n; }
210 inline bool operator!=(const QTextBlock &o) const { return p != o.p || n != o.n; }
211 inline bool operator<(const QTextBlock &o) const { return position() < o.position(); }
213 int position() const;
215 bool contains(int position) const;
217 QTextLayout *layout() const;
219 QTextBlockFormat blockFormat() const;
220 int blockFormatIndex() const;
221 QTextCharFormat charFormat() const;
222 int charFormatIndex() const;
224 Qt::LayoutDirection textDirection() const;
226 QString text() const;
228 const QTextDocument *document() const;
230 QTextList *textList() const;
232 QTextBlockUserData *userData() const;
233 void setUserData(QTextBlockUserData *data);
235 int userState() const;
236 void setUserState(int state);
238 int revision() const;
239 void setRevision(int rev);
241 bool isVisible() const;
242 void setVisible(bool visible);
244 int blockNumber() const;
245 int firstLineNumber() const;
247 void setLineCount(int count);
248 int lineCount() const;
250 class Q_GUI_EXPORT iterator {
251 const QTextDocumentPrivate *p;
255 friend class QTextBlock;
256 iterator(const QTextDocumentPrivate *priv, int begin, int end, int f) : p(priv), b(begin), e(end), n(f) {}
258 iterator() : p(0), b(0), e(0), n(0) {}
259 iterator(const iterator &o) : p(o.p), b(o.b), e(o.e), n(o.n) {}
261 QTextFragment fragment() const;
263 bool atEnd() const { return n == e; }
265 inline bool operator==(const iterator &o) const { return p == o.p && n == o.n; }
266 inline bool operator!=(const iterator &o) const { return p != o.p || n != o.n; }
267 iterator &operator++();
268 inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
269 iterator &operator--();
270 inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
274 typedef iterator Iterator;
276 iterator begin() const;
277 iterator end() const;
279 QTextBlock next() const;
280 QTextBlock previous() const;
282 inline QTextDocumentPrivate *docHandle() const { return p; }
283 inline int fragmentIndex() const { return n; }
286 QTextDocumentPrivate *p;
288 friend class QTextDocumentPrivate;
289 friend class QTextLayout;
292 Q_DECLARE_TYPEINFO(QTextBlock, Q_MOVABLE_TYPE);
293 Q_DECLARE_TYPEINFO(QTextBlock::iterator, Q_MOVABLE_TYPE);
296 class Q_GUI_EXPORT QTextFragment
299 inline QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) : p(priv), n(f), ne(fe) {}
300 inline QTextFragment() : p(0), n(0), ne(0) {}
301 inline QTextFragment(const QTextFragment &o) : p(o.p), n(o.n), ne(o.ne) {}
302 inline QTextFragment &operator=(const QTextFragment &o) { p = o.p; n = o.n; ne = o.ne; return *this; }
304 inline bool isValid() const { return p && n; }
306 inline bool operator==(const QTextFragment &o) const { return p == o.p && n == o.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 position() < o.position(); }
310 int position() const;
312 bool contains(int position) const;
314 QTextCharFormat charFormat() const;
315 int charFormatIndex() const;
316 QString text() const;
318 #if !defined(QT_NO_RAWFONT)
319 QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
323 const QTextDocumentPrivate *p;
328 Q_DECLARE_TYPEINFO(QTextFragment, Q_MOVABLE_TYPE);
334 #endif // QTEXTOBJECT_H