1 | // Copyright (C) 2019 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 QWIDGETTEXTCONTROL_P_P_H |
5 | #define QWIDGETTEXTCONTROL_P_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 purely as an |
12 | // implementation detail. 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 <QtWidgets/private/qtwidgetsglobal_p.h> |
19 | #include "QtGui/qtextdocumentfragment.h" |
20 | #include "QtGui/qtextcursor.h" |
21 | #include "QtGui/qtextformat.h" |
22 | #include "QtGui/qtextobject.h" |
23 | #if QT_CONFIG(menu) |
24 | #include "QtWidgets/qmenu.h" |
25 | #endif |
26 | #include "QtGui/qabstracttextdocumentlayout.h" |
27 | #include "QtCore/qbasictimer.h" |
28 | #include "QtCore/qpointer.h" |
29 | #include "private/qobject_p.h" |
30 | |
31 | QT_REQUIRE_CONFIG(widgettextcontrol); |
32 | |
33 | QT_BEGIN_NAMESPACE |
34 | |
35 | class QMimeData; |
36 | class QAbstractScrollArea; |
37 | |
38 | class QWidgetTextControlPrivate : public QObjectPrivate |
39 | { |
40 | public: |
41 | Q_DECLARE_PUBLIC(QWidgetTextControl) |
42 | |
43 | QWidgetTextControlPrivate(); |
44 | |
45 | bool cursorMoveKeyEvent(QKeyEvent *e); |
46 | |
47 | void updateCurrentCharFormat(); |
48 | |
49 | void indent(); |
50 | void outdent(); |
51 | |
52 | void gotoNextTableCell(); |
53 | void gotoPreviousTableCell(); |
54 | |
55 | void createAutoBulletList(); |
56 | |
57 | void init(Qt::TextFormat format = Qt::RichText, const QString &text = QString(), |
58 | QTextDocument *document = nullptr); |
59 | void setContent(Qt::TextFormat format = Qt::RichText, const QString &text = QString(), |
60 | QTextDocument *document = nullptr); |
61 | void startDrag(); |
62 | |
63 | void paste(const QMimeData *source); |
64 | |
65 | void setCursorPosition(const QPointF &pos); |
66 | void setCursorPosition(int pos, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor); |
67 | |
68 | void repaintCursor(); |
69 | inline void repaintSelection() |
70 | { repaintOldAndNewSelection(oldSelection: QTextCursor()); } |
71 | void repaintOldAndNewSelection(const QTextCursor &oldSelection); |
72 | |
73 | void selectionChanged(bool forceEmitSelectionChanged = false); |
74 | |
75 | void _q_updateCurrentCharFormatAndSelection(); |
76 | |
77 | #ifndef QT_NO_CLIPBOARD |
78 | void setClipboardSelection(); |
79 | #endif |
80 | |
81 | void _q_emitCursorPosChanged(const QTextCursor &someCursor); |
82 | void _q_contentsChanged(int from, int charsRemoved, int charsAdded); |
83 | |
84 | void setCursorVisible(bool visible); |
85 | void setBlinkingCursorEnabled(bool enable); |
86 | void updateCursorBlinking(); |
87 | |
88 | void extendWordwiseSelection(int suggestedNewPosition, qreal mouseXPosition); |
89 | void extendBlockwiseSelection(int suggestedNewPosition); |
90 | |
91 | void _q_deleteSelected(); |
92 | |
93 | void _q_setCursorAfterUndoRedo(int undoPosition, int charsAdded, int charsRemoved); |
94 | |
95 | QRectF cursorRectPlusUnicodeDirectionMarkers(const QTextCursor &cursor) const; |
96 | QRectF rectForPosition(int position) const; |
97 | QRectF selectionRect(const QTextCursor &cursor) const; |
98 | inline QRectF selectionRect() const |
99 | { return selectionRect(cursor: this->cursor); } |
100 | |
101 | QString anchorForCursor(const QTextCursor &anchor) const; |
102 | |
103 | void keyPressEvent(QKeyEvent *e); |
104 | void mousePressEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, |
105 | Qt::KeyboardModifiers modifiers, |
106 | Qt::MouseButtons buttons, |
107 | const QPoint &globalPos); |
108 | void mouseMoveEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, |
109 | Qt::KeyboardModifiers modifiers, |
110 | Qt::MouseButtons buttons, |
111 | const QPoint &globalPos); |
112 | void mouseReleaseEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, |
113 | Qt::KeyboardModifiers modifiers, |
114 | Qt::MouseButtons buttons, |
115 | const QPoint &globalPos); |
116 | void mouseDoubleClickEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, |
117 | Qt::KeyboardModifiers modifiers, |
118 | Qt::MouseButtons buttons, |
119 | const QPoint &globalPos); |
120 | bool sendMouseEventToInputContext(QEvent *e, QEvent::Type eventType, Qt::MouseButton button, |
121 | const QPointF &pos, |
122 | Qt::KeyboardModifiers modifiers, |
123 | Qt::MouseButtons buttons, |
124 | const QPoint &globalPos); |
125 | void (const QPoint &screenPos, const QPointF &docPos, QWidget *contextWidget); |
126 | void focusEvent(QFocusEvent *e); |
127 | #ifdef QT_KEYPAD_NAVIGATION |
128 | void editFocusEvent(QEvent *e); |
129 | #endif |
130 | bool dragEnterEvent(QEvent *e, const QMimeData *mimeData); |
131 | void dragLeaveEvent(); |
132 | bool dragMoveEvent(QEvent *e, const QMimeData *mimeData, const QPointF &pos); |
133 | bool dropEvent(const QMimeData *mimeData, const QPointF &pos, Qt::DropAction dropAction, QObject *source); |
134 | |
135 | void inputMethodEvent(QInputMethodEvent *); |
136 | |
137 | void activateLinkUnderCursor(QString href = QString()); |
138 | |
139 | #if QT_CONFIG(tooltip) |
140 | void showToolTip(const QPoint &globalPos, const QPointF &pos, QWidget *contextWidget); |
141 | #endif |
142 | |
143 | bool isPreediting() const; |
144 | void commitPreedit(); |
145 | |
146 | void insertParagraphSeparator(); |
147 | void append(const QString &text, Qt::TextFormat format = Qt::AutoText); |
148 | |
149 | QTextDocument *doc; |
150 | bool cursorOn; |
151 | bool cursorVisible; |
152 | QTextCursor cursor; |
153 | bool cursorIsFocusIndicator; |
154 | QTextCharFormat lastCharFormat; |
155 | |
156 | QTextCursor dndFeedbackCursor; |
157 | |
158 | Qt::TextInteractionFlags interactionFlags; |
159 | |
160 | QBasicTimer cursorBlinkTimer; |
161 | QBasicTimer trippleClickTimer; |
162 | QPointF trippleClickPoint; |
163 | |
164 | bool dragEnabled; |
165 | |
166 | bool mousePressed; |
167 | |
168 | bool mightStartDrag; |
169 | QPoint mousePressPos; |
170 | QPointer<QWidget> contextWidget; |
171 | |
172 | int lastSelectionPosition; |
173 | int lastSelectionAnchor; |
174 | |
175 | bool ignoreAutomaticScrollbarAdjustement; |
176 | |
177 | QTextCursor selectedWordOnDoubleClick; |
178 | QTextCursor selectedBlockOnTrippleClick; |
179 | |
180 | bool overwriteMode; |
181 | bool acceptRichText; |
182 | |
183 | int preeditCursor; |
184 | bool hideCursor; // used to hide the cursor in the preedit area |
185 | |
186 | QList<QAbstractTextDocumentLayout::Selection> ; |
187 | |
188 | QPalette palette; |
189 | bool hasFocus; |
190 | #ifdef QT_KEYPAD_NAVIGATION |
191 | bool hasEditFocus; |
192 | #endif |
193 | bool isEnabled; |
194 | |
195 | QString highlightedAnchor; // Anchor below cursor |
196 | QString anchorOnMousePress; |
197 | QTextBlock blockWithMarkerUnderMouse; |
198 | bool hadSelectionOnMousePress; |
199 | |
200 | bool ignoreUnusedNavigationEvents; |
201 | bool openExternalLinks; |
202 | |
203 | bool wordSelectionEnabled; |
204 | |
205 | QString linkToCopy; |
206 | void _q_copyLink(); |
207 | void _q_updateBlock(const QTextBlock &); |
208 | void _q_documentLayoutChanged(); |
209 | }; |
210 | |
211 | QT_END_NAMESPACE |
212 | |
213 | #endif // QWidgetTextControl_P_H |
214 | |