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

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtdeclarative/src/quick/items/qquicktextinput_p.h