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