Compile with clang when C++11 support is enabled
[profile/ivi/qtbase.git] / src / gui / text / qtextobject.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
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
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53
54 class QTextObjectPrivate;
55 class QTextDocument;
56 class QTextDocumentPrivate;
57 class QTextCursor;
58 class QTextBlock;
59 class QTextFragment;
60 class QTextLayout;
61 class QTextList;
62
63 class Q_GUI_EXPORT QTextObject : public QObject
64 {
65     Q_OBJECT
66
67 protected:
68     explicit QTextObject(QTextDocument *doc);
69     ~QTextObject();
70
71     void setFormat(const QTextFormat &format);
72
73 public:
74     QTextFormat format() const;
75     int formatIndex() const;
76
77     QTextDocument *document() const;
78
79     int objectIndex() const;
80
81     QTextDocumentPrivate *docHandle() const;
82
83 protected:
84     QTextObject(QTextObjectPrivate &p, QTextDocument *doc);
85
86 private:
87     Q_DECLARE_PRIVATE(QTextObject)
88     Q_DISABLE_COPY(QTextObject)
89     friend class QTextDocumentPrivate;
90 };
91
92 class QTextBlockGroupPrivate;
93 class Q_GUI_EXPORT QTextBlockGroup : public QTextObject
94 {
95     Q_OBJECT
96
97 protected:
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
107 protected:
108     QTextBlockGroup(QTextBlockGroupPrivate &p, QTextDocument *doc);
109 private:
110     Q_DECLARE_PRIVATE(QTextBlockGroup)
111     Q_DISABLE_COPY(QTextBlockGroup)
112     friend class QTextDocumentPrivate;
113 };
114
115 class Q_GUI_EXPORT QTextFrameLayoutData {
116 public:
117     virtual ~QTextFrameLayoutData();
118 };
119
120 class QTextFramePrivate;
121 class Q_GUI_EXPORT QTextFrame : public QTextObject
122 {
123     Q_OBJECT
124
125 public:
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
181 protected:
182     QTextFrame(QTextFramePrivate &p, QTextDocument *doc);
183 private:
184     friend class QTextDocumentPrivate;
185     Q_DECLARE_PRIVATE(QTextFrame)
186     Q_DISABLE_COPY(QTextFrame)
187 };
188 Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE);
189
190 inline void QTextFrame::setFrameFormat(const QTextFrameFormat &aformat)
191 { QTextObject::setFormat(aformat); }
192
193 class Q_GUI_EXPORT QTextBlockUserData {
194 public:
195     virtual ~QTextBlockUserData();
196 };
197
198 class Q_GUI_EXPORT QTextBlock
199 {
200     friend class QSyntaxHighlighter;
201 public:
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     bool isValid() const;
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
285 private:
286     QTextDocumentPrivate *p;
287     int n;
288     friend class QTextDocumentPrivate;
289     friend class QTextLayout;
290 };
291
292 Q_DECLARE_TYPEINFO(QTextBlock, Q_MOVABLE_TYPE);
293 Q_DECLARE_TYPEINFO(QTextBlock::iterator, Q_MOVABLE_TYPE);
294
295
296 class Q_GUI_EXPORT QTextFragment
297 {
298 public:
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
318 #if !defined(QT_NO_RAWFONT)
319     QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const;
320 #endif
321
322 private:
323     const QTextDocumentPrivate *p;
324     int n;
325     int ne;
326 };
327
328 Q_DECLARE_TYPEINFO(QTextFragment, Q_MOVABLE_TYPE);
329
330 QT_END_NAMESPACE
331
332 QT_END_HEADER
333
334 #endif // QTEXTOBJECT_H