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
qquicktextinput_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 QQUICKTEXTINPUT_P_H
6#define QQUICKTEXTINPUT_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#include <QtGui/qtextoption.h>
22#if QT_CONFIG(validator)
23#include <QtGui/qvalidator.h>
24#endif
25
27
28class QQuickTextInputPrivate;
29class QQmlComponent;
30
31class Q_QUICK_EXPORT QQuickTextInput : public QQuickImplicitSizeItem, public QQuickTextInterface
32{
33 Q_OBJECT
34 Q_INTERFACES(QQuickTextInterface)
35
36 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
37 Q_PROPERTY(int length READ length NOTIFY textChanged)
38 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
39 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
40 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
41 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
42 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
43 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
44 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
45 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
46
47 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
48 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
49 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
50 Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
51 Q_PROPERTY(QQmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
52 Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode NOTIFY overwriteModeChanged)
53 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
54 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
55 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
56
57 Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged)
58#if QT_CONFIG(validator)
59 Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
60#endif
61 Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
62 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
63
64 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
65 Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
66 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
67 Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
68 Q_PROPERTY(int passwordMaskDelay READ passwordMaskDelay WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay NOTIFY passwordMaskDelayChanged REVISION(2, 4))
69 Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
70 Q_PROPERTY(QString preeditText READ preeditText NOTIFY preeditTextChanged REVISION(2, 7))
71 Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
72 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
73 Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
74 Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
75 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
76 Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
77 Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
78 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
79 Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged)
80 Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged)
81 Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged)
82
83 Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged REVISION(2, 6))
84 Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged REVISION(2, 6))
85 Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged REVISION(2, 6))
86 Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION(2, 6))
87 Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION(2, 6))
88 QML_NAMED_ELEMENT(TextInput)
89 QML_ADDED_IN_VERSION(2, 0)
90#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
91 QML_ADDED_IN_VERSION(6, 4)
92#endif
93
94public:
95 QQuickTextInput(QQuickItem * parent=nullptr);
96 ~QQuickTextInput();
97
98 void componentComplete() override;
99
100 enum EchoMode {//To match QLineEdit::EchoMode
101 Normal,
102 NoEcho,
103 Password,
104 PasswordEchoOnEdit
105 };
106 Q_ENUM(EchoMode)
107
108 enum HAlignment {
109 AlignLeft = Qt::AlignLeft,
110 AlignRight = Qt::AlignRight,
111 AlignHCenter = Qt::AlignHCenter
112 };
113 Q_ENUM(HAlignment)
114
115 enum VAlignment {
116 AlignTop = Qt::AlignTop,
117 AlignBottom = Qt::AlignBottom,
118 AlignVCenter = Qt::AlignVCenter
119 };
120 Q_ENUM(VAlignment)
121
122 enum WrapMode {
123 NoWrap = QTextOption::NoWrap,
124 WordWrap = QTextOption::WordWrap,
125 WrapAnywhere = QTextOption::WrapAnywhere,
126 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
127 Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
128 };
129 Q_ENUM(WrapMode)
130
131 enum SelectionMode {
132 SelectCharacters,
133 SelectWords
134 };
135 Q_ENUM(SelectionMode)
136
137 enum CursorPosition {
138 CursorBetweenCharacters,
139 CursorOnCharacter
140 };
141 Q_ENUM(CursorPosition)
142
143 enum RenderType { QtRendering,
144 NativeRendering,
145 CurveRendering
146 };
147 Q_ENUM(RenderType)
148
149 //Auxilliary functions needed to control the TextInput from QML
150 Q_INVOKABLE int positionAt(qreal x, qreal y = 0, QQuickTextInput::CursorPosition position = QQuickTextInput::CursorBetweenCharacters) const;
151 Q_INVOKABLE QRectF positionToRectangle(int pos) const;
152 Q_INVOKABLE void moveCursorSelection(int pos);
153 Q_INVOKABLE void moveCursorSelection(int pos, QQuickTextInput::SelectionMode mode);
154
155 RenderType renderType() const;
156 void setRenderType(RenderType renderType);
157
158 QString text() const;
159 void setText(const QString &);
160
161 int length() const;
162
163 QFont font() const;
164 void setFont(const QFont &font);
165
166 QColor color() const;
167 void setColor(const QColor &c);
168
169 QColor selectionColor() const;
170 void setSelectionColor(const QColor &c);
171
172 QColor selectedTextColor() const;
173 void setSelectedTextColor(const QColor &c);
174
175 HAlignment hAlign() const;
176 void setHAlign(HAlignment align);
177 void resetHAlign();
178 HAlignment effectiveHAlign() const;
179
180 VAlignment vAlign() const;
181 void setVAlign(VAlignment align);
182
183 WrapMode wrapMode() const;
184 void setWrapMode(WrapMode w);
185
186 bool isReadOnly() const;
187 void setReadOnly(bool);
188
189 bool isCursorVisible() const;
190 void setCursorVisible(bool on);
191
192 int cursorPosition() const;
193 void setCursorPosition(int cp);
194
195 QRectF cursorRectangle() const;
196
197 int selectionStart() const;
198 int selectionEnd() const;
199
200 QString selectedText() const;
201
202 int maxLength() const;
203 void setMaxLength(int ml);
204
205#if QT_CONFIG(validator)
206 QValidator * validator() const;
207 void setValidator(QValidator* v);
208#endif
209
210 QString inputMask() const;
211 void setInputMask(const QString &im);
212
213 EchoMode echoMode() const;
214 void setEchoMode(EchoMode echo);
215
216 QString passwordCharacter() const;
217 void setPasswordCharacter(const QString &str);
218
219 int passwordMaskDelay() const;
220 void setPasswordMaskDelay(int delay);
221 void resetPasswordMaskDelay();
222
223 QString displayText() const;
224 Q_REVISION(2, 7) QString preeditText() const;
225
226 QQmlComponent* cursorDelegate() const;
227 void setCursorDelegate(QQmlComponent*);
228
229 bool overwriteMode() const;
230 void setOverwriteMode(bool overwrite);
231
232 bool focusOnPress() const;
233 void setFocusOnPress(bool);
234
235 bool autoScroll() const;
236 void setAutoScroll(bool);
237
238 bool selectByMouse() const;
239 void setSelectByMouse(bool);
240
241 SelectionMode mouseSelectionMode() const;
242 void setMouseSelectionMode(SelectionMode mode);
243
244 bool persistentSelection() const;
245 void setPersistentSelection(bool persist);
246
247 bool hasAcceptableInput() const;
248
249#if QT_CONFIG(im)
250 QVariant inputMethodQuery(Qt::InputMethodQuery property) const override;
251 Q_REVISION(2, 4) Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const;
252#endif
253
254 QRectF boundingRect() const override;
255 QRectF clipRect() const override;
256
257 bool canPaste() const;
258
259 bool canUndo() const;
260 bool canRedo() const;
261
262 bool isInputMethodComposing() const;
263
264 Qt::InputMethodHints inputMethodHints() const;
265 void setInputMethodHints(Qt::InputMethodHints hints);
266
267 Q_INVOKABLE QString getText(int start, int end) const;
268
269 qreal contentWidth() const;
270 qreal contentHeight() 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 void invalidate() override;
293
294Q_SIGNALS:
295 void textChanged();
296 void cursorPositionChanged();
297 void cursorRectangleChanged();
298 void selectionStartChanged();
299 void selectionEndChanged();
300 void selectedTextChanged();
301 void accepted();
302 void acceptableInputChanged();
303 Q_REVISION(2, 2) void editingFinished();
304 Q_REVISION(2, 9) void textEdited();
305 void colorChanged();
306 void selectionColorChanged();
307 void selectedTextColorChanged();
308 void fontChanged(const QFont &font);
309 void horizontalAlignmentChanged(QQuickTextInput::HAlignment alignment);
310 void verticalAlignmentChanged(QQuickTextInput::VAlignment alignment);
311 void wrapModeChanged();
312 void readOnlyChanged(bool isReadOnly);
313 void cursorVisibleChanged(bool isCursorVisible);
314 void cursorDelegateChanged();
315 void overwriteModeChanged(bool overwriteMode);
316 void maximumLengthChanged(int maximumLength);
317#if QT_CONFIG(validator)
318 void validatorChanged();
319#endif
320 void inputMaskChanged(const QString &inputMask);
321 void echoModeChanged(QQuickTextInput::EchoMode echoMode);
322 void passwordCharacterChanged();
323 Q_REVISION(2, 4) void passwordMaskDelayChanged(int delay);
324 void displayTextChanged();
325 Q_REVISION(2, 7) void preeditTextChanged();
326 void activeFocusOnPressChanged(bool activeFocusOnPress);
327 void autoScrollChanged(bool autoScroll);
328 void selectByMouseChanged(bool selectByMouse);
329 void mouseSelectionModeChanged(QQuickTextInput::SelectionMode mode);
330 void persistentSelectionChanged();
331 void canPasteChanged();
332 void canUndoChanged();
333 void canRedoChanged();
334 void inputMethodComposingChanged();
335 void effectiveHorizontalAlignmentChanged();
336 void contentSizeChanged();
337 void inputMethodHintsChanged();
338 void renderTypeChanged();
339 Q_REVISION(2, 6) void paddingChanged();
340 Q_REVISION(2, 6) void topPaddingChanged();
341 Q_REVISION(2, 6) void leftPaddingChanged();
342 Q_REVISION(2, 6) void rightPaddingChanged();
343 Q_REVISION(2, 6) void bottomPaddingChanged();
344
345private:
346 void invalidateFontCaches();
347 void ensureActiveFocus(Qt::FocusReason reason);
348
349protected:
350 QQuickTextInput(QQuickTextInputPrivate &dd, QQuickItem *parent = nullptr);
351#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
352 void setOldSelectionDefault();
353#endif
354
355 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
356 void itemChange(ItemChange change, const ItemChangeData &value) override;
357
358 void mousePressEvent(QMouseEvent *event) override;
359 void mouseMoveEvent(QMouseEvent *event) override;
360 void mouseReleaseEvent(QMouseEvent *event) override;
361 void mouseDoubleClickEvent(QMouseEvent *event) override;
362 void keyPressEvent(QKeyEvent* ev) override;
363#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
364 bool contextMenuEvent(QContextMenuEvent *event) override;
365#endif
366#if QT_CONFIG(im)
367 void inputMethodEvent(QInputMethodEvent *) override;
368#endif
369 void mouseUngrabEvent() override;
370 bool event(QEvent *e) override;
371 void focusOutEvent(QFocusEvent *event) override;
372 void focusInEvent(QFocusEvent *event) override;
373 void timerEvent(QTimerEvent *event) override;
374 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) override;
375 void updatePolish() override;
376
377public Q_SLOTS:
378 void selectAll();
379 void selectWord();
380 void select(int start, int end);
381 void deselect();
382 bool isRightToLeft(int start, int end);
383#if QT_CONFIG(clipboard)
384 void cut();
385 void copy();
386 void paste();
387#endif
388 void undo();
389 void redo();
390 void insert(int position, const QString &text);
391 void remove(int start, int end);
392 Q_REVISION(2, 4) void ensureVisible(int position);
393 Q_REVISION(2, 7) void clear();
394
395private Q_SLOTS:
396 void selectionChanged();
397 void createCursor();
398 void updateCursorRectangle(bool scroll = true);
399 void q_canPasteChanged();
400 void q_updateAlignment();
401 void triggerPreprocess();
402
403#if QT_CONFIG(validator)
404 void q_validatorChanged();
405#endif
406
407private:
408 friend class QQuickTextUtil;
409
410 Q_DECLARE_PRIVATE(QQuickTextInput)
411};
412
413#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
414class QQuickPre64TextInput : public QQuickTextInput {
415 Q_OBJECT
416 QML_NAMED_ELEMENT(TextInput)
417 QML_ADDED_IN_VERSION(2, 0)
418 QML_REMOVED_IN_VERSION(6, 4)
419public:
420 QQuickPre64TextInput(QQuickItem *parent = nullptr);
421};
422#endif
423
424QT_END_NAMESPACE
425
426#endif // QQUICKTEXTINPUT_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