Get started with patching up the Qt GUI docs
[profile/ivi/qtbase.git] / src / gui / text / qtextcursor.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 QTEXTCURSOR_H
43 #define QTEXTCURSOR_H
44
45 #include <QtCore/qstring.h>
46 #include <QtCore/qshareddata.h>
47 #include <QtGui/qtextformat.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53
54 class QTextDocument;
55 class QTextCursorPrivate;
56 class QTextDocumentFragment;
57 class QTextCharFormat;
58 class QTextBlockFormat;
59 class QTextListFormat;
60 class QTextTableFormat;
61 class QTextFrameFormat;
62 class QTextImageFormat;
63 class QTextDocumentPrivate;
64 class QTextList;
65 class QTextTable;
66 class QTextFrame;
67 class QTextBlock;
68
69 class Q_GUI_EXPORT QTextCursor
70 {
71 public:
72     QTextCursor();
73     explicit QTextCursor(QTextDocument *document);
74     QTextCursor(QTextDocumentPrivate *p, int pos);
75     explicit QTextCursor(QTextFrame *frame);
76     explicit QTextCursor(const QTextBlock &block);
77     explicit QTextCursor(QTextCursorPrivate *d);
78     QTextCursor(const QTextCursor &cursor);
79     QTextCursor &operator=(const QTextCursor &other);
80     ~QTextCursor();
81
82     bool isNull() const;
83
84     enum MoveMode {
85         MoveAnchor,
86         KeepAnchor
87     };
88
89     void setPosition(int pos, MoveMode mode = MoveAnchor);
90     int position() const;
91     int positionInBlock() const;
92
93     int anchor() const;
94
95     void insertText(const QString &text);
96     void insertText(const QString &text, const QTextCharFormat &format);
97
98     enum MoveOperation {
99         NoMove,
100
101         Start,
102         Up,
103         StartOfLine,
104         StartOfBlock,
105         StartOfWord,
106         PreviousBlock,
107         PreviousCharacter,
108         PreviousWord,
109         Left,
110         WordLeft,
111
112         End,
113         Down,
114         EndOfLine,
115         EndOfWord,
116         EndOfBlock,
117         NextBlock,
118         NextCharacter,
119         NextWord,
120         Right,
121         WordRight,
122
123         NextCell,
124         PreviousCell,
125         NextRow,
126         PreviousRow
127     };
128
129     bool movePosition(MoveOperation op, MoveMode = MoveAnchor, int n = 1);
130
131     bool visualNavigation() const;
132     void setVisualNavigation(bool b);
133
134     void setVerticalMovementX(int x);
135     int verticalMovementX() const;
136
137     void setKeepPositionOnInsert(bool b);
138     bool keepPositionOnInsert() const;
139
140     void deleteChar();
141     void deletePreviousChar();
142
143     enum SelectionType {
144         WordUnderCursor,
145         LineUnderCursor,
146         BlockUnderCursor,
147         Document
148     };
149     void select(SelectionType selection);
150
151     bool hasSelection() const;
152     bool hasComplexSelection() const;
153     void removeSelectedText();
154     void clearSelection();
155     int selectionStart() const;
156     int selectionEnd() const;
157
158     QString selectedText() const;
159     QTextDocumentFragment selection() const;
160     void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const;
161
162     QTextBlock block() const;
163
164     QTextCharFormat charFormat() const;
165     void setCharFormat(const QTextCharFormat &format);
166     void mergeCharFormat(const QTextCharFormat &modifier);
167
168     QTextBlockFormat blockFormat() const;
169     void setBlockFormat(const QTextBlockFormat &format);
170     void mergeBlockFormat(const QTextBlockFormat &modifier);
171
172     QTextCharFormat blockCharFormat() const;
173     void setBlockCharFormat(const QTextCharFormat &format);
174     void mergeBlockCharFormat(const QTextCharFormat &modifier);
175
176     bool atBlockStart() const;
177     bool atBlockEnd() const;
178     bool atStart() const;
179     bool atEnd() const;
180
181     void insertBlock();
182     void insertBlock(const QTextBlockFormat &format);
183     void insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat);
184
185     QTextList *insertList(const QTextListFormat &format);
186     QTextList *insertList(QTextListFormat::Style style);
187
188     QTextList *createList(const QTextListFormat &format);
189     QTextList *createList(QTextListFormat::Style style);
190     QTextList *currentList() const;
191
192     QTextTable *insertTable(int rows, int cols, const QTextTableFormat &format);
193     QTextTable *insertTable(int rows, int cols);
194     QTextTable *currentTable() const;
195
196     QTextFrame *insertFrame(const QTextFrameFormat &format);
197     QTextFrame *currentFrame() const;
198
199     void insertFragment(const QTextDocumentFragment &fragment);
200
201 #ifndef QT_NO_TEXTHTMLPARSER
202     void insertHtml(const QString &html);
203 #endif // QT_NO_TEXTHTMLPARSER
204
205     void insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment);
206     void insertImage(const QTextImageFormat &format);
207     void insertImage(const QString &name);
208     void insertImage(const QImage &image, const QString &name = QString());
209
210     void beginEditBlock();
211     void joinPreviousEditBlock();
212     void endEditBlock();
213
214     bool operator!=(const QTextCursor &rhs) const;
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
221     bool isCopyOf(const QTextCursor &other) const;
222
223     int blockNumber() const;
224     int columnNumber() const;
225
226     QTextDocument *document() const;
227
228 private:
229     QSharedDataPointer<QTextCursorPrivate> d;
230     friend class QTextCursorPrivate;
231     friend class QTextDocumentFragmentPrivate;
232     friend class QTextCopyHelper;
233     friend class QWidgetTextControlPrivate;
234 };
235
236 QT_END_NAMESPACE
237
238 QT_END_HEADER
239
240 #endif // QTEXTCURSOR_H