📄 pointer-qws.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - Qt/Embedded Pointer Handling</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }--></style></head><body bgcolor="#ffffff"><p><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align="center"> Qt/Embedded Pointer Handling</h1><br clear="all"><p>Pointer handling in Qt/Embedded works for any mouse-like device such asa touchpanel, a trackball, or real mouse.<p>In a real device, only a small number of pointer devices (usually one)would be supported, but for demonstration purposes, Qt/Embedded includesa large number of supported devices.<p><h2>Mouse Protocols</h2><p>Qt/Embedded normally auto-detects the mouse type and device if it is one ofthe supported types on <tt>/dev/psaux</tt> or one of the <tt>/dev/ttyS?</tt>serial lines. If multiple mice are detected, all may be used simultaneously.<p>Alternatively, you may set the environment variable QWS_MOUSE_PROTO todetermine which mouse to use. This environment variable may be set to:<blockquote> <i><protocol></i><tt>:</tt><i><device></i></blockquote>where <i><protocol></i> is one of:<ul> <li>MouseMan <li>IntelliMouse <li>Microsoft</ul>and <i><device></i> is the mouse device, often <tt>/dev/mouse</tt>.If no such variable is specified, the built-in defaultis <tt>Auto</tt> which enables auto-detection of the mouse protocoland device.<p>To add another protocol, new subclasses of QAutoMouseSubHandler orQMouseHandler can be written in <tt>kernel/qwsmouse_qws.cpp</tt>.<p><h2>Touch Panels</h2><p>Qt/Embedded ships with support for the NEC Vr41XX touchpaneland the iPAQ touchpanel.These are subclasses of QCalibratedMouseHandler which is in turna subclass of QMouseHandler in <tt>kernel/qwsmouse_qws.cpp</tt>.<p>Writing a custom touch panel handler for Qt/Embedded is not ashard as the QVrTPanelHandlerPrivate class makes it look.The Vr41XX touch panel handler is complex; it handles filtering ofnoisy input data, and it generates mouse release events by using atimer. <p>Many touch panel devices have a much simpler interface, so aport to Qt/Embedded can be written in a few minutes, without expertknowledge of Qt/Embedded.<p>The Qt/Embedded release contains an example touch panel handler in theclass QCustomTPanelHandlerPrivate, located in the file<tt>$QTDIR/src/kernel/qwsmouse_qws.cpp</tt>. It is protected by<tt>#ifdefQWS_CUSTOMTOUCHPANEL</tt>.<p>The example reads data from /dev/ts with the following format:Each packet consists of 5 bytes. <ul><li>Byte 0 gives status information, in particular, bit 6 (0x40)is 1 when the stylus is down, 0 if it is released.<li> Bytes 1 and 2 give the x position;<li> Bytes 3 and 4 give the y position;</ul><p>To enable this driver, uncomment the line <tt>#define QWS_CUSTOMTOUCHPANEL</tt>in the file qwsmouse_qws.cpp.<p>Chances are, your touch panel device will not match exactly theexample device. As an example, take a hypothetical device located at/dev/touchpanel. This device uses 6-byte packets. Byte 0 and 1 givestatus and pressure information. In particular, bit 5 (0x20) of byte 1tells whether the stylus is down or up. Bytes 2 and 3 give x position andbytes 4 and 5 give y position.<p>Pressure information is not necessary for basic Qt/Embedded operation,so we will ignore that for now. The following shows the modified touchpanel handler for the hypothetical device, with comments marked with<tt>//***<tt> indicating the changes made. You can also see some printfcalls left over from the (hypothetical) debugging.<p><pre>//*** Modified Trolltech's example handler to handle the//*** hypothetical touch panel.QCustomTPanelHandlerPrivate::QCustomTPanelHandlerPrivate( MouseProtocol, QString ){ //*** changed device name to /dev/touchpanel if ((mouseFD = open( "/dev/touchpanel", O_RDONLY)) < 0) { <a href="qapplication.html#290ef4">qWarning</a>( "Cannot open /dev/touchpanel (%s)", strerror(errno)); return; } //*** removed the delay since our device does not need it. //else { // sleep(1); //} <a href="qsocketnotifier.html">QSocketNotifier</a> *mouseNotifier; mouseNotifier = new <a href="qsocketnotifier.html">QSocketNotifier</a>( mouseFD, QSocketNotifier::Read, this ); connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));}QCustomTPanelHandlerPrivate::~QCustomTPanelHandlerPrivate(){ if (mouseFD >= 0) close(mouseFD);}struct CustomTPdata { unsigned char status; unsigned short xpos; unsigned short ypos;};void QCustomTPanelHandlerPrivate::readMouseData(){ if(!qt_screen) return; CustomTPdata data; //*** changed size to 6 bytes unsigned char data2[6]; int ret; //*** read 6 bytes ret=read(mouseFD,data2,6); if(ret==6) { //*** change to 6 //*** all the indexes changed: data.status=data2[1]; data.xpos=(data2[2] << 8) | data2[3]; data.ypos=(data2[4] << 8) | data2[5]; <a href="qpoint.html">QPoint</a> q; q.<a href="qpoint.html#75b57f">setX</a>(data.xpos); q.<a href="qpoint.html#c780b4">setY</a>(data.ypos); mousePos=q; if(data.status & 0x20) { //*** Changed to 0x20 (bit 5) emit mouseChanged(mousePos,Qt::LeftButton); //printf( "Stylus press/move %d,%d\n", data.xpos, data.ypos ); } else { emit mouseChanged(mousePos,0); //printf( "Stylus release %d,%d\n", data.xpos, data.ypos ); } } if(ret<0) { <a href="qapplication.html#72e78c">qDebug</a>("Error %s",strerror(errno)); }}</pre><p>Once you have your touch panel handler working, you may choose to keepit like it is. However, if you want to switch between differentmouse/touch panel devices at run time, you will have to modifyQWSServer::newMouseHandler() (also in qwsmouse_qws.cpp) to instantiateyour new handler(s). You will also need to add to the enum<tt>MouseProtocol</tt> and the table <tt>mouseConfig[]</tt>. Note thatthe precise details on how mouse and touch panel drivers are instantiatedmay have to be changed in future versions of Qt/Embedded.<p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -