1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qplatforminputcontext.h"
43 #include <qguiapplication.h>
45 #include "private/qkeymapper_p.h"
46 #include <qpa/qplatforminputcontext_p.h>
51 \class QPlatformInputContext
56 \brief The QPlatformInputContext class abstracts the input method dependent data and composing state.
58 An input method is responsible for inputting complex text that cannot
59 be inputted via simple keymap. It converts a sequence of input
60 events (typically key events) into a text string through the input
61 method specific converting process. The class of the processes are
62 widely ranging from simple finite state machine to complex text
63 translator that pools a whole paragraph of a text with text
64 editing capability to perform grammar and semantic analysis.
66 To abstract such different input method specific intermediate
67 information, Qt offers the QPlatformInputContext as base class. The
68 concept is well known as 'input context' in the input method
69 domain. An input context is created for a text widget in response
70 to a demand. It is ensured that an input context is prepared for
71 an input method before input to a text widget.
73 QPlatformInputContext provides an interface the actual input methods
74 can derive from by reimplementing methods.
82 QPlatformInputContext::QPlatformInputContext()
83 : QObject(*(new QPlatformInputContextPrivate))
90 QPlatformInputContext::~QPlatformInputContext()
95 Returns input context validity. Deriving implementations should return true.
97 bool QPlatformInputContext::isValid() const
103 Method to be called when input method needs to be reset. Called by QInputMethod::reset().
104 No further QInputMethodEvents should be sent as response.
106 void QPlatformInputContext::reset()
110 void QPlatformInputContext::commit()
115 Notification on editor updates. Called by QInputMethod::update().
117 void QPlatformInputContext::update(Qt::InputMethodQueries)
122 Called when when the word currently being composed in input item is tapped by
123 the user. Input methods often use this information to offer more word
124 suggestions to the user.
126 void QPlatformInputContext::invokeAction(QInputMethod::Action action, int cursorPosition)
128 Q_UNUSED(cursorPosition)
129 // Default behavior for simple ephemeral input contexts. Some
130 // complex input contexts should not be reset here.
131 if (action == QInputMethod::Click)
136 This function can be reimplemented to filter input events.
137 Return true if the event has been consumed. Otherwise, the unfiltered event will
138 be forwarded to widgets as ordinary way. Although the input events have accept()
139 and ignore() methods, leave it untouched.
141 bool QPlatformInputContext::filterEvent(const QEvent *event)
148 This function can be reimplemented to return virtual keyboard rectangle in currently active
149 window coordinates. Default implementation returns invalid rectangle.
151 QRectF QPlatformInputContext::keyboardRect() const
157 Active QPlatformInputContext is responsible for providing keyboardRectangle property to QInputMethod.
158 In addition of providing the value in keyboardRect function, it also needs to call this emit
159 function whenever the property changes.
161 void QPlatformInputContext::emitKeyboardRectChanged()
163 emit qApp->inputMethod()->keyboardRectangleChanged();
167 This function can be reimplemented to return true whenever input method is animating
168 shown or hidden. Default implementation returns false.
170 bool QPlatformInputContext::isAnimating() const
176 Active QPlatformInputContext is responsible for providing animating property to QInputMethod.
177 In addition of providing the value in isAnimation function, it also needs to call this emit
178 function whenever the property changes.
180 void QPlatformInputContext::emitAnimatingChanged()
182 emit qApp->inputMethod()->animatingChanged();
186 Request to show input panel.
188 void QPlatformInputContext::showInputPanel()
193 Request to hide input panel.
195 void QPlatformInputContext::hideInputPanel()
200 Returns input panel visibility status. Default implementation returns false.
202 bool QPlatformInputContext::isInputPanelVisible() const
208 Active QPlatformInputContext is responsible for providing visible property to QInputMethod.
209 In addition of providing the value in isInputPanelVisible function, it also needs to call this emit
210 function whenever the property changes.
212 void QPlatformInputContext::emitInputPanelVisibleChanged()
214 emit qApp->inputMethod()->visibleChanged();
217 QLocale QPlatformInputContext::locale() const
219 return qt_keymapper_private()->keyboardInputLocale;
222 void QPlatformInputContext::emitLocaleChanged()
224 emit qApp->inputMethod()->localeChanged();
227 Qt::LayoutDirection QPlatformInputContext::inputDirection() const
229 return qt_keymapper_private()->keyboardInputDirection;
232 void QPlatformInputContext::emitInputDirectionChanged(Qt::LayoutDirection newDirection)
234 emit qApp->inputMethod()->inputDirectionChanged(newDirection);
238 This virtual method gets called to notify updated focus to \a object.
239 \warning Input methods must not call this function directly.
241 void QPlatformInputContext::setFocusObject(QObject *object)
247 Returns true if current focus object supports input method events.
249 bool QPlatformInputContext::inputMethodAccepted() const
251 return QPlatformInputContextPrivate::s_inputMethodAccepted;
254 bool QPlatformInputContextPrivate::s_inputMethodAccepted = false;
256 void QPlatformInputContextPrivate::setInputMethodAccepted(bool accepted)
258 QPlatformInputContextPrivate::s_inputMethodAccepted = accepted;