⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qwsmouse_qws.cpp

📁 qte2.3.2版本,但是里面没有configure文件.需要重新添加
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      || fcntl(mouseFD, F_SETFL, O_NONBLOCK) < 0 )	qWarning("Error initializing touch panel.");    QSocketNotifier *mouseNotifier;    mouseNotifier = new QSocketNotifier( mouseFD, QSocketNotifier::Read,					 this );    connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));    rtimer = new QTimer( this );    connect( rtimer, SIGNAL(timeout()), this, SLOT(sendRelease()));    mouseIdx = 0;    setFilterSize( 3 );    printf("\033[?25l"); fflush(stdout); // VT100 cursor off}#endifQVrTPanelHandlerPrivate::~QVrTPanelHandlerPrivate(){    if (mouseFD >= 0)	close(mouseFD);}void QVrTPanelHandlerPrivate::sendRelease(){    sendFiltered( mousePos, 0 );}void QVrTPanelHandlerPrivate::readMouseData(){#ifdef QT_QWS_CASSIOPEIA    if(!qt_screen)	return;    static bool pressed = FALSE;    int n;    do {	n = read(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx );	if ( n > 0 )	    mouseIdx += n;    } while ( n > 0 && mouseIdx < mouseBufSize );    int idx = 0;    while ( mouseIdx-idx >= (int)sizeof( short ) * 6 ) {	uchar *mb = mouseBuf+idx;	ushort *data = (ushort *) mb;	if ( data[0] & 0x8000 ) {	    if ( data[5] > 750 ) {		QPoint t(data[3]-data[4],data[2]-data[1]);		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_OBJECTpublic:    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_OBJECTpublic:    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}#ifdef QT_QWS_PSIONclass QCustomTPanelHandlerPrivate : public QCalibratedMouseHandler {    Q_OBJECTpublic:    QCustomTPanelHandlerPrivate(MouseProtocol, QString dev);    ~QCustomTPanelHandlerPrivate();private:    int mouseFD;	int prevstate;	QPoint oldmouse;private slots:    void readMouseData();};QCustomTPanelHandlerPrivate::QCustomTPanelHandlerPrivate( MouseProtocol, QString ){    if ((mouseFD = open( "/dev/tpanel", O_RDONLY)) < 0) {        qWarning( "Cannot open /dev/tpanel (%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()));}QCustomTPanelHandlerPrivate::~QCustomTPanelHandlerPrivate(){    if (mouseFD >= 0)	close(mouseFD);}struct CustomTPdata {  unsigned short status;  unsigned short xpos;  unsigned short ypos;};void QCustomTPanelHandlerPrivate::readMouseData(){    if(!qt_screen)	return;    CustomTPdata data;    unsigned char data2[6];    int ret;    ret=read(mouseFD, &data2,sizeof(data2));    if(ret==sizeof(data2)) {	data.status = (data2[0] << 8) | data2[1];	data.xpos   = (data2[2] << 8) | data2[3];	data.ypos   = (data2[4] << 8) | data2[5];	QPoint q;	q.setX(data.xpos);	q.setY(data.ypos);	q = transform(q);	mousePos=q;	if (data.status && ! prevstate) {        	emit mouseChanged(mousePos,Qt::LeftButton);	} else if (! data.status && prevstate) {		emit mouseChanged(oldmouse,0);	}	oldmouse = q;	prevstate = data.status;    }    if(ret<0) {	qDebug("Error %s",strerror(errno));    }}#endif                                  // QT_QWS_PSION/* * Virtual framebuffer mouse driver */#ifndef QT_NO_QWS_VFB#include "qvfbhdr.h"extern int qws_display_id;#endifclass QVFbMouseHandlerPrivate : public QWSMouseHandler {    Q_OBJECTpublic:    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_PSION    handler=new QCustomTPanelHandlerPrivate(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#if ! defined(QWS_CUSTOMTOUCHPANEL) && ! defined(QT_QWS_PSION)#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;}#ifdef QT_QWS_PSION#define QT_QWS_IPAQ#endif#include "qwsmouse_qws.moc"#endif // QNX6

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -