Tutorial: Create an Input method Plug-in that Modifies Keyboard Input
|
Function | Description |
---|---|
name | Returns a string identifying the plug-in that is translated for display to the user of the device. |
identifier | Returns a string identifying the plugin-in that is not translated but is suitable for identifying the plug-in. |
icon | Returns an Icon to display to the user while the plug-in is active. |
version | Returns a version string describing the version of the plug-in. |
properties | describes the capabilities and requirements of the plug-in. The return value is determined by the content of the flags provided in QtopiaInputMethod::Properties |
state | Returns whether the input method plug-in is:
|
reset | called when the plug-in is unloaded or needs to be returned to its initial state by the server. It resets the plug-in to its state at construction. |
inputModifier | Returns the QWSInputMethod object if the plug-in modifes keyboard or mouse input to generate text for a text input widget. |
Note: While setHint does not have to be re-implemented it is highly recommended. Qt Extended calls this function with a:
Typical types of input are:
However, applications can also define custom hints such as email so the input method should be able to handle hints it does not recognize and have some fall back mode if it is going to attempt to do more than simply activate on a non-null hint. In this example we will activate the input method only for the text and words hints.
Apart from the input and icon properties specific to this example, an unsigned long ref property is required for all Qt Extended plug-ins. It is used to keep a reference of where the input method is used and when it can be safely unloaded.
For a complete list of the composing input method plug-in implementation, see <qt-extended-root-dir>/examples/inputmethods/composing/composeimpl.cpp. This is a listing of the more critical code that needs to be included.
ComposeImpl::ComposeImpl(QObject *parent)
: QtopiaInputMethod(parent), input(0), ref(0)
{
// construct icon
}
Note: It is important to construct the plug-in with an appropriate parent and to set the value of ref to 0 in the constructor.
QWSInputMethod *ComposeImpl::inputModifier( ) { if ( !input ) input = new ComposeIM( ); return input; }
Returns the QWSInputMethod provided by the plug-in. If it has not constructed one already it should construct it now.
void ComposeImpl::setHint(const QString &hint, bool) { inputModifier(); if (hint.isEmpty() || hint == "numbers" || hint == "phone") { if (input->active()) { input->setActive(false); emit stateChanged(Sleeping); } } else if (!input->active()) { input->setActive(true); emit stateChanged(Ready); } } QtopiaInputMethod::State ComposeImpl::state() const { return (input && input->active()) ? Ready : Sleeping; }
As the example input method deals with the capitalization of text it should be inactive when the input required is either a number or a phone number. Custom hints might still require changing capitalization so the default is to be on if the hint is not recognized. The input method status is communicated to the server by the stateChanged() signal and the state() function.
int ComposeImpl::properties() const { return RequireKeypad | InputModifier; }
Our input method requires the device has keyboard or keypad input and also filters either keyboard/keypad or mouse events. This is represented by returning the combination of these flags for the properties. The properties of an input method are not expected to change.
QTOPIA_EXPORT_PLUGIN(ComposeImpl)
This macro is required to provide the code required to implement the functions allowing the plug-in to be queried and loaded.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt qtextended4.4 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com