source: trunk/src/gui/text/qtextobject.h@ 858

Last change on this file since 858 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 9.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
48QT_BEGIN_HEADER
49
50QT_BEGIN_NAMESPACE
51
52QT_MODULE(Gui)
53
54class QTextObjectPrivate;
55class QTextDocument;
56class QTextDocumentPrivate;
57class QTextCursor;
58class QTextBlock;
59class QTextFragment;
60class QTextLayout;
61class QTextList;
62
63class Q_GUI_EXPORT QTextObject : public QObject
64{
65 Q_OBJECT
66
67protected:
68 explicit QTextObject(QTextDocument *doc);
69 ~QTextObject();
70
71 void setFormat(const QTextFormat &format);
72
73public:
74 QTextFormat format() const;
75 int formatIndex() const;
76
77 QTextDocument *document() const;
78
79 int objectIndex() const;
80
81 QTextDocumentPrivate *docHandle() const;
82
83protected:
84 QTextObject(QTextObjectPrivate &p, QTextDocument *doc);
85
86private:
87 Q_DECLARE_PRIVATE(QTextObject)
88 Q_DISABLE_COPY(QTextObject)
89 friend class QTextDocumentPrivate;
90};
91
92class QTextBlockGroupPrivate;
93class Q_GUI_EXPORT QTextBlockGroup : public QTextObject
94{
95 Q_OBJECT
96
97protected:
98 explicit QTextBlockGroup(QTextDocument *doc);
99 ~QTextBlockGroup();
100
101 virtual void blockInserted(const QTextBlock &block);
102 virtual void blockRemoved(const QTextBlock &block);
103 virtual void blockFormatChanged(const QTextBlock &block);
104
105 QList<QTextBlock> blockList() const;
106
107protected:
108 QTextBlockGroup(QTextBlockGroupPrivate &p, QTextDocument *doc);
109private:
110 Q_DECLARE_PRIVATE(QTextBlockGroup)
111 Q_DISABLE_COPY(QTextBlockGroup)
112 friend class QTextDocumentPrivate;
113};
114
115class Q_GUI_EXPORT QTextFrameLayoutData {
116public:
117 virtual ~QTextFrameLayoutData();
118};
119
120class QTextFramePrivate;
121class Q_GUI_EXPORT QTextFrame : public QTextObject
122{
123 Q_OBJECT
124
125public:
126 explicit QTextFrame(QTextDocument *doc);
127 ~QTextFrame();
128
129 inline void setFrameFormat(const QTextFrameFormat &format);
130 QTextFrameFormat frameFormat() const { return QTextObject::format().toFrameFormat(); }
131
132 QTextCursor firstCursorPosition() const;
133 QTextCursor lastCursorPosition() const;
134 int firstPosition() const;
135 int lastPosition() const;
136
137 QTextFrameLayoutData *layoutData() const;
138 void setLayoutData(QTextFrameLayoutData *data);
139
140 QList<QTextFrame *> childFrames() const;
141 QTextFrame *parentFrame() const;
142
143 class Q_GUI_EXPORT iterator {
144 QTextFrame *f;
145 int b;
146 int e;
147 QTextFrame *cf;
148 int cb;
149
150 friend class QTextFrame;
151 friend class QTextTableCell;
152 friend class QTextDocumentLayoutPrivate;
153 iterator(QTextFrame *frame, int block, int begin, int end);
154 public:
155 iterator();
156 iterator(const iterator &o);
157 iterator &operator=(const iterator &o);
158
159 QTextFrame *parentFrame() const { return f; }
160
161 QTextFrame *currentFrame() const;
162 QTextBlock currentBlock() const;
163
164 bool atEnd() const { return !cf && cb == e; }
165
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; }
172 };
173
174 friend class iterator;
175 // more Qt
176 typedef iterator Iterator;
177
178 iterator begin() const;
179 iterator end() const;
180
181protected:
182 QTextFrame(QTextFramePrivate &p, QTextDocument *doc);
183private:
184 friend class QTextDocumentPrivate;
185 Q_DECLARE_PRIVATE(QTextFrame)
186 Q_DISABLE_COPY(QTextFrame)
187};
188Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE);
189
190inline void QTextFrame::setFrameFormat(const QTextFrameFormat &aformat)
191{ QTextObject::setFormat(aformat); }
192
193class Q_GUI_EXPORT QTextBlockUserData {
194public:
195 virtual ~QTextBlockUserData();
196};
197
198class Q_GUI_EXPORT QTextBlock
199{
200 friend class QSyntaxHighlighter;
201public:
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; }
206
207 inline bool isValid() const { return p != 0 && n != 0; }
208
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(); }
212
213 int position() const;
214 int length() const;
215 bool contains(int position) const;
216
217 QTextLayout *layout() const;
218 void clearLayout();
219 QTextBlockFormat blockFormat() const;
220 int blockFormatIndex() const;
221 QTextCharFormat charFormat() const;
222 int charFormatIndex() const;
223
224 Qt::LayoutDirection textDirection() const;
225
226 QString text() const;
227
228 const QTextDocument *document() const;
229
230 QTextList *textList() const;
231
232 QTextBlockUserData *userData() const;
233 void setUserData(QTextBlockUserData *data);
234
235 int userState() const;
236 void setUserState(int state);
237
238 int revision() const;
239 void setRevision(int rev);
240
241 bool isVisible() const;
242 void setVisible(bool visible);
243
244 int blockNumber() const;
245 int firstLineNumber() const;
246
247 void setLineCount(int count);
248 int lineCount() const;
249
250 class Q_GUI_EXPORT iterator {
251 const QTextDocumentPrivate *p;
252 int b;
253 int e;
254 int n;
255 friend class QTextBlock;
256 iterator(const QTextDocumentPrivate *priv, int begin, int end, int f) : p(priv), b(begin), e(end), n(f) {}
257 public:
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) {}
260
261 QTextFragment fragment() const;
262
263 bool atEnd() const { return n == e; }
264
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; }
271 };
272
273 // more Qt
274 typedef iterator Iterator;
275
276 iterator begin() const;
277 iterator end() const;
278
279 QTextBlock next() const;
280 QTextBlock previous() const;
281
282 inline QTextDocumentPrivate *docHandle() const { return p; }
283 inline int fragmentIndex() const { return n; }
284
285private:
286 QTextDocumentPrivate *p;
287 int n;
288 friend class QTextDocumentPrivate;
289 friend class QTextLayout;
290};
291
292Q_DECLARE_TYPEINFO(QTextBlock, Q_MOVABLE_TYPE);
293Q_DECLARE_TYPEINFO(QTextBlock::iterator, Q_MOVABLE_TYPE);
294
295
296class Q_GUI_EXPORT QTextFragment
297{
298public:
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; }
303
304 inline bool isValid() const { return p && n; }
305
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(); }
309
310 int position() const;
311 int length() const;
312 bool contains(int position) const;
313
314 QTextCharFormat charFormat() const;
315 int charFormatIndex() const;
316 QString text() const;
317
318private:
319 const QTextDocumentPrivate *p;
320 int n;
321 int ne;
322};
323
324Q_DECLARE_TYPEINFO(QTextFragment, Q_MOVABLE_TYPE);
325
326QT_END_NAMESPACE
327
328QT_END_HEADER
329
330#endif // QTEXTOBJECT_H
Note: See TracBrowser for help on using the repository browser.