Qt 4.8
qtextcursor.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
50 
52 
53 QT_MODULE(Gui)
54 
55 class QTextDocument;
56 class QTextCursorPrivate;
58 class QTextCharFormat;
59 class QTextBlockFormat;
60 class QTextListFormat;
61 class QTextTableFormat;
62 class QTextFrameFormat;
63 class QTextImageFormat;
65 class QTextList;
66 class QTextTable;
67 class QTextFrame;
68 class QTextBlock;
69 
71 {
72 public:
73  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);
81  ~QTextCursor();
82 
83  bool isNull() const;
84 
85  enum MoveMode {
87  KeepAnchor
88  };
89 
90  void setPosition(int pos, MoveMode mode = MoveAnchor);
91  int position() const;
92  int positionInBlock() const;
93 
94  int anchor() const;
95 
96  void insertText(const QString &text);
97  void insertText(const QString &text, const QTextCharFormat &format);
98 
101 
103  Up,
112 
123 
127  PreviousRow
128  };
129 
130  bool movePosition(MoveOperation op, MoveMode = MoveAnchor, int n = 1);
131 
132  bool visualNavigation() const;
133  void setVisualNavigation(bool b);
134 
135  void setVerticalMovementX(int x);
136  int verticalMovementX() const;
137 
138  void setKeepPositionOnInsert(bool b);
139  bool keepPositionOnInsert() const;
140 
141  void deleteChar();
142  void deletePreviousChar();
143 
149  };
150  void select(SelectionType selection);
151 
152  bool hasSelection() const;
153  bool hasComplexSelection() const;
154  void removeSelectedText();
155  void clearSelection();
156  int selectionStart() const;
157  int selectionEnd() const;
158 
159  QString selectedText() const;
160  QTextDocumentFragment selection() const;
161  void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const;
162 
163  QTextBlock block() const;
164 
165  QTextCharFormat charFormat() const;
166  void setCharFormat(const QTextCharFormat &format);
167  void mergeCharFormat(const QTextCharFormat &modifier);
168 
169  QTextBlockFormat blockFormat() const;
170  void setBlockFormat(const QTextBlockFormat &format);
171  void mergeBlockFormat(const QTextBlockFormat &modifier);
172 
173  QTextCharFormat blockCharFormat() const;
174  void setBlockCharFormat(const QTextCharFormat &format);
175  void mergeBlockCharFormat(const QTextCharFormat &modifier);
176 
177  bool atBlockStart() const;
178  bool atBlockEnd() const;
179  bool atStart() const;
180  bool atEnd() const;
181 
182  void insertBlock();
183  void insertBlock(const QTextBlockFormat &format);
184  void insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat);
185 
186  QTextList *insertList(const QTextListFormat &format);
187  QTextList *insertList(QTextListFormat::Style style);
188 
189  QTextList *createList(const QTextListFormat &format);
190  QTextList *createList(QTextListFormat::Style style);
191  QTextList *currentList() const;
192 
193  QTextTable *insertTable(int rows, int cols, const QTextTableFormat &format);
194  QTextTable *insertTable(int rows, int cols);
195  QTextTable *currentTable() const;
196 
197  QTextFrame *insertFrame(const QTextFrameFormat &format);
198  QTextFrame *currentFrame() const;
199 
200  void insertFragment(const QTextDocumentFragment &fragment);
201 
202 #ifndef QT_NO_TEXTHTMLPARSER
203  void insertHtml(const QString &html);
204 #endif // QT_NO_TEXTHTMLPARSER
205 
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());
210 
211  void beginEditBlock();
212  void joinPreviousEditBlock();
213  void endEditBlock();
214 
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;
221 
222  bool isCopyOf(const QTextCursor &other) const;
223 
224  int blockNumber() const;
225  int columnNumber() const;
226 
227  QTextDocument *document() const;
228 
229 private:
232  friend class QTextCopyHelper;
233  friend class QTextControlPrivate;
234 };
235 
237 
239 
240 #endif // QTEXTCURSOR_H
double d
Definition: qnumeric_p.h:62
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
The QTextListFormat class provides formatting information for lists in a QTextDocument.
Definition: qtextformat.h:642
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
bool operator>(const QByteArray &a1, const QByteArray &a2)
Definition: qbytearray.h:551
The QTextFrame class represents a frame in a QTextDocument.
Definition: qtextobject.h:122
Position
This enum describes how a frame is located relative to the surrounding text.
Definition: qtextformat.h:734
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
bool operator!=(QBool b1, bool b2)
Definition: qglobal.h:2026
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool operator<(int priority, const QPair< QRunnable *, int > &p)
Definition: qthreadpool.cpp:50
QSharedDataPointer< QTextCursorPrivate > d
Definition: qtextcursor.h:230
bool operator<=(const QByteArray &a1, const QByteArray &a2)
Definition: qbytearray.h:545
The QTextImageFormat class provides formatting information for images in a QTextDocument.
Definition: qtextformat.h:694
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
MoveMode
If the anchor() is kept where it is and the position() is moved, the text in between will be selected...
Definition: qtextcursor.h:85
Style
This enum describes the symbols used to decorate list items:
Definition: qtextformat.h:649
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
const char * name
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QTextBlock class provides a container for text fragments in a QTextDocument.
Definition: qtextobject.h:199
The QTextTable class represents a table in a QTextDocument.
Definition: qtexttable.h:103
SelectionType
This enum describes the types of selection that can be applied with the select() function.
Definition: qtextcursor.h:144
bool operator>=(const QByteArray &a1, const QByteArray &a2)
Definition: qbytearray.h:557
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
Definition: qtextformat.h:727
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
Definition: qtextformat.h:545
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
The QTextTableFormat class provides formatting information for tables in a QTextDocument.
Definition: qtextformat.h:842
The QTextList class provides a decorated list of items in a QTextDocument.
Definition: qtextlist.h:57
#define QT_END_HEADER
Definition: qglobal.h:137
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
The QTextDocumentFragment class represents a piece of formatted text from a QTextDocument.
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
#define text
Definition: qobjectdefs.h:80