qtextcursor.h
上传用户:detong
上传日期:2022-06-22
资源大小:20675k
文件大小:6k
源码类别:

系统编程

开发平台:

Unix_Linux

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
  4. ** Contact: Qt Software Information (qt-info@nokia.com)
  5. **
  6. ** This file is part of the QtGui module of the Qt Toolkit.
  7. **
  8. ** Commercial Usage
  9. ** Licensees holding valid Qt Commercial licenses may use this file in
  10. ** accordance with the Qt Commercial License Agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Nokia.
  13. **
  14. **
  15. ** GNU General Public License Usage
  16. ** Alternatively, this file may be used under the terms of the GNU
  17. ** General Public License versions 2.0 or 3.0 as published by the Free
  18. ** Software Foundation and appearing in the file LICENSE.GPL included in
  19. ** the packaging of this file.  Please review the following information
  20. ** to ensure GNU General Public Licensing requirements will be met:
  21. ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
  22. ** http://www.gnu.org/copyleft/gpl.html.  In addition, as a special
  23. ** exception, Nokia gives you certain additional rights. These rights
  24. ** are described in the Nokia Qt GPL Exception version 1.3, included in
  25. ** the file GPL_EXCEPTION.txt in this package.
  26. **
  27. ** Qt for Windows(R) Licensees
  28. ** As a special exception, Nokia, as the sole copyright holder for Qt
  29. ** Designer, grants users of the Qt/Eclipse Integration plug-in the
  30. ** right for the Qt/Eclipse Integration to link to functionality
  31. ** provided by Qt Designer and its related libraries.
  32. **
  33. ** If you are unsure which license is appropriate for your use, please
  34. ** contact the sales department at qt-sales@nokia.com.
  35. **
  36. ****************************************************************************/
  37. #ifndef QTEXTCURSOR_H
  38. #define QTEXTCURSOR_H
  39. #include <QtCore/qstring.h>
  40. #include <QtCore/qshareddata.h>
  41. #include <QtGui/qtextformat.h>
  42. QT_BEGIN_HEADER
  43. QT_BEGIN_NAMESPACE
  44. QT_MODULE(Gui)
  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(QTextFrame *frame);
  66.     explicit QTextCursor(const QTextBlock &block);
  67.     explicit QTextCursor(QTextCursorPrivate *d);
  68.     QTextCursor(const QTextCursor &cursor);
  69.     QTextCursor &operator=(const QTextCursor &other);
  70.     ~QTextCursor();
  71.     bool isNull() const;
  72.     enum MoveMode {
  73.         MoveAnchor,
  74.         KeepAnchor
  75.     };
  76.     void setPosition(int pos, MoveMode mode = MoveAnchor);
  77.     int position() const;
  78.     int anchor() const;
  79.     void insertText(const QString &text);
  80.     void insertText(const QString &text, const QTextCharFormat &format);
  81.     enum MoveOperation {
  82.         NoMove,
  83.         Start,
  84.         Up,
  85.         StartOfLine,
  86.         StartOfBlock,
  87.         StartOfWord,
  88.         PreviousBlock,
  89.         PreviousCharacter,
  90.         PreviousWord,
  91.         Left,
  92.         WordLeft,
  93.         End,
  94.         Down,
  95.         EndOfLine,
  96.         EndOfWord,
  97.         EndOfBlock,
  98.         NextBlock,
  99.         NextCharacter,
  100.         NextWord,
  101.         Right,
  102.         WordRight
  103.     };
  104.     bool movePosition(MoveOperation op, MoveMode = MoveAnchor, int n = 1);
  105.     bool visualNavigation() const;
  106.     void setVisualNavigation(bool b);
  107.     void deleteChar();
  108.     void deletePreviousChar();
  109.     enum SelectionType {
  110.         WordUnderCursor,
  111.         LineUnderCursor,
  112.         BlockUnderCursor,
  113.         Document
  114.     };
  115.     void select(SelectionType selection);
  116.     bool hasSelection() const;
  117.     bool hasComplexSelection() const;
  118.     void removeSelectedText();
  119.     void clearSelection();
  120.     int selectionStart() const;
  121.     int selectionEnd() const;
  122.     QString selectedText() const;
  123.     QTextDocumentFragment selection() const;
  124.     void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const;
  125.     QTextBlock block() const;
  126.     QTextCharFormat charFormat() const;
  127.     void setCharFormat(const QTextCharFormat &format);
  128.     void mergeCharFormat(const QTextCharFormat &modifier);
  129.     QTextBlockFormat blockFormat() const;
  130.     void setBlockFormat(const QTextBlockFormat &format);
  131.     void mergeBlockFormat(const QTextBlockFormat &modifier);
  132.     QTextCharFormat blockCharFormat() const;
  133.     void setBlockCharFormat(const QTextCharFormat &format);
  134.     void mergeBlockCharFormat(const QTextCharFormat &modifier);
  135.     bool atBlockStart() const;
  136.     bool atBlockEnd() const;
  137.     bool atStart() const;
  138.     bool atEnd() const;
  139.     void insertBlock();
  140.     void insertBlock(const QTextBlockFormat &format);
  141.     void insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat);
  142.     QTextList *insertList(const QTextListFormat &format);
  143.     QTextList *insertList(QTextListFormat::Style style);
  144.     QTextList *createList(const QTextListFormat &format);
  145.     QTextList *createList(QTextListFormat::Style style);
  146.     QTextList *currentList() const;
  147.     QTextTable *insertTable(int rows, int cols, const QTextTableFormat &format);
  148.     QTextTable *insertTable(int rows, int cols);
  149.     QTextTable *currentTable() const;
  150.     QTextFrame *insertFrame(const QTextFrameFormat &format);
  151.     QTextFrame *currentFrame() const;
  152.     void insertFragment(const QTextDocumentFragment &fragment);
  153. #ifndef QT_NO_TEXTHTMLPARSER
  154.     void insertHtml(const QString &html);
  155. #endif // QT_NO_TEXTHTMLPARSER
  156.     void insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment);
  157.     void insertImage(const QTextImageFormat &format);
  158.     void insertImage(const QString &name);
  159.     void beginEditBlock();
  160.     void joinPreviousEditBlock();
  161.     void endEditBlock();
  162.     bool operator!=(const QTextCursor &rhs) const;
  163.     bool operator<(const QTextCursor &rhs) const;
  164.     bool operator<=(const QTextCursor &rhs) const;
  165.     bool operator==(const QTextCursor &rhs) const;
  166.     bool operator>=(const QTextCursor &rhs) const;
  167.     bool operator>(const QTextCursor &rhs) const;
  168.     bool isCopyOf(const QTextCursor &other) const;
  169.     int blockNumber() const;
  170.     int columnNumber() const;
  171. private:
  172.     QSharedDataPointer<QTextCursorPrivate> d;
  173.     friend class QTextDocumentFragmentPrivate;
  174.     friend class QTextCopyHelper;
  175. };
  176. QT_END_NAMESPACE
  177. QT_END_HEADER
  178. #endif // QTEXTCURSOR_H