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 QTEXTCURSOR_H |
5 | #define QTEXTCURSOR_H |
6 | |
7 | #include <QtGui/qtguiglobal.h> |
8 | #include <QtCore/qstring.h> |
9 | #include <QtCore/qshareddata.h> |
10 | #include <QtGui/qtextdocument.h> |
11 | #include <QtGui/qtextformat.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QTextCursorPrivate; |
16 | class QTextDocumentFragment; |
17 | class QTextCharFormat; |
18 | class QTextBlockFormat; |
19 | class QTextListFormat; |
20 | class QTextTableFormat; |
21 | class QTextFrameFormat; |
22 | class QTextImageFormat; |
23 | class QTextDocumentPrivate; |
24 | class QTextList; |
25 | class QTextTable; |
26 | class QTextFrame; |
27 | class QTextBlock; |
28 | |
29 | class Q_GUI_EXPORT QTextCursor |
30 | { |
31 | public: |
32 | QTextCursor(); |
33 | explicit QTextCursor(QTextDocument *document); |
34 | QTextCursor(QTextDocumentPrivate *p, int pos); |
35 | explicit QTextCursor(QTextCursorPrivate *d); |
36 | explicit QTextCursor(QTextFrame *frame); |
37 | explicit QTextCursor(const QTextBlock &block); |
38 | QTextCursor(const QTextCursor &cursor); |
39 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QTextCursor) |
40 | QTextCursor &operator=(const QTextCursor &other); |
41 | ~QTextCursor(); |
42 | |
43 | void swap(QTextCursor &other) noexcept { d.swap(other&: other.d); } |
44 | |
45 | bool isNull() const; |
46 | |
47 | enum MoveMode { |
48 | MoveAnchor, |
49 | KeepAnchor |
50 | }; |
51 | |
52 | void setPosition(int pos, MoveMode mode = MoveAnchor); |
53 | int position() const; |
54 | int positionInBlock() const; |
55 | |
56 | int anchor() const; |
57 | |
58 | void insertText(const QString &text); |
59 | void insertText(const QString &text, const QTextCharFormat &format); |
60 | |
61 | enum MoveOperation { |
62 | NoMove, |
63 | |
64 | Start, |
65 | Up, |
66 | StartOfLine, |
67 | StartOfBlock, |
68 | StartOfWord, |
69 | PreviousBlock, |
70 | PreviousCharacter, |
71 | PreviousWord, |
72 | Left, |
73 | WordLeft, |
74 | |
75 | End, |
76 | Down, |
77 | EndOfLine, |
78 | EndOfWord, |
79 | EndOfBlock, |
80 | NextBlock, |
81 | NextCharacter, |
82 | NextWord, |
83 | Right, |
84 | WordRight, |
85 | |
86 | NextCell, |
87 | PreviousCell, |
88 | NextRow, |
89 | PreviousRow |
90 | }; |
91 | |
92 | bool movePosition(MoveOperation op, MoveMode = MoveAnchor, int n = 1); |
93 | |
94 | bool visualNavigation() const; |
95 | void setVisualNavigation(bool b); |
96 | |
97 | void setVerticalMovementX(int x); |
98 | int verticalMovementX() const; |
99 | |
100 | void setKeepPositionOnInsert(bool b); |
101 | bool keepPositionOnInsert() const; |
102 | |
103 | void deleteChar(); |
104 | void deletePreviousChar(); |
105 | |
106 | enum SelectionType { |
107 | WordUnderCursor, |
108 | LineUnderCursor, |
109 | BlockUnderCursor, |
110 | Document |
111 | }; |
112 | void select(SelectionType selection); |
113 | |
114 | bool hasSelection() const; |
115 | bool hasComplexSelection() const; |
116 | void removeSelectedText(); |
117 | void clearSelection(); |
118 | int selectionStart() const; |
119 | int selectionEnd() const; |
120 | |
121 | QString selectedText() const; |
122 | QTextDocumentFragment selection() const; |
123 | void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const; |
124 | |
125 | QTextBlock block() const; |
126 | |
127 | QTextCharFormat charFormat() const; |
128 | void setCharFormat(const QTextCharFormat &format); |
129 | void mergeCharFormat(const QTextCharFormat &modifier); |
130 | |
131 | QTextBlockFormat blockFormat() const; |
132 | void setBlockFormat(const QTextBlockFormat &format); |
133 | void mergeBlockFormat(const QTextBlockFormat &modifier); |
134 | |
135 | QTextCharFormat blockCharFormat() const; |
136 | void setBlockCharFormat(const QTextCharFormat &format); |
137 | void mergeBlockCharFormat(const QTextCharFormat &modifier); |
138 | |
139 | bool atBlockStart() const; |
140 | bool atBlockEnd() const; |
141 | bool atStart() const; |
142 | bool atEnd() const; |
143 | |
144 | void insertBlock(); |
145 | void insertBlock(const QTextBlockFormat &format); |
146 | void insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat); |
147 | |
148 | QTextList *insertList(const QTextListFormat &format); |
149 | QTextList *insertList(QTextListFormat::Style style); |
150 | |
151 | QTextList *createList(const QTextListFormat &format); |
152 | QTextList *createList(QTextListFormat::Style style); |
153 | QTextList *currentList() const; |
154 | |
155 | QTextTable *insertTable(int rows, int cols, const QTextTableFormat &format); |
156 | QTextTable *insertTable(int rows, int cols); |
157 | QTextTable *currentTable() const; |
158 | |
159 | QTextFrame *insertFrame(const QTextFrameFormat &format); |
160 | QTextFrame *currentFrame() const; |
161 | |
162 | void insertFragment(const QTextDocumentFragment &fragment); |
163 | |
164 | #ifndef QT_NO_TEXTHTMLPARSER |
165 | void insertHtml(const QString &html); |
166 | #endif // QT_NO_TEXTHTMLPARSER |
167 | #if QT_CONFIG(textmarkdownreader) |
168 | void insertMarkdown(const QString &markdown, |
169 | QTextDocument::MarkdownFeatures features = QTextDocument::MarkdownDialectGitHub); |
170 | #endif // textmarkdownreader |
171 | |
172 | void insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment); |
173 | void insertImage(const QTextImageFormat &format); |
174 | void insertImage(const QString &name); |
175 | void insertImage(const QImage &image, const QString &name = QString()); |
176 | |
177 | void beginEditBlock(); |
178 | void joinPreviousEditBlock(); |
179 | void endEditBlock(); |
180 | |
181 | bool operator!=(const QTextCursor &rhs) const; |
182 | bool operator<(const QTextCursor &rhs) const; |
183 | bool operator<=(const QTextCursor &rhs) const; |
184 | bool operator==(const QTextCursor &rhs) const; |
185 | bool operator>=(const QTextCursor &rhs) const; |
186 | bool operator>(const QTextCursor &rhs) const; |
187 | |
188 | bool isCopyOf(const QTextCursor &other) const; |
189 | |
190 | int blockNumber() const; |
191 | int columnNumber() const; |
192 | |
193 | QTextDocument *document() const; |
194 | |
195 | private: |
196 | QSharedDataPointer<QTextCursorPrivate> d; |
197 | friend class QTextCursorPrivate; |
198 | friend class QTextDocumentPrivate; |
199 | friend class QTextDocumentFragmentPrivate; |
200 | friend class QTextCopyHelper; |
201 | friend class QWidgetTextControlPrivate; |
202 | }; |
203 | |
204 | Q_DECLARE_SHARED(QTextCursor) |
205 | |
206 | QT_END_NAMESPACE |
207 | |
208 | #endif // QTEXTCURSOR_H |
209 | |