1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QTEXTCURSOR_P_H |
5 | #define QTEXTCURSOR_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of other Qt classes. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtGui/private/qtguiglobal_p.h> |
19 | #include "qtextcursor.h" |
20 | #include "qtextdocument.h" |
21 | #include "qtextdocument_p.h" |
22 | #include <private/qtextformat_p.h> |
23 | #include "qtextobject.h" |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | class Q_GUI_EXPORT QTextCursorPrivate : public QSharedData |
28 | { |
29 | public: |
30 | QTextCursorPrivate(QTextDocumentPrivate *p); |
31 | QTextCursorPrivate(const QTextCursorPrivate &rhs); |
32 | ~QTextCursorPrivate(); |
33 | |
34 | static inline QTextCursorPrivate *getPrivate(QTextCursor *c) { return c->d; } |
35 | |
36 | enum AdjustResult { CursorMoved, CursorUnchanged }; |
37 | AdjustResult adjustPosition(int positionOfChange, int charsAddedOrRemoved, QTextUndoCommand::Operation op); |
38 | |
39 | void adjustCursor(QTextCursor::MoveOperation m); |
40 | |
41 | void remove(); |
42 | void clearCells(QTextTable *table, int startRow, int startCol, int numRows, int numCols, QTextUndoCommand::Operation op); |
43 | inline bool setPosition(int newPosition) { |
44 | Q_ASSERT(newPosition >= 0 && newPosition < priv->length()); |
45 | bool moved = position != newPosition; |
46 | if (moved) { |
47 | position = newPosition; |
48 | currentCharFormat = -1; |
49 | } |
50 | return moved; |
51 | } |
52 | void setX(); |
53 | bool canDelete(int pos) const; |
54 | |
55 | void insertBlock(const QTextBlockFormat &format, const QTextCharFormat &charFormat); |
56 | bool movePosition(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); |
57 | |
58 | inline QTextBlock block() const |
59 | { return QTextBlock(priv, priv->blockMap().findNode(k: position)); } |
60 | inline QTextBlockFormat blockFormat() const |
61 | { return block().blockFormat(); } |
62 | |
63 | QTextLayout *blockLayout(QTextBlock &block) const; |
64 | |
65 | QTextTable *complexSelectionTable() const; |
66 | void selectedTableCells(int *firstRow, int *numRows, int *firstColumn, int *numColumns) const; |
67 | |
68 | void setBlockCharFormat(const QTextCharFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode); |
69 | void setBlockFormat(const QTextBlockFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode); |
70 | void setCharFormat(const QTextCharFormat &format, QTextDocumentPrivate::FormatChangeMode changeMode); |
71 | |
72 | void aboutToRemoveCell(int from, int to); |
73 | |
74 | static QTextCursor fromPosition(QTextDocumentPrivate *d, int pos) |
75 | { return QTextCursor(d, pos); } |
76 | |
77 | QTextDocumentPrivate *priv; |
78 | qreal x; |
79 | int position; |
80 | int anchor; |
81 | int adjusted_anchor; |
82 | int currentCharFormat; |
83 | uint visualNavigation : 1; |
84 | uint keepPositionOnInsert : 1; |
85 | uint changed : 1; |
86 | }; |
87 | |
88 | QT_END_NAMESPACE |
89 | |
90 | #endif // QTEXTCURSOR_P_H |
91 | |