Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include <qinputmethod.h> | - |
43 | #include <private/qinputmethod_p.h> | - |
44 | #include <qguiapplication.h> | - |
45 | #include <qtimer.h> | - |
46 | #include <qpa/qplatforminputcontext_p.h> | - |
47 | | - |
48 | QT_BEGIN_NAMESPACE | - |
49 | | - |
50 | /*! | - |
51 | \internal | - |
52 | */ | - |
53 | QInputMethod::QInputMethod() | - |
54 | : QObject(*new QInputMethodPrivate) | - |
55 | { | - |
56 | } executed: } Execution Count:289 | 289 |
57 | | - |
58 | /*! | - |
59 | \internal | - |
60 | */ | - |
61 | QInputMethod::~QInputMethod() | - |
62 | { | - |
63 | } | - |
64 | | - |
65 | /*! | - |
66 | \class QInputMethod | - |
67 | \brief The QInputMethod class provides access to the active text input method. | - |
68 | \inmodule QtGui | - |
69 | | - |
70 | QInputMethod is used by the text editors for integrating to the platform text input | - |
71 | methods and more commonly by application views for querying various text input method-related | - |
72 | information like virtual keyboard visibility and keyboard dimensions. | - |
73 | | - |
74 | Qt Quick also provides access to QInputMethod in QML through \l{QmlGlobalQtObject}{Qt global object} | - |
75 | as \c Qt.inputMethod property. | - |
76 | */ | - |
77 | | - |
78 | /*! | - |
79 | Returns the transformation from input item coordinates to the window coordinates. | - |
80 | */ | - |
81 | QTransform QInputMethod::inputItemTransform() const | - |
82 | { | - |
83 | Q_D(const QInputMethod); executed (the execution status of this line is deduced): const QInputMethodPrivate * const d = d_func(); | - |
84 | return d->inputItemTransform; executed: return d->inputItemTransform; Execution Count:2 | 2 |
85 | } | - |
86 | | - |
87 | /*! | - |
88 | Sets the transformation from input item coordinates to window coordinates to be \a transform. | - |
89 | Item transform needs to be updated by the focused window like QQuickCanvas whenever | - |
90 | item is moved inside the scene. | - |
91 | */ | - |
92 | void QInputMethod::setInputItemTransform(const QTransform &transform) | - |
93 | { | - |
94 | Q_D(QInputMethod); executed (the execution status of this line is deduced): QInputMethodPrivate * const d = d_func(); | - |
95 | if (d->inputItemTransform == transform) evaluated: d->inputItemTransform == transform yes Evaluation Count:1694 | yes Evaluation Count:634 |
| 634-1694 |
96 | return; executed: return; Execution Count:1694 | 1694 |
97 | | - |
98 | d->inputItemTransform = transform; executed (the execution status of this line is deduced): d->inputItemTransform = transform; | - |
99 | emit cursorRectangleChanged(); executed (the execution status of this line is deduced): cursorRectangleChanged(); | - |
100 | } executed: } Execution Count:634 | 634 |
101 | | - |
102 | /*! | - |
103 | \property QInputMethod::cursorRectangle | - |
104 | \brief Input item's cursor rectangle in window coordinates. | - |
105 | | - |
106 | Cursor rectangle is often used by various text editing controls | - |
107 | like text prediction popups for following the text being typed. | - |
108 | */ | - |
109 | QRectF QInputMethod::cursorRectangle() const | - |
110 | { | - |
111 | Q_D(const QInputMethod); executed (the execution status of this line is deduced): const QInputMethodPrivate * const d = d_func(); | - |
112 | | - |
113 | QObject *focusObject = qGuiApp->focusObject(); executed (the execution status of this line is deduced): QObject *focusObject = (static_cast<QGuiApplication *>(QCoreApplication::instance()))->focusObject(); | - |
114 | if (!focusObject) evaluated: !focusObject yes Evaluation Count:1 | yes Evaluation Count:2 |
| 1-2 |
115 | return QRectF(); executed: return QRectF(); Execution Count:1 | 1 |
116 | | - |
117 | QInputMethodQueryEvent query(Qt::ImCursorRectangle); executed (the execution status of this line is deduced): QInputMethodQueryEvent query(Qt::ImCursorRectangle); | - |
118 | QGuiApplication::sendEvent(focusObject, &query); executed (the execution status of this line is deduced): QGuiApplication::sendEvent(focusObject, &query); | - |
119 | QRectF r = query.value(Qt::ImCursorRectangle).toRectF(); executed (the execution status of this line is deduced): QRectF r = query.value(Qt::ImCursorRectangle).toRectF(); | - |
120 | if (!r.isValid()) partially evaluated: !r.isValid() no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
121 | return QRectF(); never executed: return QRectF(); | 0 |
122 | | - |
123 | return d->inputItemTransform.mapRect(r); executed: return d->inputItemTransform.mapRect(r); Execution Count:2 | 2 |
124 | } | - |
125 | | - |
126 | /*! | - |
127 | \property QInputMethod::keyboardRectangle | - |
128 | \brief Virtual keyboard's geometry in window coordinates. | - |
129 | */ | - |
130 | QRectF QInputMethod::keyboardRectangle() const | - |
131 | { | - |
132 | Q_D(const QInputMethod); executed (the execution status of this line is deduced): const QInputMethodPrivate * const d = d_func(); | - |
133 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
134 | if (ic) partially evaluated: ic yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
135 | return ic->keyboardRect(); executed: return ic->keyboardRect(); Execution Count:3 | 3 |
136 | return QRectF(); never executed: return QRectF(); | 0 |
137 | } | - |
138 | | - |
139 | /*! | - |
140 | Requests virtual keyboard to open. If the platform | - |
141 | doesn't provide virtual keyboard the visibility | - |
142 | remains false. | - |
143 | | - |
144 | Normally applications should not need to call this | - |
145 | function, keyboard should automatically open when | - |
146 | the text editor gains focus. | - |
147 | */ | - |
148 | void QInputMethod::show() | - |
149 | { | - |
150 | Q_D(QInputMethod); executed (the execution status of this line is deduced): QInputMethodPrivate * const d = d_func(); | - |
151 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
152 | if (ic) partially evaluated: ic yes Evaluation Count:11 | no Evaluation Count:0 |
| 0-11 |
153 | ic->showInputPanel(); executed: ic->showInputPanel(); Execution Count:11 | 11 |
154 | } executed: } Execution Count:11 | 11 |
155 | | - |
156 | /*! | - |
157 | Requests virtual keyboard to close. | - |
158 | | - |
159 | Normally applications should not need to call this function, | - |
160 | keyboard should automatically close when the text editor loses | - |
161 | focus, for example when the parent view is closed. | - |
162 | */ | - |
163 | void QInputMethod::hide() | - |
164 | { | - |
165 | Q_D(QInputMethod); executed (the execution status of this line is deduced): QInputMethodPrivate * const d = d_func(); | - |
166 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
167 | if (ic) partially evaluated: ic yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
168 | ic->hideInputPanel(); executed: ic->hideInputPanel(); Execution Count:2 | 2 |
169 | } executed: } Execution Count:2 | 2 |
170 | | - |
171 | /*! | - |
172 | \property QInputMethod::visible | - |
173 | \brief Virtual keyboard's visibility on the screen | - |
174 | | - |
175 | Input method visibility remains false for devices | - |
176 | with no virtual keyboards. | - |
177 | | - |
178 | \sa show(), hide() | - |
179 | */ | - |
180 | bool QInputMethod::isVisible() const | - |
181 | { | - |
182 | Q_D(const QInputMethod); executed (the execution status of this line is deduced): const QInputMethodPrivate * const d = d_func(); | - |
183 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
184 | if (ic) partially evaluated: ic yes Evaluation Count:5 | no Evaluation Count:0 |
| 0-5 |
185 | return ic->isInputPanelVisible(); executed: return ic->isInputPanelVisible(); Execution Count:5 | 5 |
186 | return false; never executed: return false; | 0 |
187 | } | - |
188 | | - |
189 | /*! | - |
190 | Controls the keyboard visibility. Equivalent | - |
191 | to calling show() (if \a visible is \c true) | - |
192 | or hide() (if \a visible is \c false). | - |
193 | | - |
194 | \sa show(), hide() | - |
195 | */ | - |
196 | void QInputMethod::setVisible(bool visible) | - |
197 | { | - |
198 | visible ? show() : hide(); executed (the execution status of this line is deduced): visible ? show() : hide(); | - |
199 | } executed: } Execution Count:2 | 2 |
200 | | - |
201 | /*! | - |
202 | \property QInputMethod::animating | - |
203 | \brief True when the virtual keyboard is being opened or closed. | - |
204 | | - |
205 | Animating is false when keyboard is fully open or closed. | - |
206 | When \c animating is \c true and \c visibility is \c true keyboard | - |
207 | is being opened. When \c animating is \c true and \c visibility is | - |
208 | false keyboard is being closed. | - |
209 | */ | - |
210 | | - |
211 | bool QInputMethod::isAnimating() const | - |
212 | { | - |
213 | Q_D(const QInputMethod); executed (the execution status of this line is deduced): const QInputMethodPrivate * const d = d_func(); | - |
214 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
215 | if (ic) partially evaluated: ic yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
216 | return ic->isAnimating(); executed: return ic->isAnimating(); Execution Count:3 | 3 |
217 | return false; never executed: return false; | 0 |
218 | } | - |
219 | | - |
220 | /*! | - |
221 | \property QInputMethod::locale | - |
222 | \brief Current input locale. | - |
223 | */ | - |
224 | QLocale QInputMethod::locale() const | - |
225 | { | - |
226 | Q_D(const QInputMethod); executed (the execution status of this line is deduced): const QInputMethodPrivate * const d = d_func(); | - |
227 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
228 | if (ic) partially evaluated: ic yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
229 | return ic->locale(); executed: return ic->locale(); Execution Count:1 | 1 |
230 | return QLocale::c(); never executed: return QLocale::c(); | 0 |
231 | } | - |
232 | | - |
233 | /*! | - |
234 | \property QInputMethod::inputDirection | - |
235 | \brief Current input direction. | - |
236 | */ | - |
237 | Qt::LayoutDirection QInputMethod::inputDirection() const | - |
238 | { | - |
239 | Q_D(const QInputMethod); executed (the execution status of this line is deduced): const QInputMethodPrivate * const d = d_func(); | - |
240 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
241 | if (ic) evaluated: ic yes Evaluation Count:93 | yes Evaluation Count:605 |
| 93-605 |
242 | return ic->inputDirection(); executed: return ic->inputDirection(); Execution Count:93 | 93 |
243 | return Qt::LeftToRight; executed: return Qt::LeftToRight; Execution Count:605 | 605 |
244 | } | - |
245 | | - |
246 | /*! | - |
247 | Called by the input item to inform the platform input methods when there has been | - |
248 | state changes in editor's input method query attributes. When calling the function | - |
249 | \a queries parameter has to be used to tell what has changes, which input method | - |
250 | can use to make queries for attributes it's interested with QInputMethodQueryEvent. | - |
251 | | - |
252 | In particular calling update whenever the cursor position changes is important as | - |
253 | that often causes other query attributes like surrounding text and text selection | - |
254 | to change as well. The attributes that often change together with cursor position | - |
255 | have been grouped in Qt::ImQueryInput value for convenience. | - |
256 | */ | - |
257 | void QInputMethod::update(Qt::InputMethodQueries queries) | - |
258 | { | - |
259 | Q_D(QInputMethod); executed (the execution status of this line is deduced): QInputMethodPrivate * const d = d_func(); | - |
260 | | - |
261 | if (queries & Qt::ImEnabled) { evaluated: queries & Qt::ImEnabled yes Evaluation Count:19954 | yes Evaluation Count:463 |
| 463-19954 |
262 | QObject *focus = qApp->focusObject(); executed (the execution status of this line is deduced): QObject *focus = (static_cast<QGuiApplication *>(QCoreApplication::instance()))->focusObject(); | - |
263 | bool enabled = d->objectAcceptsInputMethod(focus); executed (the execution status of this line is deduced): bool enabled = d->objectAcceptsInputMethod(focus); | - |
264 | QPlatformInputContextPrivate::setInputMethodAccepted(enabled); executed (the execution status of this line is deduced): QPlatformInputContextPrivate::setInputMethodAccepted(enabled); | - |
265 | } executed: } Execution Count:19954 | 19954 |
266 | | - |
267 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
268 | if (ic) evaluated: ic yes Evaluation Count:3501 | yes Evaluation Count:16916 |
| 3501-16916 |
269 | ic->update(queries); executed: ic->update(queries); Execution Count:3501 | 3501 |
270 | | - |
271 | if (queries & Qt::ImCursorRectangle) evaluated: queries & Qt::ImCursorRectangle yes Evaluation Count:19253 | yes Evaluation Count:1164 |
| 1164-19253 |
272 | emit cursorRectangleChanged(); executed: cursorRectangleChanged(); Execution Count:19253 | 19253 |
273 | } executed: } Execution Count:20417 | 20417 |
274 | | - |
275 | /*! | - |
276 | Resets the input method state. For example, a text editor normally calls | - |
277 | this method before inserting a text to make widget ready to accept a text. | - |
278 | | - |
279 | Input method resets automatically when the focused editor changes. | - |
280 | */ | - |
281 | void QInputMethod::reset() | - |
282 | { | - |
283 | Q_D(QInputMethod); executed (the execution status of this line is deduced): QInputMethodPrivate * const d = d_func(); | - |
284 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
285 | if (ic) evaluated: ic yes Evaluation Count:244 | yes Evaluation Count:4 |
| 4-244 |
286 | ic->reset(); executed: ic->reset(); Execution Count:244 | 244 |
287 | } executed: } Execution Count:248 | 248 |
288 | | - |
289 | /*! | - |
290 | Commits the word user is currently composing to the editor. The function is | - |
291 | mostly needed by the input methods with text prediction features and by the | - |
292 | methods where the script used for typing characters is different from the | - |
293 | script that actually gets appended to the editor. Any kind of action that | - |
294 | interrupts the text composing needs to flush the composing state by calling the | - |
295 | commit() function, for example when the cursor is moved elsewhere. | - |
296 | */ | - |
297 | void QInputMethod::commit() | - |
298 | { | - |
299 | Q_D(QInputMethod); executed (the execution status of this line is deduced): QInputMethodPrivate * const d = d_func(); | - |
300 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
301 | if (ic) evaluated: ic yes Evaluation Count:59 | yes Evaluation Count:1283 |
| 59-1283 |
302 | ic->commit(); executed: ic->commit(); Execution Count:59 | 59 |
303 | } executed: } Execution Count:1342 | 1342 |
304 | | - |
305 | /*! | - |
306 | \enum QInputMethod::Action | - |
307 | | - |
308 | Indicates the kind of action performed by the user. | - |
309 | | - |
310 | \value Click A normal click/tap | - |
311 | \value ContextMenu A context menu click/tap (e.g. right-button or tap-and-hold) | - |
312 | | - |
313 | \sa invokeAction() | - |
314 | */ | - |
315 | | - |
316 | /*! | - |
317 | Called by the input item when the word currently being composed is tapped by | - |
318 | the user, as indicated by the action \a a and the given \a cursorPosition. | - |
319 | Input methods often use this information to offer more word suggestions to the user. | - |
320 | */ | - |
321 | void QInputMethod::invokeAction(Action a, int cursorPosition) | - |
322 | { | - |
323 | Q_D(QInputMethod); executed (the execution status of this line is deduced): QInputMethodPrivate * const d = d_func(); | - |
324 | QPlatformInputContext *ic = d->platformInputContext(); executed (the execution status of this line is deduced): QPlatformInputContext *ic = d->platformInputContext(); | - |
325 | if (ic) partially evaluated: ic yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
326 | ic->invokeAction(a, cursorPosition); executed: ic->invokeAction(a, cursorPosition); Execution Count:1 | 1 |
327 | } executed: } Execution Count:1 | 1 |
328 | | - |
329 | bool QInputMethodPrivate::objectAcceptsInputMethod(QObject *object) | - |
330 | { | - |
331 | bool enabled = false; executed (the execution status of this line is deduced): bool enabled = false; | - |
332 | if (object) { evaluated: object yes Evaluation Count:4236 | yes Evaluation Count:15718 |
| 4236-15718 |
333 | QInputMethodQueryEvent query(Qt::ImEnabled); executed (the execution status of this line is deduced): QInputMethodQueryEvent query(Qt::ImEnabled); | - |
334 | QGuiApplication::sendEvent(object, &query); executed (the execution status of this line is deduced): QGuiApplication::sendEvent(object, &query); | - |
335 | enabled = query.value(Qt::ImEnabled).toBool(); executed (the execution status of this line is deduced): enabled = query.value(Qt::ImEnabled).toBool(); | - |
336 | } executed: } Execution Count:4236 | 4236 |
337 | | - |
338 | return enabled; executed: return enabled; Execution Count:19954 | 19954 |
339 | } | - |
340 | | - |
341 | QT_END_NAMESPACE | - |
342 | | - |
343 | #include "moc_qinputmethod.cpp" | - |
344 | | - |
| | |