QT学习笔记(二):QWSServer class

来源:互联网 发布:熊猫直播数据 编辑:程序博客网 时间:2024/06/05 22:47
1. QWSServer Class 为 Qt for Embeded Linux 封装了一个服务进程 .
当你运行一个基于嵌入式平台的Qt程序时,它只能作为一个server或者连接到一个已经存在的server
来运行。

server和client进程有不同的职责: client进程执行应用程序特定的操作; server进程负责管理一个或多个client进程,同时负责指针操作,字符输入和屏幕输出。除此之外,server进程还要提供功能函数来处理不同的输入法。

在Qt for Embeded Linux中,系统产生的所有事件都被传送到server进程,然后再由server进程分
发给合适的client进程。

注意:在Qt for Embeded Linux中,QWSServer类是有QApplication进行实例化的。你不应该自己进行实例化。我们可以使用 QWSServer * QWSServer::instance () [static]   来获得
指向server的指针。
注意:所有QWSServer的static function都只能在server进程中调用。
server process: 在运行程序的时候指定 -qws 参数 或  QApplication a(argc, argv, QApplication::GuiServer);   

2. QWSServer的作用
当application增加或减少窗口的时候,server process就要维护每一个窗口的信息。

Client Administration

As applications add and remove windows, the server process maintains information about each window. InQt for Embedded Linux, top-level windows are encapsulated as QWSWindow objects. Each window can tell which client that owns it through its QWSWindow::client() function. Use the clientWindows() function to retrieve a list of the current top-level windows. Given a particular position on the display, the window containing it can be retrieved using the windowAt() function.

QWSServer also provides the windowEvent() signal which is emitted whenever something happens to a top level window; the WindowEvent enum describes the various types of events that the signal recognizes. In addition, the server class provides the markedText() signal which is emitted whenever some text has been selected in any of the windows, passing the selection as parameter.

The QCopChannel class and the QCOP communication protocol enable transfer of messages between clients. QWSServer provides the newChannel() and removedChannel() signals that is emitted whenever a newQCopChannel object is created or destroyed, respectively.

See also: QWSWindow, QWSClient and QCopChannel.

Mouse Handling

The mouse driver (represented by an instance of the QWSMouseHandler class) is loaded by the server application when it starts running, using Qt's plugin system. A mouse driver receives mouse events from the device and encapsulates each event with an instance of the QWSEvent class which it then passes to the server.

The openMouse() function opens the mouse devices specified by the QWS_MOUSE_PROTO environment variable, and the setMouseHandler() functions sets the primary mouse driver. Alternatively, the staticsetDefaultMouse() function provides means of specifying the mouse driver to use if the QWS_MOUSE_PROTOvariable is not defined (note that the default is otherwise platform dependent). The primary mouse driver can be retrieved using the static mouseHandler() function. Use the closeMouse() function to delete the mouse drivers.

In addition, the QWSServer class can control the flow of mouse input using the suspendMouse() andresumeMouse() functions.

See also: QWSMouseHandler and Qt for Embedded Linux Pointer Handling.

Keyboard Handling

The keyboard driver (represented by an instance of the QWSKeyboardHandler class) is loaded by the server application when it starts running, using Qt's plugin system. A keyboard driver receives keyboard events from the device and encapsulates each event with an instance of the QWSEvent class which it then passes to the server.

The openKeyboard() function opens the keyboard devices specified by the QWS_KEYBOARD environment variable, and the setKeyboardHandler() functions sets the primary keyboard driver. Alternatively, the staticsetDefaultKeyboard() function provides means of specifying the keyboard driver to use if theQWS_KEYBOARD variable is not defined (note again that the default is otherwise platform dependent). The primary keyboard driver can be retrieved using the static keyboardHandler() function. Use thecloseKeyboard() function to delete the keyboard drivers.

In addition, the QWSServer class can handle key events from both physical and virtual keyboards using theprocessKeyEvent() and sendKeyEvent() functions, respectively. Use the addKeyboardFilter() function to filter the key events from physical keyboard drivers, the most recently added filter can be removed and deleted using the removeKeyboardFilter() function.

See also: QWSKeyboardHandler and Qt for Embedded Linux Character Input.

Display Handling

When a screen update is required, the server runs through all the top-level windows that intersect with the region that is about to be updated, and ensures that the associated clients have updated their memory buffer. Then the server uses the screen driver (represented by an instance of the QScreen class) to copy the content of the memory to the screen.

In addition, the QWSServer class provides some means of managing the screen output: Use the refresh() function to refresh the entire display, or alternatively a specified region of it. The enablePainting() function can be used to disable (and enable) painting onto the screen. QWSServer also provide thesetMaxWindowRect() function restricting the area of the screen which Qt for Embedded Linux applications will consider to be the maximum area to use for windows. To set the brush used as the background in the absence of obscuring windows, QWSServer provides the static setBackground() function. The correspondingbackgroundBrush() function returns the currently set brush.

QWSServer also controls the screen saver: Use the setScreenSaver() to install a custom screen saver derived from the QWSScreenSaver class. Once installed, the screensaver can be activated using thescreenSaverActivate() function, and the screenSaverActive() function returns its current status. Use thesetScreenSaverInterval() function to specify the timeout interval. Qt for Embedded Linux also supports multilevel screen saving, use the setScreenSaverIntervals() function to specify the various levels and their timeout intervals.

Finally, the QWSServer class controls the cursor's appearance, i.e., use the setCursorVisible() function to hide or show the cursor, and the isCursorVisible() function to determine whether the cursor is visible on the display or not.

See also: QScreen and Qt for Embedded Linux Display Management.

Input Method Handling

Whenever the server receives an event, it queries its stack of top-level windows to find the window containing the event's position (each window can identify the client application that created it). Then the server forwards the event to the appropriate client. If an input method is installed, it is used as a filter between the server and the client application.

Derive from the QWSInputMethod class to create custom input methods, and use the server'ssetCurrentInputMethod() function to install it. Use the sendIMEvent() and sendIMQuery() functions to send input method events and queries.

QWSServer provides the IMMouse enum describing the various mouse events recognized by theQWSInputMethod::mouseHandler() function. The latter function allows subclasses of QWSInputMethod to handle mouse events within the preedit text.

See also QWSInputMethod.