Qt 4.7: QWSInputMethod Class Reference

Qt Reference Documentation

# QWSInputMethod Class Reference

The QWSInputMethod class provides international input methods in Qt for Embedded Linux. More...

     #include <QWSInputMethod>

This class is under development and is subject to change.

Inherits: QObject.

- List of all members, including inherited members
- Obsolete members

## Public Types

enum | UpdateType { Update, FocusIn, FocusOut, Reset, Destroyed }

## Public Functions

| QWSInputMethod ()
virtual | ~QWSInputMethod ()
virtual bool | filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat )
virtual bool | filter ( const QPoint & position, int state, int wheel )
virtual void | mouseHandler ( int offset, int state )
virtual void | queryResponse ( int property, const QVariant & result )
virtual void | reset ()
virtual void | updateHandler ( int type )

- 29 public functions inherited from QObject

## Protected Functions

uint | inputResolutionShift () const
void | sendCommitString ( const QString & commitString, int replaceFromPosition = 0, int replaceLength = 0 )
void | sendEvent ( const QInputMethodEvent * event )
void | sendMouseEvent ( const QPoint & position, int state, int wheel )
void | sendPreeditString ( const QString & preeditString, int cursorPosition, int selectionLength = 0 )
void | sendQuery ( int property )
uint | setInputResolution ( bool isHigh )

- 7 protected functions inherited from QObject

### Additional Inherited Members

- 1 property inherited from QObject
- 1 public slot inherited from QObject
- 1 signal inherited from QObject
- 5 static public members inherited from QObject

## Detailed Description

The QWSInputMethod class provides international input methods in Qt for Embedded Linux.

Note that this class is only available in Qt for Embedded Linux.

A Qt for Embedded Linux application requires a server application to be running, or to be the server application itself. All system generated events, including keyboard and mouse events, are passed to the server application which then propagates the event to the appropriate client.

An input method consists of a filter and optionally a graphical interface, and is used to filter input events between the server and the client application.

### Creating Custom Input Methods

To implement a custom input method, derive from the QWSInputMethod class, and use the server's setCurrentInputMethod() function to install it.

When subclassing QWSInputMethod, you can reimplement the filter() functions to handle input from both physical and virtual keyboards as well as mouse devices. Note that the default implementations do nothing. Use the setInputResolution() function to control the number of bits shifted when filtering mouse input, i.e., when going from pointer resolution to screen resolution (the current resolution can be retrieved using the inputResolutionShift() function).

Reimplement the reset() function to restore the state of the input method. Note that the default implementation calls the sendEvent() function with empty preedit and commit strings if the input method is in compose mode (i.e., if the input method is actively composing a preedit string).

To receive replies to an input method query (sent using the sendQuery() function), you must reimplement the queryResponse() function, while the mouseHandler() function must be reimplemented if you want to handle mouse events within the preedit text. Reimplement the updateHandler() function to handle update events including resets and focus changes. The UpdateType enum describes the various types of update events recognized by the input method.

### Using Input Methods

In addition to the filter(), reset(), queryResponse(), mouseHandler() and updateHandler() function mentioned in the previous section, the QWSInputMethod provides several other functions helping the window system to manage the installed input methods.

The sendEvent() function sends the given event to the focus widget, while the sendPreeditString() function sends the given preedit text (encapsulated by an event). QWSInputMethod also provides the sendCommitString() convenience function which sends an event encapsulating the given commit string to the current focus widget, and the sendMouseEvent() function which sends the given mouse event.

Finally, the QWSInputMethod class provides the sendQuery() function for sending input method queries. This function encapsulates the event with a QWSEvent instance of the IMQuery type.

See also QWSServer and Qt for Embedded Linux Architecture.

## Member Type Documentation

### enum QWSInputMethod::UpdateType

This enum describes the various types of update events recognized by the input method.

Constant | Value | Description
--- | --- | ---
`QWSInputMethod::Update` | `0` | The input widget is updated in some way; use sendQuery() with Qt::ImMicroFocus as an argument for more information.
`QWSInputMethod::FocusIn` | `1` | A new input widget receives focus.
`QWSInputMethod::FocusOut` | `2` | The input widget loses focus.
`QWSInputMethod::Reset` | `3` | The input method should be reset.
`QWSInputMethod::Destroyed` | `4` | The input widget is destroyed.

See also updateHandler().

## Member Function Documentation

### QWSInputMethod::QWSInputMethod ()

Constructs a new input method.

Use the QWSServer::setCurrentInputMethod() function to install it.

### QWSInputMethod::~QWSInputMethod ()`[virtual]`

Destroys this input method, uninstalling it if it is installed.

### bool QWSInputMethod::filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat )`[virtual]`

Filters the key input identified by the given unicode, keycode, modifiers, isPress and autoRepeat parameters.

Note that the default implementation does nothing; reimplement this function to handle input from both physical and virtual devices.

The keycode is a Qt::Key value, and the modifiers is an OR combination of Qt::KeyboardModifiers. The isPress parameter is telling whether the input is a key press or key release, and the autoRepeat parameter determines whether the input is autorepeated ( i.e., in which case the QWSKeyboardHandler::beginAutoRepeat() function has been called).

To block the event from further processing, return true when reimplementing this function; the default implementation returns false.

See also setInputResolution() and inputResolutionShift().

### bool QWSInputMethod::filter ( const QPoint & position, int state, int wheel )`[virtual]`

This is an overloaded function.

Filters the mouse input identified by the given position, state, and wheel parameters.

### uint QWSInputMethod::inputResolutionShift () const`[protected]`

Returns the number of bits shifted to go from pointer resolution to screen resolution when filtering mouse input.

See also setInputResolution() and filter().

### void QWSInputMethod::mouseHandler ( int offset, int state )`[virtual]`

Handles mouse events within the preedit text.

Note that the default implementation resets the input method on all mouse presses; reimplement this function to alter this behavior.

The offset parameter specifies the position of the mouse event within the string, and state specifies the type of the mouse event as described by the QWSServer::IMMouse enum. If state is less than 0, the mouse event is inside the associated widget, but outside the preedit text. When clicking in a different widget, the state is QWSServer::MouseOutside.

See also sendPreeditString() and reset().

### void QWSInputMethod::queryResponse ( int property, const QVariant & result )`[virtual]`

Receive replies to an input method query.

Note that the default implementation does nothing; reimplement this function to receive such replies.

Internally, an input method query is passed encapsulated by an IMQuery event generated by the sendQuery() function. The queried property and the result is passed in the property and result parameters.

See also sendQuery() and QWSServer::sendIMQuery().

### void QWSInputMethod::reset ()`[virtual]`

Resets the state of the input method.

If the input method is in compose mode, i.e., the input method is actively composing a preedit string, the default implementation calls sendEvent() with empty preedit and commit strings; otherwise it does nothing. Reimplement this function to alter this behavior.

See also sendEvent().

### void QWSInputMethod::sendCommitString ( const QString & commitString, int replaceFromPosition = 0, int replaceLength = 0 )`[protected]`

Sends an event encapsulating the given commitString, to the focus widget.

Note that this will cause the input method to leave compose mode, i.e., the input method will no longer be actively composing the preedit string.

If the specified replaceLength is greater than 0, the commit string will replace the given number of characters of the receiving widget's previous text, starting at the given replaceFromPosition relative to the start of the current preedit string.

Internally, the event is represented by a QWSEvent object of the IMEvent type.

See also sendEvent() and sendPreeditString().

### void QWSInputMethod::sendEvent ( const QInputMethodEvent * event )`[protected]`

Sends the given event to the focus widget.

The `QInputMethodEvent` class is derived from QWSEvent, i.e., the given event is a QWSEvent object of the IMEvent type.

See also sendPreeditString(), sendCommitString(), and reset().

### void QWSInputMethod::sendMouseEvent ( const QPoint & position, int state, int wheel )`[protected]`

Sends a mouse event specified by the given position, state and wheel parameters.

The given position will be transformed if the screen coordinates do not match the pointer device coordinates.

Note that the event will be not be tested by the active input method, but calling the QWSServer::sendMouseEvent() function will make the current input method filter the event.

See also mouseHandler() and sendEvent().

### void QWSInputMethod::sendPreeditString ( const QString & preeditString, int cursorPosition, int selectionLength = 0 )`[protected]`

Sends an event encapsulating the given preeditString, to the focus widget.

The specified selectionLength is the number of characters to be marked as selected (starting at the given cursorPosition). If selectionLength is negative, the text before cursorPosition is marked.

The preedit string is marked with QInputContext::PreeditFormat, and the selected part is marked with QInputContext::SelectionFormat.

Sending an input method event with a non-empty preedit string will cause the input method to enter compose mode. Sending an input method event with an empty preedit string will cause the input method to leave compose mode, i.e., the input method will no longer be actively composing the preedit string.

Internally, the event is represented by a QWSEvent object of the IMEvent type.

See also sendEvent() and sendCommitString().

### void QWSInputMethod::sendQuery ( int property )`[protected]`

Sends an input method query (internally encapsulated by a QWSEvent of the IMQuery type) for the specified property.

To receive responses to input method queries, the virtual queryResponse() function must be reimplemented.

See also queryResponse() and QWSServer::sendIMQuery().

### uint QWSInputMethod::setInputResolution ( bool isHigh )`[protected]`

Sets and returns the number of bits shifted to go from pointer resolution to screen resolution when filtering mouse input.

If isHigh is true and the device has a pointer device resolution twice or more of the screen resolution, the positions passed to the filter() function will be presented at the higher resolution; otherwise the resolution will be equal to that of the screen resolution.

See also inputResolutionShift() and filter().

### void QWSInputMethod::updateHandler ( int type )`[virtual]`

Handles update events including resets and focus changes. The update events are specified by the given type which is one of the UpdateType enum values.

Note that reimplementations of this function must call the base implementation for all cases that it does not handle itself.

See also UpdateType.