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