Qt 6.x
The Qt SDK
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
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
20#include <QtGui/qtextoption.h>
21#if QT_CONFIG(validator)
22#include <QtGui/qvalidator.h>
23#endif
24
26
28class Q_QUICK_PRIVATE_EXPORT QQuickTextInput : public QQuickImplicitSizeItem, public QQuickTextInterface
29{
32
33 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)
34 Q_PROPERTY(int length READ length NOTIFY textChanged FINAL)
35 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
36 Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged FINAL)
37 Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged FINAL)
38 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
39 Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged FINAL)
40 Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged FINAL)
41 Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged FINAL)
42 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged FINAL)
43
44 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged FINAL)
45 Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged FINAL)
46 Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged FINAL)
47 Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged FINAL)
48 Q_PROPERTY(QQmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged FINAL)
49 Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode NOTIFY overwriteModeChanged FINAL)
50 Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged FINAL)
51 Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged FINAL)
52 Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged FINAL)
53
54 Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged FINAL)
55#if QT_CONFIG(validator)
56 Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL)
57#endif
58 Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged FINAL)
59 Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL)
60
61 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged FINAL)
62 Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged FINAL)
63 Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged FINAL)
64 Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged FINAL)
65 Q_PROPERTY(int passwordMaskDelay READ passwordMaskDelay WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay NOTIFY passwordMaskDelayChanged REVISION(2, 4) FINAL)
66 Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged FINAL)
67 Q_PROPERTY(QString preeditText READ preeditText NOTIFY preeditTextChanged REVISION(2, 7) FINAL)
68 Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged FINAL)
69 Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged FINAL)
70 Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged FINAL)
71 Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged FINAL)
72 Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged FINAL)
73 Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged FINAL)
74 Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged FINAL)
75 Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL)
76 Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged FINAL)
77 Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged FINAL)
78 Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged FINAL)
79
80 Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged REVISION(2, 6) FINAL)
81 Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged REVISION(2, 6) FINAL)
82 Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged REVISION(2, 6) FINAL)
83 Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION(2, 6) FINAL)
84 Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION(2, 6) FINAL)
85 QML_NAMED_ELEMENT(TextInput)
87#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
89#endif
90
91public:
94
95 void componentComplete() override;
96
97 enum EchoMode {//To match QLineEdit::EchoMode
101 PasswordEchoOnEdit
102 };
103 Q_ENUM(EchoMode)
104
106 AlignLeft = Qt::AlignLeft,
107 AlignRight = Qt::AlignRight,
108 AlignHCenter = Qt::AlignHCenter
109 };
110 Q_ENUM(HAlignment)
111
113 AlignTop = Qt::AlignTop,
114 AlignBottom = Qt::AlignBottom,
115 AlignVCenter = Qt::AlignVCenter
116 };
117 Q_ENUM(VAlignment)
118
119 enum WrapMode {
123 WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
125 };
126 Q_ENUM(WrapMode)
127
130 SelectWords
131 };
132 Q_ENUM(SelectionMode)
133
136 CursorOnCharacter
137 };
138 Q_ENUM(CursorPosition)
139
141 NativeRendering
142 };
143 Q_ENUM(RenderType)
144
145 //Auxilliary functions needed to control the TextInput from QML
147 Q_INVOKABLE QRectF positionToRectangle(int pos) const;
148 Q_INVOKABLE void moveCursorSelection(int pos);
149 Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
150
151 RenderType renderType() const;
152 void setRenderType(RenderType renderType);
153
154 QString text() const;
155 void setText(const QString &);
156
157 int length() const;
158
159 QFont font() const;
160 void setFont(const QFont &font);
161
162 QColor color() const;
163 void setColor(const QColor &c);
164
165 QColor selectionColor() const;
166 void setSelectionColor(const QColor &c);
167
168 QColor selectedTextColor() const;
169 void setSelectedTextColor(const QColor &c);
170
171 HAlignment hAlign() const;
172 void setHAlign(HAlignment align);
173 void resetHAlign();
174 HAlignment effectiveHAlign() const;
175
176 VAlignment vAlign() const;
177 void setVAlign(VAlignment align);
178
179 WrapMode wrapMode() const;
180 void setWrapMode(WrapMode w);
181
182 bool isReadOnly() const;
183 void setReadOnly(bool);
184
185 bool isCursorVisible() const;
186 void setCursorVisible(bool on);
187
188 int cursorPosition() const;
189 void setCursorPosition(int cp);
190
191 QRectF cursorRectangle() const;
192
193 int selectionStart() const;
194 int selectionEnd() const;
195
196 QString selectedText() const;
197
198 int maxLength() const;
199 void setMaxLength(int ml);
200
201#if QT_CONFIG(validator)
202 QValidator * validator() const;
203 void setValidator(QValidator* v);
204#endif
205
206 QString inputMask() const;
207 void setInputMask(const QString &im);
208
209 EchoMode echoMode() const;
210 void setEchoMode(EchoMode echo);
211
212 QString passwordCharacter() const;
213 void setPasswordCharacter(const QString &str);
214
215 int passwordMaskDelay() const;
216 void setPasswordMaskDelay(int delay);
217 void resetPasswordMaskDelay();
218
219 QString displayText() const;
220 Q_REVISION(2, 7) QString preeditText() const;
221
222 QQmlComponent* cursorDelegate() const;
223 void setCursorDelegate(QQmlComponent*);
224
225 bool overwriteMode() const;
226 void setOverwriteMode(bool overwrite);
227
228 bool focusOnPress() const;
229 void setFocusOnPress(bool);
230
231 bool autoScroll() const;
232 void setAutoScroll(bool);
233
234 bool selectByMouse() const;
235 void setSelectByMouse(bool);
236
237 SelectionMode mouseSelectionMode() const;
238 void setMouseSelectionMode(SelectionMode mode);
239
240 bool persistentSelection() const;
241 void setPersistentSelection(bool persist);
242
243 bool hasAcceptableInput() const;
244
245#if QT_CONFIG(im)
246 QVariant inputMethodQuery(Qt::InputMethodQuery property) const override;
247 Q_REVISION(2, 4) Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const;
248#endif
249
250 QRectF boundingRect() const override;
251 QRectF clipRect() const override;
252
253 bool canPaste() const;
254
255 bool canUndo() const;
256 bool canRedo() const;
257
258 bool isInputMethodComposing() const;
259
260 Qt::InputMethodHints inputMethodHints() const;
261 void setInputMethodHints(Qt::InputMethodHints hints);
262
263 Q_INVOKABLE QString getText(int start, int end) const;
264
265 qreal contentWidth() const;
266 qreal contentHeight() const;
267
268 qreal padding() const;
269 void setPadding(qreal padding);
270 void resetPadding();
271
272 qreal topPadding() const;
273 void setTopPadding(qreal padding);
274 void resetTopPadding();
275
276 qreal leftPadding() const;
277 void setLeftPadding(qreal padding);
278 void resetLeftPadding();
279
280 qreal rightPadding() const;
281 void setRightPadding(qreal padding);
282 void resetRightPadding();
283
284 qreal bottomPadding() const;
285 void setBottomPadding(qreal padding);
286 void resetBottomPadding();
287
288 void invalidate() override;
289
297 void accepted();
299 Q_REVISION(2, 2) void editingFinished();
300 Q_REVISION(2, 9) void textEdited();
302 void selectionColorChanged();
303 void selectedTextColorChanged();
304 void fontChanged(const QFont &font);
305 void horizontalAlignmentChanged(QQuickTextInput::HAlignment alignment);
306 void verticalAlignmentChanged(QQuickTextInput::VAlignment alignment);
307 void wrapModeChanged();
308 void readOnlyChanged(bool isReadOnly);
309 void cursorVisibleChanged(bool isCursorVisible);
310 void cursorDelegateChanged();
311 void overwriteModeChanged(bool overwriteMode);
312 void maximumLengthChanged(int maximumLength);
313#if QT_CONFIG(validator)
314 void validatorChanged();
315#endif
316 void inputMaskChanged(const QString &inputMask);
319 Q_REVISION(2, 4) void passwordMaskDelayChanged(int delay);
320 void displayTextChanged();
321 Q_REVISION(2, 7) void preeditTextChanged();
322 void activeFocusOnPressChanged(bool activeFocusOnPress);
323 void autoScrollChanged(bool autoScroll);
324 void selectByMouseChanged(bool selectByMouse);
325 void mouseSelectionModeChanged(QQuickTextInput::SelectionMode mode);
326 void persistentSelectionChanged();
327 void canPasteChanged();
328 void canUndoChanged();
329 void canRedoChanged();
330 void inputMethodComposingChanged();
331 void effectiveHorizontalAlignmentChanged();
332 void contentSizeChanged();
333 void inputMethodHintsChanged();
334 void renderTypeChanged();
335 Q_REVISION(2, 6) void paddingChanged();
336 Q_REVISION(2, 6) void topPaddingChanged();
337 Q_REVISION(2, 6) void leftPaddingChanged();
338 Q_REVISION(2, 6) void rightPaddingChanged();
339 Q_REVISION(2, 6) void bottomPaddingChanged();
340
341private:
342 void invalidateFontCaches();
343 void ensureActiveFocus(Qt::FocusReason reason);
344
345protected:
347#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
348 void setOldSelectionDefault();
349#endif
350
351 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
352
353 void mousePressEvent(QMouseEvent *event) override;
354 void mouseMoveEvent(QMouseEvent *event) override;
355 void mouseReleaseEvent(QMouseEvent *event) override;
357 void keyPressEvent(QKeyEvent* ev) override;
358#if QT_CONFIG(im)
359 void inputMethodEvent(QInputMethodEvent *) override;
360#endif
361 void mouseUngrabEvent() override;
362 bool event(QEvent *e) override;
363 void focusOutEvent(QFocusEvent *event) override;
364 void focusInEvent(QFocusEvent *event) override;
365 void timerEvent(QTimerEvent *event) override;
367 void updatePolish() override;
368
369public Q_SLOTS:
370 void selectAll();
371 void selectWord();
372 void select(int start, int end);
373 void deselect();
374 bool isRightToLeft(int start, int end);
375#if QT_CONFIG(clipboard)
376 void cut();
377 void copy();
378 void paste();
379#endif
380 void undo();
381 void redo();
382 void insert(int position, const QString &text);
383 void remove(int start, int end);
384 Q_REVISION(2, 4) void ensureVisible(int position);
385 Q_REVISION(2, 7) void clear();
386
388 void selectionChanged();
389 void createCursor();
390 void updateCursorRectangle(bool scroll = true);
391 void q_canPasteChanged();
392 void q_updateAlignment();
393 void triggerPreprocess();
394
395#if QT_CONFIG(validator)
396 void q_validatorChanged();
397#endif
398
399private:
400 friend class QQuickTextUtil;
401
402 Q_DECLARE_PRIVATE(QQuickTextInput)
403};
404
405#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
406class QQuickPre64TextInput : public QQuickTextInput {
408 QML_NAMED_ELEMENT(TextInput)
411public:
412 QQuickPre64TextInput(QQuickItem *parent = nullptr);
413};
414#endif
415
417
419
420#endif // QQUICKTEXTINPUT_P_H
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore
Definition qcoreevent.h:45
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
\reentrant
Definition qfont.h:20
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:624
The QKeyEvent class describes a key event.
Definition qevent.h:423
\inmodule QtGui
Definition qevent.h:195
virtual void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object.
Definition qobject.cpp:1433
The QQmlComponent class encapsulates a QML component definition.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive focus-out events for an item.
virtual void mouseReleaseEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse release events for an item.
virtual QSGNode * updatePaintNode(QSGNode *, UpdatePaintNodeData *)
Called on the render thread when it is time to sync the state of the item with the scene graph.
virtual void mouseDoubleClickEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse double-click events for an ite...
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
virtual void mouseUngrabEvent()
This event handler can be reimplemented in a subclass to be notified when a mouse ungrab event has oc...
virtual void keyPressEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key press events for an item.
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
virtual QRectF boundingRect() const
Returns the extents of the item in its own coordinate system: a rectangle from {0,...
virtual void mousePressEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse press events for an item.
Q_REVISION(2, 1) void activeFocusOnTabChanged(bool)
virtual void updatePolish()
This function should perform any layout as required for this item.
virtual QRectF clipRect() const
Returns the rectangular area within this item that is currently visible in \l viewportItem(),...
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive focus-in events for an item.
virtual void mouseMoveEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse move events for an item.
void cursorPositionChanged()
Q_REVISION(2, 4) void passwordMaskDelayChanged(int delay)
void passwordCharacterChanged()
Q_REVISION(2, 7) QString preeditText() const
void selectedTextChanged()
void echoModeChanged(QQuickTextInput::EchoMode echoMode)
void cursorRectangleChanged()
Q_REVISION(2, 2) void editingFinished()
Q_REVISION(2, 4) void ensureVisible(int position)
void acceptableInputChanged()
void inputMaskChanged(const QString &inputMask)
void selectionEndChanged()
void selectionStartChanged()
virtual void invalidate()=0
\inmodule QtCore\reentrant
Definition qrect.h:483
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
@ WrapAtWordBoundaryOrAnywhere
Definition qtextoption.h:65
\inmodule QtCore
Definition qcoreevent.h:359
The QValidator class provides validation of input text.
Definition qvalidator.h:24
\inmodule QtCore
Definition qvariant.h:64
QString str
[2]
b clear()
QString text
void colorChanged()
void textChanged(const QString &newText)
double e
cache insert(employee->id(), employee)
uint alignment
Combined button and popup list for selecting options.
InputMethodQuery
@ AlignRight
Definition qnamespace.h:145
@ AlignBottom
Definition qnamespace.h:153
@ AlignVCenter
Definition qnamespace.h:154
@ AlignTop
Definition qnamespace.h:152
@ AlignHCenter
Definition qnamespace.h:147
@ AlignLeft
Definition qnamespace.h:143
static jboolean cut(JNIEnv *, jobject)
static jboolean copy(JNIEnv *, jobject)
static jboolean paste(JNIEnv *, jobject)
static jboolean selectAll(JNIEnv *, jobject)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
GLsizei const GLfloat * v
[13]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLuint GLuint end
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint start
struct _cl_event * event
GLenum query
const GLubyte * c
GLsizei maxLength
#define QML_DECLARE_TYPE(TYPE)
Definition qqml.h:19
#define QML_NAMED_ELEMENT(NAME)
#define QML_REMOVED_IN_VERSION(MAJOR, MINOR)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static qreal positionAt(const QQuickRangeSlider *slider, QQuickItem *handle, const QPointF &point)
static void getText(QString &text, QTextDocumentPrivate *priv, const QString &docText, int pos, int end)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_REVISION(...)
#define Q_INVOKABLE
#define Q_INTERFACES(x)
#define Q_SLOTS
#define Q_SIGNALS
double qreal
Definition qtypes.h:92
const char property[13]
Definition qwizard.cpp:101
settings remove("monkey")
myFilter setColor(QColor(128, 0, 0))
selection select(topLeft, bottomRight)
insertRed setText("insert red text")
stack undo()
QDBusArgument argument
QJSValueList args
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent