The QWSInputMethod class provides international input methods in Qt for Embedded Linux. 更多...
| 头: | #include <QWSInputMethod> |
| 继承: | QObject |
该类在开发且可能改变。
| enum | UpdateType { Update, FocusIn, FocusOut, Reset, Destroyed } |
| 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 ) |
| 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 ) |
The QWSInputMethod class provides international input methods in Qt for Embedded Linux.
注意,此类只可用于 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.
To implement a custom input method, derive from the QWSInputMethod class, and use the server's setCurrentInputMethod() function to install it.
当子类化 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 () 函数)。
重实现 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.
除了 filter (), reset (), queryResponse (), mouseHandler () 和 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 还提供 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 类提供 sendQuery () function for sending input method queries. This function encapsulates the event with a QWSEvent instance of the IMQuery 类型。
另请参阅 QWSServer and Qt for Embedded Linux 体系结构 .
This enum describes the various types of update events recognized by the input method.
| 常量 | 值 | 描述 |
|---|---|---|
QWSInputMethod::Update
|
0
|
The input widget is updated in some way; use sendQuery () 采用 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. |
另请参阅 updateHandler ().
Constructs a new input method.
使用 QWSServer::setCurrentInputMethod () function to install it.
[虚拟]
QWSInputMethod::
~QWSInputMethod
()
Destroys this input method, uninstalling it if it is installed.
[虚拟]
bool
QWSInputMethod::
filter
(
int
unicode
,
int
keycode
,
int
modifiers
,
bool
isPress
,
bool
autoRepeat
)
Filters the key input identified by the given unicode , keycode , modifiers , isPress and autoRepeat 参数。
Note that the default implementation does nothing; reimplement this function to handle input from both physical and virtual devices.
The keycode 是 Qt::Key value, and the modifiers is an OR combination of Qt::KeyboardModifiers 。 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.
另请参阅 setInputResolution () 和 inputResolutionShift ().
[虚拟]
bool
QWSInputMethod::
filter
(const
QPoint
&
position
,
int
state
,
int
wheel
)
这是重载函数。
Filters the mouse input identified by the given position , state ,和 wheel 参数。
[protected]
uint
QWSInputMethod::
inputResolutionShift
() const
Returns the number of bits shifted to go from pointer resolution to screen resolution when filtering mouse input.
另请参阅 setInputResolution () 和 filter ().
[虚拟]
void
QWSInputMethod::
mouseHandler
(
int
offset
,
int
state
)
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 .
另请参阅 sendPreeditString () 和 reset ().
[虚拟]
void
QWSInputMethod::
queryResponse
(
int
property
, const
QVariant
&
result
)
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 参数。
另请参阅 sendQuery () 和 QWSServer::sendIMQuery ().
[虚拟]
void
QWSInputMethod::
reset
()
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.
另请参阅 sendEvent ().
[protected]
void
QWSInputMethod::
sendCommitString
(const
QString
&
commitString
,
int
replaceFromPosition
= 0,
int
replaceLength
= 0)
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.
若指定 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 类型。
另请参阅 sendEvent () 和 sendPreeditString ().
[protected]
void
QWSInputMethod::
sendEvent
(const
QInputMethodEvent
*
event
)
发送给定 event to the focus widget.
The
QInputMethodEvent
类派生自
QWSEvent
, i.e., the given
event
是
QWSEvent
object of the
IMEvent
类型。
另请参阅 sendPreeditString (), sendCommitString (),和 reset ().
[protected]
void
QWSInputMethod::
sendMouseEvent
(const
QPoint
&
position
,
int
state
,
int
wheel
)
Sends a mouse event specified by the given position , state and wheel 参数。
给定 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.
另请参阅 mouseHandler () 和 sendEvent ().
[protected]
void
QWSInputMethod::
sendPreeditString
(const
QString
&
preeditString
,
int
cursorPosition
,
int
selectionLength
= 0)
Sends an event encapsulating the given preeditString , to the focus widget.
指定 selectionLength is the number of characters to be marked as selected (starting at the given cursorPosition )。若 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 类型。
另请参阅 sendEvent () 和 sendCommitString ().
[protected]
void
QWSInputMethod::
sendQuery
(
int
property
)
Sends an input method query (internally encapsulated by a QWSEvent 的 IMQuery type) for the specified property .
To receive responses to input method queries, the virtual queryResponse () function must be reimplemented.
另请参阅 queryResponse () 和 QWSServer::sendIMQuery ().
[protected]
uint
QWSInputMethod::
setInputResolution
(
bool
isHigh
)
Sets and returns the number of bits shifted to go from pointer resolution to screen resolution when filtering mouse input.
若 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.
另请参阅 inputResolutionShift () 和 filter ().
[虚拟]
void
QWSInputMethod::
updateHandler
(
int
type
)
Handles update events including resets and focus changes. The update events are specified by the given type which is one of the UpdateType 枚举值。
Note that reimplementations of this function must call the base implementation for all cases that it does not handle itself.
另请参阅 UpdateType .