qtextcursor.h 7.2 KB

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