1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <QtVirtualKeyboard/qvirtualkeyboardabstractinputmethod.h>
5#include <QtVirtualKeyboard/private/qvirtualkeyboardabstractinputmethod_p.h>
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \class QVirtualKeyboardAbstractInputMethod
11
12 \inmodule QtVirtualKeyboard
13 \ingroup qtvirtualkeyboard-cpp-for-devs
14
15 \brief The base class for input methods.
16
17 Use this class if you want to implement a custom input
18 method using C/C++ language.
19*/
20
21QVirtualKeyboardAbstractInputMethod::QVirtualKeyboardAbstractInputMethod(QVirtualKeyboardAbstractInputMethodPrivate &dd, QObject *parent) :
22 QObject(dd, parent)
23{
24}
25
26/*!
27 Constructs an input method with \a parent.
28*/
29
30QVirtualKeyboardAbstractInputMethod::QVirtualKeyboardAbstractInputMethod(QObject *parent) :
31 QObject(*new QVirtualKeyboardAbstractInputMethodPrivate(), parent)
32{
33}
34
35/*!
36 Destroys the input method and frees all allocated resources.
37*/
38QVirtualKeyboardAbstractInputMethod::~QVirtualKeyboardAbstractInputMethod()
39{
40}
41
42/*!
43 Returns the input context associated with the input method.
44 This method returns \c NULL if the input method is not active.
45*/
46QVirtualKeyboardInputContext *QVirtualKeyboardAbstractInputMethod::inputContext() const
47{
48 Q_D(const QVirtualKeyboardAbstractInputMethod);
49 return d->inputEngine ? d->inputEngine->inputContext() : nullptr;
50}
51
52/*!
53 Returns the input engine associated with the input method.
54 This method returns \c NULL if the input method is not active.
55*/
56QVirtualKeyboardInputEngine *QVirtualKeyboardAbstractInputMethod::inputEngine() const
57{
58 Q_D(const QVirtualKeyboardAbstractInputMethod);
59 return d->inputEngine;
60}
61
62/*!
63 This method is called by the input engine when the input method needs
64 to be reset. The input method must reset its internal state only. The main
65 difference to the update() method is that reset() modifies only
66 the input method state, i.e. it must not modify the input context.
67*/
68void QVirtualKeyboardAbstractInputMethod::reset()
69{
70}
71
72/*!
73 This method is called by the input engine when the input method needs to be
74 updated. The input method must close the current pre-edit text and
75 restore its internal state to the default.
76*/
77void QVirtualKeyboardAbstractInputMethod::update()
78{
79}
80
81/*!
82 Clears input mode.
83
84 This method is called by the virtual keyboard when this input method is being replaced
85 by another input method. It should clear the operations performed by setInputMode() method,
86 for example, to disconnect signal handlers from the virtual keyboard or free up resources.
87
88 The input mode may be reactivated by calling setInputMode(). However, note that the calls to
89 setInputMethod() and clearInputMethod() are not in balance. Thus, for example, setInputMethod()
90 may be called multiple times without matching calls to clearInputMethod().
91
92 The default implementation does nothing.
93
94 \since QtQuick.VirtualKeyboard 6.1
95*/
96void QVirtualKeyboardAbstractInputMethod::clearInputMode()
97{
98}
99
100/*!
101 \internal
102 Called by the input engine when the input method is activated and
103 deactivated.
104*/
105void QVirtualKeyboardAbstractInputMethod::setInputEngine(QVirtualKeyboardInputEngine *inputEngine)
106{
107 Q_D(QVirtualKeyboardAbstractInputMethod);
108 if (d->inputEngine) {
109 d->inputEngine->disconnect(receiver: this, SLOT(reset()));
110 d->inputEngine->disconnect(receiver: this, SLOT(update()));
111 }
112 d->inputEngine = inputEngine;
113 if (d->inputEngine) {
114 connect(asender: d->inputEngine, SIGNAL(inputMethodReset()), SLOT(reset()));
115 connect(asender: d->inputEngine, SIGNAL(inputMethodUpdate()), SLOT(update()));
116 }
117}
118
119QList<QVirtualKeyboardSelectionListModel::Type> QVirtualKeyboardAbstractInputMethod::selectionLists()
120{
121 return QList<QVirtualKeyboardSelectionListModel::Type>();
122}
123
124int QVirtualKeyboardAbstractInputMethod::selectionListItemCount(QVirtualKeyboardSelectionListModel::Type type)
125{
126 Q_UNUSED(type);
127 return 0;
128}
129
130QVariant QVirtualKeyboardAbstractInputMethod::selectionListData(QVirtualKeyboardSelectionListModel::Type type, int index, QVirtualKeyboardSelectionListModel::Role role)
131{
132 Q_UNUSED(type);
133 Q_UNUSED(index);
134 switch (role) {
135 case QVirtualKeyboardSelectionListModel::Role::Display:
136 return QVariant(QString());
137 case QVirtualKeyboardSelectionListModel::Role::WordCompletionLength:
138 return QVariant(0);
139 case QVirtualKeyboardSelectionListModel::Role::Dictionary:
140 return QVariant(static_cast<int>(QVirtualKeyboardSelectionListModel::DictionaryType::Default));
141 case QVirtualKeyboardSelectionListModel::Role::CanRemoveSuggestion:
142 return QVariant(false);
143 }
144 return QVariant();
145}
146
147void QVirtualKeyboardAbstractInputMethod::selectionListItemSelected(QVirtualKeyboardSelectionListModel::Type type, int index)
148{
149 Q_UNUSED(type);
150 Q_UNUSED(index);
151}
152
153bool QVirtualKeyboardAbstractInputMethod::selectionListRemoveItem(QVirtualKeyboardSelectionListModel::Type type, int index)
154{
155 Q_UNUSED(type);
156 Q_UNUSED(index);
157 return false;
158}
159
160/*!
161 \since QtQuick.VirtualKeyboard 2.0
162
163 Returns list of supported pattern recognition modes.
164
165 This method is called by the input engine to query the list of
166 supported pattern recognition modes.
167*/
168QList<QVirtualKeyboardInputEngine::PatternRecognitionMode> QVirtualKeyboardAbstractInputMethod::patternRecognitionModes() const
169{
170 return QList<QVirtualKeyboardInputEngine::PatternRecognitionMode>();
171}
172
173/*!
174 \since QtQuick.VirtualKeyboard 2.0
175
176 This method is called when a trace interaction starts with the specified \a patternRecognitionMode.
177 The trace is uniquely identified by the \a traceId.
178 The \a traceCaptureDeviceInfo provides information about the source device and the
179 \a traceScreenInfo provides information about the screen context.
180
181 If the input method accepts the event and wants to capture the trace input, it must return
182 a new QVirtualKeyboardTrace object. This object must remain valid until the traceEnd() method is called. If the
183 QVirtualKeyboardTrace is rendered on screen, it remains there until the QVirtualKeyboardTrace object is destroyed.
184*/
185QVirtualKeyboardTrace *QVirtualKeyboardAbstractInputMethod::traceBegin(
186 int traceId, QVirtualKeyboardInputEngine::PatternRecognitionMode patternRecognitionMode,
187 const QVariantMap &traceCaptureDeviceInfo, const QVariantMap &traceScreenInfo)
188{
189 Q_UNUSED(traceId);
190 Q_UNUSED(patternRecognitionMode);
191 Q_UNUSED(traceCaptureDeviceInfo);
192 Q_UNUSED(traceScreenInfo);
193 return nullptr;
194}
195
196/*!
197 \since QtQuick.VirtualKeyboard 2.0
198
199 This method is called when the trace interaction ends. The input method should destroy the \a trace object
200 at some point after this function is called. See the \l {Trace API for Input Methods} how to access the gathered
201 data.
202
203 The method returns \c true if the trace interaction is accepted.
204*/
205bool QVirtualKeyboardAbstractInputMethod::traceEnd(QVirtualKeyboardTrace *trace)
206{
207 Q_UNUSED(trace);
208 return false;
209}
210
211/*!
212 \since QtQuick.VirtualKeyboard 2.0
213
214 This function attempts to reselect a word located at the \a cursorPosition.
215 The \a reselectFlags define the rules for how the word should be selected in
216 relation to the cursor position.
217
218 The function returns \c true if the word was successfully reselected.
219*/
220bool QVirtualKeyboardAbstractInputMethod::reselect(int cursorPosition, const QVirtualKeyboardInputEngine::ReselectFlags &reselectFlags)
221{
222 Q_UNUSED(cursorPosition);
223 Q_UNUSED(reselectFlags);
224 return false;
225}
226
227/*!
228 \since QtQuick.VirtualKeyboard 2.4
229
230 Called when the user clicks on pre-edit text at \a cursorPosition.
231
232 The function should return \c true if it handles the event. Otherwise the input
233 falls back to \l reselect() for further processing.
234*/
235bool QVirtualKeyboardAbstractInputMethod::clickPreeditText(int cursorPosition)
236{
237 Q_UNUSED(cursorPosition);
238 return false;
239}
240
241/*!
242 \fn QList<QVirtualKeyboardInputEngine::InputMode> QVirtualKeyboardAbstractInputMethod::inputModes(const QString& locale)
243
244 Returns the list of input modes for \a locale.
245*/
246
247/*!
248 \fn bool QVirtualKeyboardAbstractInputMethod::setInputMode(const QString& locale, QVirtualKeyboardInputEngine::InputMode inputMode)
249
250 Sets the \a inputMode and \a locale for this input method. Returns \c true
251 if successful.
252*/
253
254/*!
255 \fn bool QVirtualKeyboardAbstractInputMethod::setTextCase(QVirtualKeyboardInputEngine::TextCase textCase)
256
257 Updates the \a textCase for this input method. The method returns \c true
258 if successful.
259*/
260
261/*!
262 \fn bool QVirtualKeyboardAbstractInputMethod::keyEvent(Qt::Key key, const QString& text, Qt::KeyboardModifiers modifiers)
263
264 The purpose of this method is to handle the key events generated by the the
265 input engine.
266
267 The \a key parameter specifies the code of the key to handle. The key code
268 does not distinguish between capital and non-capital letters. The \a
269 text parameter contains the Unicode text for the key. The \a modifiers
270 parameter contains the key modifiers that apply to key.
271
272 This method returns \c true if the key event was successfully handled.
273 If the return value is \c false, the key event is redirected to the default
274 input method for further processing.
275*/
276
277/*!
278 \fn QList<QVirtualKeyboardSelectionListModel::Type> QVirtualKeyboardAbstractInputMethod::selectionLists()
279
280 Returns the list of selection lists used by this input method.
281
282 This method is called by input engine when the input method is being
283 activated and every time the input method hints are updated. The input method
284 can reserve selection lists by returning the desired selection list types.
285
286 The input method may request the input engine to update the selection lists
287 at any time by emitting selectionListsChanged() signal. This signal will
288 trigger a call to this method, allowing the input method to update the selection
289 list types.
290*/
291
292/*!
293 \fn int QVirtualKeyboardAbstractInputMethod::selectionListItemCount(QVirtualKeyboardSelectionListModel::Type type)
294
295 Returns the number of items in the selection list identified by \a type.
296*/
297
298/*!
299 \fn QVariant QVirtualKeyboardAbstractInputMethod::selectionListData(QVirtualKeyboardSelectionListModel::Type type, int index, QVirtualKeyboardSelectionListModel::Role role)
300
301 Returns item data for the selection list identified by \a type. The \a role
302 parameter specifies which data is requested. The \a index parameter is a
303 zero based index into the list.
304*/
305
306/*!
307 \fn void QVirtualKeyboardAbstractInputMethod::selectionListItemSelected(QVirtualKeyboardSelectionListModel::Type type, int index)
308
309 This method is called when an item at \a index has been selected by the
310 user. The selection list is identified by the \a type parameter.
311*/
312
313/*!
314 \fn bool QVirtualKeyboardAbstractInputMethod::selectionListRemoveItem(QVirtualKeyboardSelectionListModel::Type type, int index)
315
316 This method is called when an item at \a index must be removed from dictionary.
317 The selection list is identified by the \a type parameter.
318 The function returns \c true if the word was successfully removed.
319*/
320
321/*!
322 \fn void QVirtualKeyboardAbstractInputMethod::selectionListChanged(QVirtualKeyboardSelectionListModel::Type type)
323
324 The input method emits this signal when the contents of the selection list
325 has changed. The \a type parameter specifies which selection list has
326 changed.
327*/
328
329/*!
330 \fn void QVirtualKeyboardAbstractInputMethod::selectionListActiveItemChanged(QVirtualKeyboardSelectionListModel::Type type, int index)
331
332 The input method emits this signal when the current \a index has changed
333 in the selection list identified by \a type.
334*/
335
336/*!
337 \fn void QVirtualKeyboardAbstractInputMethod::selectionListsChanged()
338 \since QtQuick.VirtualKeyboard 2.2
339
340 The input method emits this signal when the selection list types have
341 changed. This signal will trigger a call to selectionLists() method,
342 allowing the input method to update the selection list types.
343*/
344
345QT_END_NAMESPACE
346

source code of qtvirtualkeyboard/src/virtualkeyboard/qvirtualkeyboardabstractinputmethod.cpp