📄 qwsmouse_qws.cpp
字号:
if ( sendFiltered( t, Qt::LeftButton ) )
pressed = TRUE;
if ( pressed )
rtimer->start( 200, TRUE ); // release unreliable
}
} else if ( pressed ) {
rtimer->start( 50, TRUE );
pressed = FALSE;
}
idx += sizeof( ushort ) * 6;
}
int surplus = mouseIdx - idx;
for ( int i = 0; i < surplus; i++ )
mouseBuf[i] = mouseBuf[idx+i];
mouseIdx = surplus;
#endif
}
class QTPanelHandlerPrivate : public QCalibratedMouseHandler
{
Q_OBJECT
public:
QTPanelHandlerPrivate(MouseProtocol, QString dev);
~QTPanelHandlerPrivate();
private:
static const int mouseBufSize = 2048;
int mouseFD;
QPoint oldmouse;
bool waspressed;
QPointArray samples;
unsigned int currSample;
unsigned int numSamples;
int mouseIdx;
uchar mouseBuf[mouseBufSize];
private slots:
void readMouseData();
};
QTPanelHandlerPrivate::QTPanelHandlerPrivate( MouseProtocol, QString )
: samples(QT_QWS_TP_SAMPLE_SIZE), currSample(0), numSamples(0)
{
#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
#if defined(QT_QWS_IPAQ)
# ifdef QT_QWS_IPAQ_RAW
if ((mouseFD = open( "/dev/h3600_tsraw", O_RDONLY | O_NDELAY)) < 0) {
# else
if ((mouseFD = open( "/dev/h3600_ts", O_RDONLY | O_NDELAY)) < 0) {
# endif
qWarning( "Cannot open /dev/h3600_ts (%s)", strerror(errno));
return;
}
#elif defined(QT_QWS_EBX)
//# ifdef QT_QWS_EBX_TSRAW
# if 0
if ((mouseFD = open( "/dev/tsraw", O_RDONLY | O_NDELAY)) < 0) {
qWarning( "Cannot open /dev/tsraw (%s)", strerror(errno));
return;
}
# else
if ((mouseFD = open( "/dev/ts", O_RDONLY | O_NDELAY)) < 0) {
qWarning( "Cannot open /dev/ts (%s)", strerror(errno));
return;
}
# endif
#endif
QSocketNotifier *mouseNotifier;
mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read,
this );
connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
waspressed=FALSE;
mouseIdx = 0;
#endif
}
QTPanelHandlerPrivate::~QTPanelHandlerPrivate()
{
#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
if (mouseFD >= 0)
close(mouseFD);
#endif
}
void QTPanelHandlerPrivate::readMouseData()
{
#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
if(!qt_screen)
return;
int n;
do {
n = read(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx );
if ( n > 0 )
mouseIdx += n;
} while ( n > 0 && mouseIdx < mouseBufSize );
TS_EVENT *data;
int idx = 0;
while ( mouseIdx-idx >= (int)sizeof( TS_EVENT ) ) {
uchar *mb = mouseBuf+idx;
data = (TS_EVENT *) mb;
if(data->pressure >= QT_QWS_TP_PRESSURE_THRESHOLD) {
#ifdef QT_QWS_CUSTOM
samples[currSample] = QPoint( 1000 - data->x, data->y );
#else
samples[currSample] = QPoint( data->x, data->y );
#endif
numSamples++;
if ( numSamples >= samples.count() ) {
int maxd = 0;
unsigned int ignore = 0;
// throw away the "worst" sample
for ( unsigned int i = 0; i < samples.count(); i++ ) {
int d = ( mousePos - samples[i] ).manhattanLength();
if ( d > maxd ) {
maxd = d;
ignore = i;
}
}
bool first = TRUE;
// average the rest
for ( unsigned int i = 0; i < samples.count(); i++ ) {
if ( ignore != i ) {
if ( first ) {
mousePos = samples[i];
first = FALSE;
} else {
mousePos += samples[i];
}
}
}
mousePos /= (int)(samples.count() - 1);
# if defined(QT_QWS_IPAQ_RAW) || defined(QT_QWS_EBX_RAW)
mousePos = transform( mousePos );
# endif
if ( waspressed ) {
if ( QABS(mousePos.x()-oldmouse.x()) < QT_QWS_TP_MOVE_LIMIT &&
QABS(mousePos.y()-oldmouse.y()) < QT_QWS_TP_MOVE_LIMIT ) {
if ( oldmouse != mousePos ) {
emit mouseChanged(mousePos,Qt::LeftButton);
oldmouse=mousePos;
}
}
} else {
emit mouseChanged(mousePos,Qt::LeftButton);
oldmouse=mousePos;
waspressed=true;
}
}
currSample++;
if ( currSample >= samples.count() )
currSample = 0;
} else {
if ( waspressed ) {
currSample = 0;
numSamples = 0;
emit mouseChanged(oldmouse,0);
oldmouse = QPoint( -100, -100 );
waspressed=false;
}
}
idx += sizeof( TS_EVENT );
}
int surplus = mouseIdx - idx;
for ( int i = 0; i < surplus; i++ )
mouseBuf[i] = mouseBuf[idx+i];
mouseIdx = surplus;
#endif
}
// YOPY touch panel support based on changes contributed by Ron Victorelli
// (victorrj at icubed.com) to Custom TP driver.
//
class QYopyTPanelHandlerPrivate : public QWSMouseHandler {
Q_OBJECT
public:
QYopyTPanelHandlerPrivate(MouseProtocol, QString dev);
~QYopyTPanelHandlerPrivate();
private:
int mouseFD;
int prevstate;
private slots:
void readMouseData();
};
QYopyTPanelHandlerPrivate::QYopyTPanelHandlerPrivate( MouseProtocol, QString )
{
#ifdef QT_QWS_YOPY
if ((mouseFD = open( "/dev/ts", O_RDONLY)) < 0) {
qWarning( "Cannot open /dev/ts (%s)", strerror(errno));
return;
} else {
sleep(1);
}
prevstate=0;
QSocketNotifier *mouseNotifier;
mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read,
this );
connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
#endif
}
QYopyTPanelHandlerPrivate::~QYopyTPanelHandlerPrivate()
{
if (mouseFD >= 0)
close(mouseFD);
}
#define YOPY_XPOS(d) (d[1]&0x3FF)
#define YOPY_YPOS(d) (d[2]&0x3FF)
#define YOPY_PRES(d) (d[0]&0xFF)
#define YOPY_STAT(d) (d[3]&0x01 )
struct YopyTPdata {
unsigned char status;
unsigned short xpos;
unsigned short ypos;
};
void QYopyTPanelHandlerPrivate::readMouseData()
{
#ifdef QT_QWS_YOPY
if(!qt_screen)
return;
YopyTPdata data;
unsigned int yopDat[4];
int ret;
ret=read(mouseFD,&yopDat,sizeof(yopDat));
if(ret) {
data.status= ( YOPY_PRES(yopDat) ) ? 1 : 0;
data.xpos=YOPY_XPOS(yopDat);
data.ypos=YOPY_YPOS(yopDat);
QPoint q;
q.setX(data.xpos);
q.setY(data.ypos);
mousePos=q;
if(data.status && !prevstate) {
emit mouseChanged(mousePos,Qt::LeftButton);
} else if( !data.status && prevstate ) {
emit mouseChanged(mousePos,0);
}
prevstate = data.status;
}
if(ret<0) {
qDebug("Error %s",strerror(errno));
}
#endif
}
//alvin
// Sitsang touch panel support based on tslib
//
#ifdef QT_QWS_SITSANG
class QSitsangTPanelHandlerPrivate : public QCalibratedMouseHandler
{
Q_OBJECT
public:
QSitsangTPanelHandlerPrivate(MouseProtocol, QString dev);
~QSitsangTPanelHandlerPrivate();
private:
struct tsdev *ts;
private slots:
void readMouseData();
};
QSitsangTPanelHandlerPrivate::QSitsangTPanelHandlerPrivate( MouseProtocol, QString )
{
char* ts_file=NULL;
ts_file=getenv("TSLIB_TSDEVICE");
if ( ts_file ) {
ts = ts_open(ts_file,0);
} else {
ts = ts_open("/dev/input/event0",0);
}
if ( !ts ) {
qWarning("open touch device error for sitsang touchscreen");
}
if ( ts_config( ts )<0 ) {
qWarning("Open ts_config reading error for sitsang touchscreen");
}
QSocketNotifier *mouseNotifier;
mouseNotifier = new QSocketNotifier( ts->fd, QSocketNotifier::Read,
this );
connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
}
QSitsangTPanelHandlerPrivate::~QSitsangTPanelHandlerPrivate()
{
if ( ts )
ts_close(ts);
}
void QSitsangTPanelHandlerPrivate::readMouseData()
{
struct ts_sample samp;
QPoint tp;
int ret;
if ( !qt_screen )
return;
ret = ts_read( ts, &samp, 1);
if (ret <0 ){
qWarning("ts_read error for sitsang touchscreen");
return;
}
if ( ret == 1 ) {
mousePos.setX( samp.x );
mousePos.setY( samp.y );
if ( samp.pressure >= QT_QWS_TP_PRESSURE_THRESHOLD ) {
mouseChanged(mousePos, Qt::LeftButton);
} else {
mouseChanged(mousePos, 0);
}
}
}
#endif //QT_QWS_SITSANG
//alvin
class QCustomTPanelHandlerPrivate : public QWSMouseHandler {
Q_OBJECT
public:
QCustomTPanelHandlerPrivate(MouseProtocol, QString dev);
~QCustomTPanelHandlerPrivate();
private:
int mouseFD;
private slots:
void readMouseData();
};
QCustomTPanelHandlerPrivate::QCustomTPanelHandlerPrivate( MouseProtocol, QString )
{
#ifdef QWS_CUSTOMTOUCHPANEL
if ((mouseFD = open( "/dev/ts", O_RDONLY)) < 0) {
qWarning( "Cannot open /dev/ts (%s)", strerror(errno));
return;
} else {
sleep(1);
}
QSocketNotifier *mouseNotifier;
mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read,
this );
connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
#endif
}
QCustomTPanelHandlerPrivate::~QCustomTPanelHandlerPrivate()
{
if (mouseFD >= 0)
close(mouseFD);
}
struct CustomTPdata {
unsigned char status;
unsigned short xpos;
unsigned short ypos;
};
void QCustomTPanelHandlerPrivate::readMouseData()
{
#ifdef QWS_CUSTOMTOUCHPANEL
if(!qt_screen)
return;
CustomTPdata data;
unsigned char data2[5];
int ret;
ret=read(mouseFD,data2,5);
if(ret==5) {
data.status=data2[0];
data.xpos=(data2[1] << 8) | data2[2];
data.ypos=(data2[3] << 8) | data2[4];
QPoint q;
q.setX(data.xpos);
q.setY(data.ypos);
mousePos=q;
if(data.status & 0x40) {
emit mouseChanged(mousePos,Qt::LeftButton);
} else {
emit mouseChanged(mousePos,0);
}
}
if(ret<0) {
qDebug("Error %s",strerror(errno));
}
#endif
}
/*
* Virtual framebuffer mouse driver
*/
#ifndef QT_NO_QWS_VFB
#include "qvfbhdr.h"
extern int qws_display_id;
#endif
class QVFbMouseHandlerPrivate : public QWSMouseHandler {
Q_OBJECT
public:
QVFbMouseHandlerPrivate(MouseProtocol, QString dev);
~QVFbMouseHandlerPrivate();
bool isOpen() const { return mouseFD > 0; }
private:
static const int mouseBufSize = 128;
int mouseFD;
int mouseIdx;
uchar mouseBuf[mouseBufSize];
private slots:
void readMouseData();
};
QVFbMouseHandlerPrivate::QVFbMouseHandlerPrivate( MouseProtocol, QString mouseDev )
{
mouseFD = -1;
#ifndef QT_NO_QWS_VFB
if ( mouseDev.isEmpty() )
mouseDev = QString(QT_VFB_MOUSE_PIPE).arg(qws_display_id);
if ((mouseFD = open( mouseDev.local8Bit(), O_RDWR | O_NDELAY)) < 0) {
qDebug( "Cannot open %s (%s)", mouseDev.ascii(),
strerror(errno));
} else {
// Clear pending input
char buf[2];
while (read(mouseFD, buf, 1) > 0) { }
mouseIdx = 0;
QSocketNotifier *mouseNotifier;
mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read, this );
connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
}
#endif
}
QVFbMouseHandlerPrivate::~QVFbMouseHandlerPrivate()
{
#ifndef QT_NO_QWS_VFB
if (mouseFD >= 0)
close(mouseFD);
#endif
}
void QVFbMouseHandlerPrivate::readMouseData()
{
#ifndef QT_NO_QWS_VFB
int n;
do {
n = read(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx );
if ( n > 0 )
mouseIdx += n;
} while ( n > 0 );
int idx = 0;
while ( mouseIdx-idx >= int(sizeof( QPoint ) + sizeof( int )) ) {
uchar *mb = mouseBuf+idx;
QPoint *p = (QPoint *) mb;
mb += sizeof( QPoint );
int *bstate = (int *)mb;
mousePos = *p;
limitToScreen( mousePos );
emit mouseChanged(mousePos, *bstate);
idx += sizeof( QPoint ) + sizeof( int );
}
int surplus = mouseIdx - idx;
for ( int i = 0; i < surplus; i++ )
mouseBuf[i] = mouseBuf[idx+i];
mouseIdx = surplus;
#endif
}
/*
* return a QWSMouseHandler that supports /a spec.
*/
QWSMouseHandler* QWSServer::newMouseHandler(const QString& spec)
{
static int init=0;
if ( !init && qt_screen ) {
init = 1;
// mousePos = QPoint(qt_screen->width()/2,
// qt_screen->height()/2);
}
int c = spec.find(':');
QString mouseProto;
QString mouseDev;
if ( c >= 0 ) {
mouseProto = spec.left(c);
mouseDev = spec.mid(c+1);
} else {
mouseProto = spec;
}
MouseProtocol mouseProtocol = Unknown;
int idx = 0;
while (mouseProtocol == Unknown && mouseConfig[idx].name) {
if (mouseProto == QString(mouseConfig[idx].name)) {
mouseProtocol = mouseConfig[idx].id;
}
idx++;
}
QWSMouseHandler *handler = 0;
#ifdef QT_QWS_SITSANG
handler=new QSitsangTPanelHandlerPrivate(mouseProtocol,mouseDev);
#endif
#ifdef QWS_CUSTOMTOUCHPANEL
handler=new QCustomTPanelHandlerPrivate(mouseProtocol,mouseDev);
#endif
#ifdef QT_QWS_YOPY
handler=new QYopyTPanelHandlerPrivate(mouseProtocol,mouseDev);
#endif
#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
handler=new QTPanelHandlerPrivate(mouseProtocol,mouseDev);
#endif
#ifndef QWS_CUSTOMTOUCHPANEL
#if !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX)
switch ( mouseProtocol ) {
case Auto:
handler = new QAutoMouseHandler();
break;
case MouseMan:
case IntelliMouse:
case Microsoft:
case BusMouse:
handler = new QWSMouseHandlerPrivate( mouseProtocol, mouseDev );
break;
case QVFBMouse:
handler = new QVFbMouseHandlerPrivate( mouseProtocol, mouseDev );
break;
case TPanel:
handler = new QVrTPanelHandlerPrivate( mouseProtocol, mouseDev );
break;
default:
qDebug( "Mouse type %s unsupported", spec.latin1() );
}
#endif
#endif
return handler;
}
#include "qwsmouse_qws.moc"
#endif // QNX6
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -