Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquicktextedit_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKTEXTEDIT_P_H
6#define QQUICKTEXTEDIT_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
21
22#include <QtGui/qtextoption.h>
23
25
26class QTextDocument;
27class QQuickTextDocument;
28class QQuickTextEditPrivate;
29class QQuickTextSelection;
30class QTextBlock;
31class QQmlComponent;
32
34{
35 Q_GADGET
36 QML_ANONYMOUS
39};
40
41class Q_QUICK_EXPORT QQuickTextEdit : public QQuickImplicitSizeItem, public QQuickTextInterface
42{
43 Q_OBJECT
44 Q_INTERFACES(QQuickTextInterface)
45
46 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
47 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
48 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
49 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
50 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
51 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
52 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
53 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
54 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
55 Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged)
56 Q_PROPERTY(int length READ length NOTIFY textChanged)
57 Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged)
58 Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged)
59 Q_PROPERTY(qreal paintedWidth READ contentWidth NOTIFY contentSizeChanged) // Compatibility
60 Q_PROPERTY(qreal paintedHeight READ contentHeight NOTIFY contentSizeChanged)
61 Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
62 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
63 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
64 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
65 Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
66 Q_PROPERTY(QQmlComponent* cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
67 Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode NOTIFY overwriteModeChanged)
68 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
69 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
70 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
71 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
72 Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
73 Q_PROPERTY(qreal textMargin READ textMargin WRITE setTextMargin NOTIFY textMarginChanged)
74 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
75 Q_PROPERTY(bool selectByKeyboard READ selectByKeyboard WRITE setSelectByKeyboard NOTIFY selectByKeyboardChanged REVISION(2, 1))
76 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
77 Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
78 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
79 Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
80 Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
81 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
82 Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl RESET resetBaseUrl NOTIFY baseUrlChanged)
83 Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged)
84 Q_PROPERTY(QQuickTextDocument *textDocument READ textDocument CONSTANT FINAL REVISION(2, 1))
85 Q_PROPERTY(QString hoveredLink READ hoveredLink NOTIFY linkHovered REVISION(2, 2))
86 Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged REVISION(2, 6))
87 Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged REVISION(2, 6))
88 Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged REVISION(2, 6))
89 Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION(2, 6))
90 Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION(2, 6))
91 Q_PROPERTY(QString preeditText READ preeditText NOTIFY preeditTextChanged REVISION(2, 7))
92 Q_PROPERTY(qreal tabStopDistance READ tabStopDistance WRITE setTabStopDistance NOTIFY tabStopDistanceChanged REVISION(2, 10))
93 Q_PROPERTY(QQuickTextSelection* cursorSelection READ cursorSelection REVISION(6, 7) CONSTANT FINAL)
94 QML_NAMED_ELEMENT(TextEdit)
95#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
96 QML_ADDED_IN_VERSION(6, 4)
97#endif
98
99public:
100 QQuickTextEdit(QQuickItem *parent=nullptr);
101 ~QQuickTextEdit() override;
102
103 enum HAlignment {
104 AlignLeft = Qt::AlignLeft,
105 AlignRight = Qt::AlignRight,
106 AlignHCenter = Qt::AlignHCenter,
107 AlignJustify = Qt::AlignJustify
108 };
109 Q_ENUM(HAlignment)
110
111 enum VAlignment {
112 AlignTop = Qt::AlignTop,
113 AlignBottom = Qt::AlignBottom,
114 AlignVCenter = Qt::AlignVCenter
115 };
116 Q_ENUM(VAlignment)
117
118 enum TextFormat {
119 PlainText = Qt::PlainText,
120 RichText = Qt::RichText,
121 AutoText = Qt::AutoText,
122 MarkdownText = Qt::MarkdownText
123 };
124 Q_ENUM(TextFormat)
125
126 enum WrapMode { NoWrap = QTextOption::NoWrap,
127 WordWrap = QTextOption::WordWrap,
128 WrapAnywhere = QTextOption::WrapAnywhere,
129 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
130 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
131 };
132 Q_ENUM(WrapMode)
133
134 enum SelectionMode {
135 SelectCharacters,
136 SelectWords
137 };
138 Q_ENUM(SelectionMode)
139
140 enum RenderType { QtRendering,
141 NativeRendering,
142 CurveRendering
143 };
144 Q_ENUM(RenderType)
145
146 QString text() const;
147 void setText(const QString &);
148
149 Q_REVISION(2, 7) QString preeditText() const;
150
151 TextFormat textFormat() const;
152 void setTextFormat(TextFormat format);
153
154 QFont font() const;
155 void setFont(const QFont &font);
156
157 QColor color() const;
158 void setColor(const QColor &c);
159
160 QColor selectionColor() const;
161 void setSelectionColor(const QColor &c);
162
163 QColor selectedTextColor() const;
164 void setSelectedTextColor(const QColor &c);
165
166 HAlignment hAlign() const;
167 void setHAlign(HAlignment align);
168 void resetHAlign();
169 HAlignment effectiveHAlign() const;
170
171 VAlignment vAlign() const;
172 void setVAlign(VAlignment align);
173
174 WrapMode wrapMode() const;
175 void setWrapMode(WrapMode w);
176
177 int lineCount() const;
178
179 int length() const;
180
181 bool isCursorVisible() const;
182 void setCursorVisible(bool on);
183
184 int cursorPosition() const;
185 void setCursorPosition(int pos);
186
187 QQmlComponent* cursorDelegate() const;
188 void setCursorDelegate(QQmlComponent*);
189
190 bool overwriteMode() const;
191 void setOverwriteMode(bool overwrite);
192
193 int selectionStart() const;
194 int selectionEnd() const;
195
196 QString selectedText() const;
197
198 bool focusOnPress() const;
199 void setFocusOnPress(bool on);
200
201 bool persistentSelection() const;
202 void setPersistentSelection(bool on);
203
204 qreal textMargin() const;
205 void setTextMargin(qreal margin);
206
207 Qt::InputMethodHints inputMethodHints() const;
208 void setInputMethodHints(Qt::InputMethodHints hints);
209
210 bool selectByKeyboard() const;
211 void setSelectByKeyboard(bool);
212
213 bool selectByMouse() const;
214 void setSelectByMouse(bool);
215
216 SelectionMode mouseSelectionMode() const;
217 void setMouseSelectionMode(SelectionMode mode);
218
219 bool canPaste() const;
220
221 bool canUndo() const;
222 bool canRedo() const;
223
224 void componentComplete() override;
225
226 int resourcesLoading() const; // mainly for testing
227
228 /* FROM EDIT */
229 void setReadOnly(bool);
230 bool isReadOnly() const;
231
232 QRectF cursorRectangle() const;
233
234#if QT_CONFIG(im)
235 QVariant inputMethodQuery(Qt::InputMethodQuery property) const override;
236 Q_REVISION(2, 4) Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const;
237#endif
238
239 qreal contentWidth() const;
240 qreal contentHeight() const;
241
242 QUrl baseUrl() const;
243 void setBaseUrl(const QUrl &url);
244 void resetBaseUrl();
245
246 Q_INVOKABLE QRectF positionToRectangle(int) const;
247 Q_INVOKABLE int positionAt(qreal x, qreal y) const;
248 Q_INVOKABLE void moveCursorSelection(int pos);
249 Q_INVOKABLE void moveCursorSelection(int pos, QQuickTextEdit::SelectionMode mode);
250
251 QQuickTextSelection *cursorSelection() const;
252
253 QRectF boundingRect() const override;
254 QRectF clipRect() const override;
255
256 bool isInputMethodComposing() const;
257
258 RenderType renderType() const;
259 void setRenderType(RenderType renderType);
260
261 Q_INVOKABLE QString getText(int start, int end) const;
262 Q_INVOKABLE QString getFormattedText(int start, int end) const;
263
264 QQuickTextDocument *textDocument();
265
266 QString hoveredLink() const;
267
268 Q_REVISION(2, 3) Q_INVOKABLE QString linkAt(qreal x, qreal y) const;
269
270 qreal padding() const;
271 void setPadding(qreal padding);
272 void resetPadding();
273
274 qreal topPadding() const;
275 void setTopPadding(qreal padding);
276 void resetTopPadding();
277
278 qreal leftPadding() const;
279 void setLeftPadding(qreal padding);
280 void resetLeftPadding();
281
282 qreal rightPadding() const;
283 void setRightPadding(qreal padding);
284 void resetRightPadding();
285
286 qreal bottomPadding() const;
287 void setBottomPadding(qreal padding);
288 void resetBottomPadding();
289
290 int tabStopDistance() const;
291 void setTabStopDistance(qreal distance);
292
293 void invalidate() override;
294
295Q_SIGNALS:
296 void textChanged();
297 Q_REVISION(2, 7) void preeditTextChanged();
298 void contentSizeChanged();
299 void cursorPositionChanged();
300 void cursorRectangleChanged();
301 void selectionStartChanged();
302 void selectionEndChanged();
303 void selectedTextChanged();
304 void colorChanged(const QColor &color);
305 void selectionColorChanged(const QColor &color);
306 void selectedTextColorChanged(const QColor &color);
307 void fontChanged(const QFont &font);
308 void horizontalAlignmentChanged(QQuickTextEdit::HAlignment alignment);
309 void verticalAlignmentChanged(QQuickTextEdit::VAlignment alignment);
310 void wrapModeChanged();
311 void lineCountChanged();
312 void textFormatChanged(QQuickTextEdit::TextFormat textFormat);
313 void readOnlyChanged(bool isReadOnly);
314 void cursorVisibleChanged(bool isCursorVisible);
315 void cursorDelegateChanged();
316 void overwriteModeChanged(bool overwriteMode);
317 void activeFocusOnPressChanged(bool activeFocusOnPressed);
318 void persistentSelectionChanged(bool isPersistentSelection);
319 void textMarginChanged(qreal textMargin);
320 Q_REVISION(2, 1) void selectByKeyboardChanged(bool selectByKeyboard);
321 void selectByMouseChanged(bool selectByMouse);
322 void mouseSelectionModeChanged(QQuickTextEdit::SelectionMode mode);
323 void linkActivated(const QString &link);
324 Q_REVISION(2, 2) void linkHovered(const QString &link);
325 void canPasteChanged();
326 void canUndoChanged();
327 void canRedoChanged();
328 void inputMethodComposingChanged();
329 void effectiveHorizontalAlignmentChanged();
330 void baseUrlChanged();
331 void inputMethodHintsChanged();
332 void renderTypeChanged();
333 Q_REVISION(2, 6) void editingFinished();
334 Q_REVISION(2, 6) void paddingChanged();
335 Q_REVISION(2, 6) void topPaddingChanged();
336 Q_REVISION(2, 6) void leftPaddingChanged();
337 Q_REVISION(2, 6) void rightPaddingChanged();
338 Q_REVISION(2, 6) void bottomPaddingChanged();
339 Q_REVISION(2, 10) void tabStopDistanceChanged(qreal distance);
340 Q_REVISION(6, 9) void textEdited();
341
342public Q_SLOTS:
343 void selectAll();
344 void selectWord();
345 void select(int start, int end);
346 void deselect();
347 bool isRightToLeft(int start, int end);
348#if QT_CONFIG(clipboard)
349 void cut();
350 void copy();
351 void paste();
352#endif
353 void undo();
354 void redo();
355 void insert(int position, const QString &text);
356 void remove(int start, int end);
357 Q_REVISION(2, 2) void append(const QString &text);
358 Q_REVISION(2, 7) void clear();
359
360private Q_SLOTS:
361 void q_invalidate();
362 void q_textChanged();
363 void q_contentsChange(int, int, int);
364 void updateSelection();
365 void moveCursorDelegate();
366 void createCursor();
367 void q_canPasteChanged();
368 void updateWholeDocument();
369 void invalidateBlock(const QTextBlock &block);
370 void updateCursor();
371 void q_linkHovered(const QString &link);
372 void q_markerHovered(bool hovered);
373 void q_updateAlignment();
374 void updateSize();
375 void triggerPreprocess();
376 Q_REVISION(6, 7) QVariant loadResource(int type, const QUrl &source);
377 void resourceRequestFinished();
378
379private:
380 void markDirtyNodesForRange(int start, int end, int charDelta);
381 void updateTotalLines();
382 void invalidateFontCaches();
383 QTextDocument* document() const;
384 void setDocument(QTextDocument *doc);
385
386protected:
387 QQuickTextEdit(QQuickTextEditPrivate &dd, QQuickItem *parent = nullptr);
388#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
389 void setOldSelectionDefault();
390#endif
391
392 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
393 void itemChange(ItemChange change, const ItemChangeData &value) override;
394
395 bool event(QEvent *) override;
396 void keyPressEvent(QKeyEvent *) override;
397 void keyReleaseEvent(QKeyEvent *) override;
398 void focusInEvent(QFocusEvent *event) override;
399 void focusOutEvent(QFocusEvent *event) override;
400
401 void hoverEnterEvent(QHoverEvent *event) override;
402 void hoverMoveEvent(QHoverEvent *event) override;
403 void hoverLeaveEvent(QHoverEvent *event) override;
404
405 // mouse filter?
406 void mousePressEvent(QMouseEvent *event) override;
407 void mouseReleaseEvent(QMouseEvent *event) override;
408 void mouseDoubleClickEvent(QMouseEvent *event) override;
409 void mouseMoveEvent(QMouseEvent *event) override;
410#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
411 bool contextMenuEvent(QContextMenuEvent *event) override;
412#endif
413#if QT_CONFIG(im)
414 void inputMethodEvent(QInputMethodEvent *e) override;
415#endif
416 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
417 void updatePolish() override;
418
419 friend class QQuickTextUtil;
420 friend class QQuickTextDocumentPrivate;
421
422private:
423 Q_DISABLE_COPY(QQuickTextEdit)
424 Q_DECLARE_PRIVATE(QQuickTextEdit)
425};
426
427#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
428class QQuickPre64TextEdit : public QQuickTextEdit {
429 Q_OBJECT
430 QML_NAMED_ELEMENT(TextEdit)
431 QML_ADDED_IN_VERSION(2, 0)
432 QML_REMOVED_IN_VERSION(6, 4)
433public:
434 QQuickPre64TextEdit(QQuickItem *parent = nullptr);
435};
436#endif
437
438Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(int, QQuickTextEdit::HAlignment, QQuickTextEdit::VAlignment)
439
440QT_END_NAMESPACE
441
442#endif // QQUICKTEXTEDIT_P_H
For specifying a pen used for drawing rectangle borders on a QQuickView.
Q_DECLARE_INTERFACE(QNetworkAccessBackendFactory, QNetworkAccessBackendFactory_iid)
static void qt_quickitems_defineModule()
#define QQuickTextInterface_iid