1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QTEXTCURSOR_H
41#define QTEXTCURSOR_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtCore/qstring.h>
45#include <QtCore/qshareddata.h>
46#include <QtGui/qtextformat.h>
47
48QT_BEGIN_NAMESPACE
49
50
51class QTextDocument;
52class QTextCursorPrivate;
53class QTextDocumentFragment;
54class QTextCharFormat;
55class QTextBlockFormat;
56class QTextListFormat;
57class QTextTableFormat;
58class QTextFrameFormat;
59class QTextImageFormat;
60class QTextDocumentPrivate;
61class QTextList;
62class QTextTable;
63class QTextFrame;
64class QTextBlock;
65
66class Q_GUI_EXPORT QTextCursor
67{
68public:
69 QTextCursor();
70 explicit QTextCursor(QTextDocument *document);
71 QTextCursor(QTextDocumentPrivate *p, int pos);
72 explicit QTextCursor(QTextCursorPrivate *d);
73 explicit QTextCursor(QTextFrame *frame);
74 explicit QTextCursor(const QTextBlock &block);
75 QTextCursor(const QTextCursor &cursor);
76#ifdef Q_COMPILER_RVALUE_REFS
77 QTextCursor &operator=(QTextCursor &&other) Q_DECL_NOTHROW { swap(other); return *this; }
78#endif
79 QTextCursor &operator=(const QTextCursor &other);
80 ~QTextCursor();
81
82 void swap(QTextCursor &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
83
84 bool isNull() const;
85
86 enum MoveMode {
87 MoveAnchor,
88 KeepAnchor
89 };
90
91 void setPosition(int pos, MoveMode mode = MoveAnchor);
92 int position() const;
93 int positionInBlock() const;
94
95 int anchor() const;
96
97 void insertText(const QString &text);
98 void insertText(const QString &text, const QTextCharFormat &format);
99
100 enum MoveOperation {
101 NoMove,
102
103 Start,
104 Up,
105 StartOfLine,
106 StartOfBlock,
107 StartOfWord,
108 PreviousBlock,
109 PreviousCharacter,
110 PreviousWord,
111 Left,
112 WordLeft,
113
114 End,
115 Down,
116 EndOfLine,
117 EndOfWord,
118 EndOfBlock,
119 NextBlock,
120 NextCharacter,
121 NextWord,
122 Right,
123 WordRight,
124
125 NextCell,
126 PreviousCell,
127 NextRow,
128 PreviousRow
129 };
130
131 bool movePosition(MoveOperation op, MoveMode = MoveAnchor, int n = 1);
132
133 bool visualNavigation() const;
134 void setVisualNavigation(bool b);
135
136 void setVerticalMovementX(int x);
137 int verticalMovementX() const;
138
139 void setKeepPositionOnInsert(bool b);
140 bool keepPositionOnInsert() const;
141
142 void deleteChar();
143 void deletePreviousChar();
144
145 enum SelectionType {
146 WordUnderCursor,
147 LineUnderCursor,
148 BlockUnderCursor,
149 Document
150 };
151 void select(SelectionType selection);
152
153 bool hasSelection() const;
154 bool hasComplexSelection() const;
155 void removeSelectedText();
156 void clearSelection();
157 int selectionStart() const;
158 int selectionEnd() const;
159
160 QString selectedText() const;
161 QTextDocumentFragment selection() const;
162 void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const;
163
164 QTextBlock block() const;
165
166 QTextCharFormat charFormat() const;
167 void setCharFormat(const QTextCharFormat &format);
168 void mergeCharFormat(const QTextCharFormat &modifier);
169
170 QTextBlockFormat blockFormat() const;
171 void setBlockFormat(const QTextBlockFormat &format);
172 void mergeBlockFormat(const QTextBlockFormat &modifier);
173
174 QTextCharFormat blockCharFormat() const;
175 void setBlockCharFormat(const QTextCharFormat &format);
176 void mergeBlockCharFormat(const QTextCharFormat &modifier);
177
178 bool atBlockStart() const;
179 bool atBlockEnd() const;
180 bool atStart() const;
181 bool atEnd() const;
182
183 void insertBlock();
184 void insertBlock(const QTextBlockFormat &format);
185 void insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat);
186
187 QTextList *insertList(const QTextListFormat &format);
188 QTextList *insertList(QTextListFormat::Style style);
189
190 QTextList *createList(const QTextListFormat &format);
191 QTextList *createList(QTextListFormat::Style style);
192 QTextList *currentList() const;
193
194 QTextTable *insertTable(int rows, int cols, const QTextTableFormat &format);
195 QTextTable *insertTable(int rows, int cols);
196 QTextTable *currentTable() const;
197
198 QTextFrame *insertFrame(const QTextFrameFormat &format);
199 QTextFrame *currentFrame() const;
200
201 void insertFragment(const QTextDocumentFragment &fragment);
202
203#ifndef QT_NO_TEXTHTMLPARSER
204 void insertHtml(const QString &html);
205#endif // QT_NO_TEXTHTMLPARSER
206
207 void insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment);
208 void insertImage(const QTextImageFormat &format);
209 void insertImage(const QString &name);
210 void insertImage(const QImage &image, const QString &name = QString());
211
212 void beginEditBlock();
213 void joinPreviousEditBlock();
214 void endEditBlock();
215
216 bool operator!=(const QTextCursor &rhs) const;
217 bool operator<(const QTextCursor &rhs) const;
218 bool operator<=(const QTextCursor &rhs) const;
219 bool operator==(const QTextCursor &rhs) const;
220 bool operator>=(const QTextCursor &rhs) const;
221 bool operator>(const QTextCursor &rhs) const;
222
223 bool isCopyOf(const QTextCursor &other) const;
224
225 int blockNumber() const;
226 int columnNumber() const;
227
228 QTextDocument *document() const;
229
230private:
231 QSharedDataPointer<QTextCursorPrivate> d;
232 friend class QTextCursorPrivate;
233 friend class QTextDocumentPrivate;
234 friend class QTextDocumentFragmentPrivate;
235 friend class QTextCopyHelper;
236 friend class QWidgetTextControlPrivate;
237};
238
239Q_DECLARE_SHARED(QTextCursor)
240
241QT_END_NAMESPACE
242
243#endif // QTEXTCURSOR_H
244