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
qquickinputmethod.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 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
6
7#include <QtGui/qguiapplication.h>
8
10
11/*!
12 \qmlsingletontype InputMethod
13 \inqmlmodule QtQuick
14
15 \brief Provides access to \l QInputMethod for QML applications.
16
17 The InputMethod singleton allows access to application's \l QInputMethod object
18 and all its properties and slots. See the \l QInputMethod documentation for
19 further details.
20
21 \since 6.4
22*/
23
24/*!
25 \qmlproperty rect InputMethod::cursorRectangle
26
27 \brief Input item's cursor rectangle in window coordinates.
28
29 The cursor rectangle is often used by various text editing controls
30 like text prediction popups for following the text being typed.
31*/
32
33/*!
34 \qmlproperty rect InputMethod::anchorRectangle
35
36 \brief Input item's anchor rectangle in window coordinates.
37
38 The anchor rectangle is often used by various text editing controls
39 like text prediction popups for following the text selection.
40*/
41
42/*!
43 \qmlproperty rect InputMethod::keyboardRectangle
44 \brief Virtual keyboard's geometry in window coordinates.
45
46 This might be an empty rectangle if it is not possible to know the geometry
47 of the keyboard. This is the case for a floating keyboard on android.
48*/
49
50/*!
51 \qmlproperty rect InputMethod::inputItemClipRectangle
52 \brief Input item's clipped rectangle in window coordinates.
53
54 The clipped input rectangle is often used by various input methods to determine
55 how much screen real estate is available for the input method (e.g. Virtual Keyboard).
56*/
57
58/*!
59 \qmlproperty bool InputMethod::visible
60 \brief Virtual keyboard's visibility on the screen
61
62 The value of this property remains false for devices
63 with no virtual keyboards.
64
65 \sa show(), hide()
66*/
67
68/*!
69 \qmlproperty bool InputMethod::animating
70 \brief True when the virtual keyboard is being opened or closed.
71
72 The value of this property is false when keyboard is fully open or closed.
73 When \c animating is \c true and \c visibility is \c true keyboard
74 is being opened. When \c animating is \c true and \c visibility is
75 false keyboard is being closed.
76*/
77
78/*!
79 \qmlproperty Locale InputMethod::locale
80 \brief Current input locale.
81*/
82
83/*!
84 \qmlproperty enumeration InputMethod::inputDirection
85 \brief Current input direction.
86
87 Possible values:
88
89 \value Qt.LeftToRight (default) Items are laid out from left to right.
90 \value Qt.RightToLeft Items are laid out from right to left.
91 */
92
93/*!
94 \qmlmethod void InputMethod::commit()
95
96 Commits the word that the user is currently composing to the editor. The function is
97 mostly needed by the input methods with text prediction features and by the
98 methods where the script used for typing characters is different from the
99 script that actually gets appended to the editor. Any kind of action that
100 interrupts the text composing needs to flush the composing state by calling the
101 commit() function, for example when the cursor is moved elsewhere.
102*/
103
104/*!
105 \qmlmethod void InputMethod::hide()
106
107 Requests the virtual keyboard to close.
108
109 Normally applications should not need to call this function,
110 as the keyboard should close automatically when the text editor loses
111 focus, for example when the parent view is closed.
112*/
113
114/*!
115 \qmlmethod void InputMethod::invokeAction(var a, int cursorPosition)
116
117 Called by the input item when the word currently being composed is tapped by
118 the user, as indicated by the action \a a and the given \a cursorPosition.
119 Input methods often use this information to offer more word suggestions to the user.
120
121 \sa QInputMethod::Action
122*/
123
124/*!
125 \qmlmethod void InputMethod::reset()
126
127 Resets the input method state. For example, a text editor normally calls
128 this method before inserting a text to make widget ready to accept a text.
129
130 Input method resets automatically when the focused editor changes.
131*/
132
133/*!
134 \qmlmethod void InputMethod::show()
135
136 Requests the virtual keyboard to open. If the platform
137 doesn't provide a virtual keyboard the visibility
138 remains false.
139
140 Normally applications should not need to call this
141 function, as the keyboard should open automatically when
142 the text editor gains focus.
143*/
144
145/*!
146 \qmlmethod void InputMethod::update(enumeration queries)
147
148 Called by the input item to inform the platform input methods when there have been
149 state changes in the editor's input method query attributes. When calling the function
150 \a queries parameter has to be used to tell what has changed. An input method
151 can use this to make queries for attributes it is interested in with QInputMethodQueryEvent.
152
153 In particular calling update() whenever the cursor position changes is important as
154 that often causes other query attributes, like surrounding text and text selection,
155 to change as well. The attributes that often change together with cursor position
156 have been grouped in Qt::ImQueryInput value for convenience.
157
158 \sa Qt::InputMethodQueries
159*/
160
161QQuickInputMethod::QQuickInputMethod(QObject *parent) : QObject(parent)
162{
163 QInputMethod *inputMethod = QGuiApplication::inputMethod();
164 connect(inputMethod, &QInputMethod::anchorRectangleChanged, this,
165 &QQuickInputMethod::anchorRectangleChanged);
166 connect(inputMethod, &QInputMethod::animatingChanged, this,
167 &QQuickInputMethod::animatingChanged);
168 connect(inputMethod, &QInputMethod::cursorRectangleChanged, this,
169 &QQuickInputMethod::cursorRectangleChanged);
170 connect(inputMethod, &QInputMethod::inputDirectionChanged, this,
171 &QQuickInputMethod::inputDirectionChanged);
172 connect(inputMethod, &QInputMethod::inputItemClipRectangleChanged, this,
173 &QQuickInputMethod::inputItemClipRectangleChanged);
174 connect(inputMethod, &QInputMethod::keyboardRectangleChanged, this,
175 &QQuickInputMethod::keyboardRectangleChanged);
176 connect(inputMethod, &QInputMethod::localeChanged, this, &QQuickInputMethod::localeChanged);
177 connect(inputMethod, &QInputMethod::visibleChanged, this, &QQuickInputMethod::visibleChanged);
178}
179
180void QQuickInputMethod::commit()
181{
182 QGuiApplication::inputMethod()->commit();
183}
184void QQuickInputMethod::hide()
185{
186 QGuiApplication::inputMethod()->hide();
187}
188void QQuickInputMethod::invokeAction(QInputMethod::Action a, int cursorPosition)
189{
190 QGuiApplication::inputMethod()->invokeAction(a, cursorPosition);
191}
192void QQuickInputMethod::reset()
193{
194 QGuiApplication::inputMethod()->reset();
195}
196void QQuickInputMethod::show()
197{
198 QGuiApplication::inputMethod()->show();
199}
200void QQuickInputMethod::update(Qt::InputMethodQueries queries)
201{
202 QGuiApplication::inputMethod()->update(queries);
203}
204
205QRectF QQuickInputMethod::anchorRectangle() const
206{
207 return QGuiApplication::inputMethod()->cursorRectangle();
208}
209QRectF QQuickInputMethod::cursorRectangle() const
210{
211 return QGuiApplication::inputMethod()->cursorRectangle();
212}
213Qt::LayoutDirection QQuickInputMethod::inputDirection() const
214{
215 return QGuiApplication::inputMethod()->inputDirection();
216}
217QRectF QQuickInputMethod::inputItemClipRectangle() const
218{
219 return QGuiApplication::inputMethod()->inputItemClipRectangle();
220}
221
222QRectF QQuickInputMethod::inputItemRectangle() const
223{
224 return QGuiApplication::inputMethod()->inputItemRectangle();
225}
226void QQuickInputMethod::setInputItemRectangle(const QRectF &rect)
227{
228 QGuiApplication::inputMethod()->setInputItemRectangle(rect);
229}
230
231QTransform QQuickInputMethod::inputItemTransform() const
232{
233 return QGuiApplication::inputMethod()->inputItemTransform();
234}
235void QQuickInputMethod::setInputItemTransform(const QTransform &transform)
236{
237 QGuiApplication::inputMethod()->setInputItemTransform(transform);
238}
239
240bool QQuickInputMethod::isAnimating() const
241{
242 return QGuiApplication::inputMethod()->isAnimating();
243}
244
245bool QQuickInputMethod::isVisible() const
246{
247 return QGuiApplication::inputMethod()->isVisible();
248}
249void QQuickInputMethod::setVisible(bool visible)
250{
251 QGuiApplication::inputMethod()->setVisible(visible);
252}
253
254QRectF QQuickInputMethod::keyboardRectangle() const
255{
256 return QGuiApplication::inputMethod()->keyboardRectangle();
257}
258QLocale QQuickInputMethod::locale() const
259{
260 return QGuiApplication::inputMethod()->locale();
261}
262
263QT_END_NAMESPACE
264
265#include "moc_qquickinputmethod_p.cpp"
Combined button and popup list for selecting options.