/src/qtbase/src/gui/text/qtextobject.h
Line | Count | Source |
1 | | // Copyright (C) 2016 The Qt Company Ltd. |
2 | | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | | |
4 | | #ifndef QTEXTOBJECT_H |
5 | | #define QTEXTOBJECT_H |
6 | | |
7 | | #include <QtGui/qtguiglobal.h> |
8 | | #include <QtCore/qobject.h> |
9 | | #include <QtGui/qtextformat.h> |
10 | | #include <QtGui/qtextlayout.h> |
11 | | #include <QtGui/qglyphrun.h> |
12 | | |
13 | | QT_BEGIN_NAMESPACE |
14 | | |
15 | | |
16 | | class QTextObjectPrivate; |
17 | | class QTextDocument; |
18 | | class QTextDocumentPrivate; |
19 | | class QTextCursor; |
20 | | class QTextBlock; |
21 | | class QTextFragment; |
22 | | class QTextList; |
23 | | |
24 | | class Q_GUI_EXPORT QTextObject : public QObject |
25 | | { |
26 | 0 | Q_OBJECT |
27 | 0 |
|
28 | 0 | protected: |
29 | 0 | explicit QTextObject(QTextDocument *doc); |
30 | 0 | ~QTextObject(); |
31 | 0 |
|
32 | 0 | void setFormat(const QTextFormat &format); |
33 | 0 |
|
34 | 0 | public: |
35 | 0 | QTextFormat format() const; |
36 | 0 | int formatIndex() const; |
37 | 0 |
|
38 | 0 | QTextDocument *document() const; |
39 | 0 |
|
40 | 0 | int objectIndex() const; |
41 | 0 |
|
42 | 0 | protected: |
43 | 0 | QTextObject(QTextObjectPrivate &p, QTextDocument *doc); |
44 | 0 |
|
45 | 0 | private: |
46 | 0 | Q_DECLARE_PRIVATE(QTextObject) Unexecuted instantiation: QTextObject::d_func() Unexecuted instantiation: QTextObject::d_func() const |
47 | 0 | Q_DISABLE_COPY(QTextObject) |
48 | 0 | friend class QTextDocumentPrivate; |
49 | 0 | }; |
50 | 0 |
|
51 | 0 | class QTextBlockGroupPrivate; |
52 | 0 | class Q_GUI_EXPORT QTextBlockGroup : public QTextObject |
53 | 0 | { |
54 | 0 | Q_OBJECT |
55 | 0 |
|
56 | 0 | protected: |
57 | 0 | explicit QTextBlockGroup(QTextDocument *doc); |
58 | 0 | ~QTextBlockGroup(); |
59 | 0 |
|
60 | 0 | virtual void blockInserted(const QTextBlock &block); |
61 | 0 | virtual void blockRemoved(const QTextBlock &block); |
62 | 0 | virtual void blockFormatChanged(const QTextBlock &block); |
63 | 0 |
|
64 | 0 | QList<QTextBlock> blockList() const; |
65 | 0 |
|
66 | 0 | protected: |
67 | 0 | QTextBlockGroup(QTextBlockGroupPrivate &p, QTextDocument *doc); |
68 | 0 | private: |
69 | 0 | Q_DECLARE_PRIVATE(QTextBlockGroup) Unexecuted instantiation: QTextBlockGroup::d_func() Unexecuted instantiation: QTextBlockGroup::d_func() const |
70 | 0 | Q_DISABLE_COPY(QTextBlockGroup) |
71 | 0 | friend class QTextDocumentPrivate; |
72 | 0 | }; |
73 | 0 |
|
74 | 0 | class Q_GUI_EXPORT QTextFrameLayoutData { |
75 | 0 | public: |
76 | 0 | virtual ~QTextFrameLayoutData(); |
77 | 0 | }; |
78 | 0 |
|
79 | 0 | class QTextFramePrivate; |
80 | 0 | class Q_GUI_EXPORT QTextFrame : public QTextObject |
81 | 0 | { |
82 | 0 | Q_OBJECT |
83 | 0 |
|
84 | 0 | public: |
85 | 0 | explicit QTextFrame(QTextDocument *doc); |
86 | 0 | ~QTextFrame(); |
87 | 0 |
|
88 | 0 | inline void setFrameFormat(const QTextFrameFormat &format); |
89 | 0 | QTextFrameFormat frameFormat() const { return QTextObject::format().toFrameFormat(); } |
90 | | |
91 | | QTextCursor firstCursorPosition() const; |
92 | | QTextCursor lastCursorPosition() const; |
93 | | int firstPosition() const; |
94 | | int lastPosition() const; |
95 | | |
96 | | QTextFrameLayoutData *layoutData() const; |
97 | | void setLayoutData(QTextFrameLayoutData *data); |
98 | | |
99 | | QList<QTextFrame *> childFrames() const; |
100 | | QTextFrame *parentFrame() const; |
101 | | |
102 | | class iterator { |
103 | | QTextFrame *f = nullptr; |
104 | | int b = 0; |
105 | | int e = 0; |
106 | | QTextFrame *cf = nullptr; |
107 | | int cb = 0; |
108 | | |
109 | | friend class QTextFrame; |
110 | | friend class QTextTableCell; |
111 | | friend class QTextDocumentLayoutPrivate; |
112 | | inline iterator(QTextFrame *frame, int block, int begin, int end) |
113 | 0 | : f(frame), b(begin), e(end), cb(block) |
114 | 0 | {} |
115 | | public: |
116 | 0 | constexpr iterator() noexcept = default; |
117 | 0 | QTextFrame *parentFrame() const { return f; } |
118 | | |
119 | 0 | QTextFrame *currentFrame() const { return cf; } |
120 | | Q_GUI_EXPORT QTextBlock currentBlock() const; |
121 | | |
122 | 0 | bool atEnd() const { return !cf && cb == e; } |
123 | | |
124 | 0 | inline bool operator==(const iterator &o) const { return f == o.f && cf == o.cf && cb == o.cb; } |
125 | 0 | inline bool operator!=(const iterator &o) const { return f != o.f || cf != o.cf || cb != o.cb; } |
126 | | Q_GUI_EXPORT iterator &operator++(); |
127 | 0 | inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; } |
128 | | Q_GUI_EXPORT iterator &operator--(); |
129 | 0 | inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; } |
130 | | }; |
131 | | |
132 | | friend class iterator; |
133 | | // more Qt |
134 | | typedef iterator Iterator; |
135 | | |
136 | | iterator begin() const; |
137 | | iterator end() const; |
138 | | |
139 | | protected: |
140 | | QTextFrame(QTextFramePrivate &p, QTextDocument *doc); |
141 | | private: |
142 | | friend class QTextDocumentPrivate; |
143 | 0 | Q_DECLARE_PRIVATE(QTextFrame) Unexecuted instantiation: QTextFrame::d_func() Unexecuted instantiation: QTextFrame::d_func() const |
144 | 0 | Q_DISABLE_COPY(QTextFrame) |
145 | 0 | }; |
146 | 0 | Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_RELOCATABLE_TYPE); |
147 | 0 |
|
148 | 0 | inline void QTextFrame::setFrameFormat(const QTextFrameFormat &aformat) |
149 | 0 | { QTextObject::setFormat(aformat); } |
150 | | |
151 | | class Q_GUI_EXPORT QTextBlockUserData { |
152 | | public: |
153 | | virtual ~QTextBlockUserData(); |
154 | | }; |
155 | | |
156 | | class Q_GUI_EXPORT QTextBlock |
157 | | { |
158 | | friend class QSyntaxHighlighter; |
159 | | public: |
160 | 0 | inline QTextBlock(QTextDocumentPrivate *priv, int b) : p(priv), n(b) {} |
161 | 0 | inline QTextBlock() : p(nullptr), n(0) {} |
162 | 0 | inline QTextBlock(const QTextBlock &o) : p(o.p), n(o.n) {} |
163 | 0 | inline QTextBlock &operator=(const QTextBlock &o) { p = o.p; n = o.n; return *this; } |
164 | | |
165 | | bool isValid() const; |
166 | | |
167 | 0 | inline bool operator==(const QTextBlock &o) const { return p == o.p && n == o.n; } |
168 | 0 | inline bool operator!=(const QTextBlock &o) const { return p != o.p || n != o.n; } |
169 | 0 | inline bool operator<(const QTextBlock &o) const { return position() < o.position(); } |
170 | | |
171 | | int position() const; |
172 | | int length() const; |
173 | | bool contains(int position) const; |
174 | | |
175 | | QTextLayout *layout() const; |
176 | | void clearLayout(); |
177 | | QTextBlockFormat blockFormat() const; |
178 | | int blockFormatIndex() const; |
179 | | QTextCharFormat charFormat() const; |
180 | | int charFormatIndex() const; |
181 | | |
182 | | Qt::LayoutDirection textDirection() const; |
183 | | |
184 | | QString text() const; |
185 | | |
186 | | QList<QTextLayout::FormatRange> textFormats() const; |
187 | | |
188 | | const QTextDocument *document() const; |
189 | | |
190 | | QTextList *textList() const; |
191 | | |
192 | | QTextBlockUserData *userData() const; |
193 | | void setUserData(QTextBlockUserData *data); |
194 | | |
195 | | int userState() const; |
196 | | void setUserState(int state); |
197 | | |
198 | | int revision() const; |
199 | | void setRevision(int rev); |
200 | | |
201 | | bool isVisible() const; |
202 | | void setVisible(bool visible); |
203 | | |
204 | | int blockNumber() const; |
205 | | int firstLineNumber() const; |
206 | | |
207 | | void setLineCount(int count); |
208 | | int lineCount() const; |
209 | | |
210 | | class iterator { |
211 | | const QTextDocumentPrivate *p = nullptr; |
212 | | int b = 0; |
213 | | int e = 0; |
214 | | int n = 0; |
215 | | friend class QTextBlock; |
216 | | iterator(const QTextDocumentPrivate *priv, int begin, int end, int f) |
217 | 0 | : p(priv), b(begin), e(end), n(f) {} |
218 | | public: |
219 | 0 | constexpr iterator() = default; |
220 | | |
221 | | Q_GUI_EXPORT QTextFragment fragment() const; |
222 | | |
223 | 0 | bool atEnd() const { return n == e; } |
224 | | |
225 | 0 | inline bool operator==(const iterator &o) const { return p == o.p && n == o.n; } |
226 | 0 | inline bool operator!=(const iterator &o) const { return p != o.p || n != o.n; } |
227 | | Q_GUI_EXPORT iterator &operator++(); |
228 | 0 | inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; } |
229 | | Q_GUI_EXPORT iterator &operator--(); |
230 | 0 | inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; } |
231 | | }; |
232 | | |
233 | | // more Qt |
234 | | typedef iterator Iterator; |
235 | | |
236 | | iterator begin() const; |
237 | | iterator end() const; |
238 | | |
239 | | QTextBlock next() const; |
240 | | QTextBlock previous() const; |
241 | | |
242 | 0 | inline int fragmentIndex() const { return n; } |
243 | | |
244 | | private: |
245 | | QTextDocumentPrivate *p; |
246 | | int n; |
247 | | friend class QTextDocumentPrivate; |
248 | | friend class QTextLayout; |
249 | | }; |
250 | | |
251 | | Q_DECLARE_TYPEINFO(QTextBlock, Q_RELOCATABLE_TYPE); |
252 | | Q_DECLARE_TYPEINFO(QTextBlock::iterator, Q_RELOCATABLE_TYPE); |
253 | | |
254 | | |
255 | | class Q_GUI_EXPORT QTextFragment |
256 | | { |
257 | | public: |
258 | 0 | inline QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) : p(priv), n(f), ne(fe) {} |
259 | 0 | inline QTextFragment() : p(nullptr), n(0), ne(0) {} |
260 | 0 | inline QTextFragment(const QTextFragment &o) : p(o.p), n(o.n), ne(o.ne) {} |
261 | 0 | inline QTextFragment &operator=(const QTextFragment &o) { p = o.p; n = o.n; ne = o.ne; return *this; } |
262 | | |
263 | 0 | inline bool isValid() const { return p && n; } |
264 | | |
265 | 0 | inline bool operator==(const QTextFragment &o) const { return p == o.p && n == o.n; } |
266 | 0 | inline bool operator!=(const QTextFragment &o) const { return p != o.p || n != o.n; } |
267 | 0 | inline bool operator<(const QTextFragment &o) const { return position() < o.position(); } |
268 | | |
269 | | int position() const; |
270 | | int length() const; |
271 | | bool contains(int position) const; |
272 | | |
273 | | QTextCharFormat charFormat() const; |
274 | | int charFormatIndex() const; |
275 | | QString text() const; |
276 | | |
277 | | #if !defined(QT_NO_RAWFONT) |
278 | | QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const; |
279 | | #endif |
280 | | |
281 | | private: |
282 | | const QTextDocumentPrivate *p; |
283 | | int n; |
284 | | int ne; |
285 | | }; |
286 | | |
287 | | Q_DECLARE_TYPEINFO(QTextFragment, Q_RELOCATABLE_TYPE); |
288 | | |
289 | | QT_END_NAMESPACE |
290 | | |
291 | | #endif // QTEXTOBJECT_H |