1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtCore/qstring.h>
46 #include <QtCore/qshareddata.h>
47 #include <QtGui/qtextformat.h>
56 class QTextCursorPrivate;
57 class QTextDocumentFragment;
58 class QTextCharFormat;
59 class QTextBlockFormat;
60 class QTextListFormat;
61 class QTextTableFormat;
62 class QTextFrameFormat;
63 class QTextImageFormat;
64 class QTextDocumentPrivate;
70 class Q_GUI_EXPORT QTextCursor
74 explicit QTextCursor(QTextDocument *document);
75 QTextCursor(QTextDocumentPrivate *p, int pos);
76 explicit QTextCursor(QTextFrame *frame);
77 explicit QTextCursor(const QTextBlock &block);
78 explicit QTextCursor(QTextCursorPrivate *d);
79 QTextCursor(const QTextCursor &cursor);
80 QTextCursor &operator=(const QTextCursor &other);
90 void setPosition(int pos, MoveMode mode = MoveAnchor);
92 int positionInBlock() const;
96 void insertText(const QString &text);
97 void insertText(const QString &text, const QTextCharFormat &format);
130 bool movePosition(MoveOperation op, MoveMode = MoveAnchor, int n = 1);
132 bool visualNavigation() const;
133 void setVisualNavigation(bool b);
135 void setVerticalMovementX(int x);
136 int verticalMovementX() const;
138 void setKeepPositionOnInsert(bool b);
139 bool keepPositionOnInsert() const;
142 void deletePreviousChar();
150 void select(SelectionType selection);
152 bool hasSelection() const;
153 bool hasComplexSelection() const;
154 void removeSelectedText();
155 void clearSelection();
156 int selectionStart() const;
157 int selectionEnd() const;
159 QString selectedText() const;
160 QTextDocumentFragment selection() const;
161 void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const;
163 QTextBlock block() const;
165 QTextCharFormat charFormat() const;
166 void setCharFormat(const QTextCharFormat &format);
167 void mergeCharFormat(const QTextCharFormat &modifier);
169 QTextBlockFormat blockFormat() const;
170 void setBlockFormat(const QTextBlockFormat &format);
171 void mergeBlockFormat(const QTextBlockFormat &modifier);
173 QTextCharFormat blockCharFormat() const;
174 void setBlockCharFormat(const QTextCharFormat &format);
175 void mergeBlockCharFormat(const QTextCharFormat &modifier);
177 bool atBlockStart() const;
178 bool atBlockEnd() const;
179 bool atStart() const;
183 void insertBlock(const QTextBlockFormat &format);
184 void insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat);
186 QTextList *insertList(const QTextListFormat &format);
187 QTextList *insertList(QTextListFormat::Style style);
189 QTextList *createList(const QTextListFormat &format);
190 QTextList *createList(QTextListFormat::Style style);
191 QTextList *currentList() const;
193 QTextTable *insertTable(int rows, int cols, const QTextTableFormat &format);
194 QTextTable *insertTable(int rows, int cols);
195 QTextTable *currentTable() const;
197 QTextFrame *insertFrame(const QTextFrameFormat &format);
198 QTextFrame *currentFrame() const;
200 void insertFragment(const QTextDocumentFragment &fragment);
202 #ifndef QT_NO_TEXTHTMLPARSER
203 void insertHtml(const QString &html);
204 #endif // QT_NO_TEXTHTMLPARSER
206 void insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment);
207 void insertImage(const QTextImageFormat &format);
208 void insertImage(const QString &name);
209 void insertImage(const QImage &image, const QString &name = QString());
211 void beginEditBlock();
212 void joinPreviousEditBlock();
215 bool operator!=(const QTextCursor &rhs) const;
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;
222 bool isCopyOf(const QTextCursor &other) const;
224 int blockNumber() const;
225 int columnNumber() const;
227 QTextDocument *document() const;
230 QSharedDataPointer<QTextCursorPrivate> d;
231 friend class QTextCursorPrivate;
232 friend class QTextDocumentFragmentPrivate;
233 friend class QTextCopyHelper;
234 friend class QWidgetTextControlPrivate;
241 #endif // QTEXTCURSOR_H