struct TouchPoint {
int id;
short posX, posY;
short lastPosX, lastPosY;
short startPosX, startPosY;
int state;
unsigned short pressure; // 0 to 65535.
};
void simulateTouch (const TouchPacket *packet)
{
const TouchPacket::e_touchType type = packet->touchType();
const Qt::TouchPointStates states = static_cast<Qt::TouchPointStates>(packet->touchStates());
const Qt::KeyboardModifiers modifiers = packet->getQtModifiers();
const int numPoints = static_cast<int> ( packet->touchPoints().size() );
QList< QTouchEvent::TouchPoint > points;
points.reserve( numPoints );
const int width = this->mainWindow->width();
const int height = this->mainWindow->height();
QWidget *parent
= this
->mainWindow;
while (parent->parentWidget() != 0) {
parent = parent->parentWidget();
}
// need the position of the top level widget (position is relative to desktop and not parent widget)
const QPoint pos
= parent
->pos
();
for (int i(0); i<numPoints; ++i) {
const TouchPacket::TouchPoint & pkPoint( packet->touchPoints()[i] );
nextPt.
setScreenRect (QRectF());
nextPt.
setNormalizedPos(QPointF(pkPoint.
posX / qreal
(width
), pkPoint.
posY / qreal
(height
)));
nextPt.
setLastNormalizedPos(QPointF(pkPoint.
lastPosX / qreal
(width
), pkPoint.
lastPosY / qreal
(height
)));
nextPt.
setStartNormalizedPos(QPointF(pkPoint.
startPosX / qreal
(width
), pkPoint.
startPosY / qreal
(height
)));
nextPt.
setPos( QPointF(pkPoint.
posX, pkPoint.
posY) );
nextPt.setScenePos (nextPt.pos());
nextPt.setScreenPos(pos + nextPt.pos());
nextPt.
setLastPos( QPointF(pkPoint.
lastPosX, pkPoint.
lastPosY));
nextPt.setLastScenePos (nextPt.lastPos());
nextPt.setLastScreenPos(pos + nextPt.lastPos());
nextPt.
setStartPos(QPointF(pkPoint.
startPosX, pkPoint.
startPosY));
nextPt.setStartScenePos(nextPt.startPos());
nextPt.setStartScreenPos(pos + nextPt.startPos());
nextPt.setPressure( 1.0 ); //((double)pkPoint.pressure ) / 65535. ) ;
nextPt.setState (static_cast<Qt::TouchPointStates>(pkPoint.state));
points.push_back(nextPt);
//qDebug() << nextPt.pos() << nextPt.normalizedPos() << nextPt.state() << nextPt.pressure() << nextPt.screenRect();
}
QTouchEvent * tevent = NULL;
switch (type) {
case TouchPacket::TouchBegin:
tevent
= new QTouchEvent
( QEvent::TouchBegin,
&this
->touchDevice, modifiers, states, points
);
break;
case TouchPacket::TouchCancel:
tevent
= new QTouchEvent
( QEvent::TouchCancel,
&this
->touchDevice, modifiers, states, points
);
break;
case TouchPacket::TouchEnd:
tevent
= new QTouchEvent
( QEvent::TouchEnd,
&this
->touchDevice, modifiers, states, points
);
break;
case TouchPacket::TouchUpdate:
tevent
= new QTouchEvent
( QEvent::TouchUpdate,
&this
->touchDevice, modifiers, states, points
);
break;
default:
qWarning() << "Unknown touch packet" << type;
}
if (tevent) {
// The post event queue will take ownership of the event and delete it once it has been posted
QWidget *currentWidget
= this
->mainWindow
->childAt
(points.
at(0).
pos().
toPoint());
//qDebug() << "posting to" << currentWidget << "with" << tevent->touchPoints().count() << "points" << states;
}
}
struct TouchPoint {
int id;
short posX, posY;
short lastPosX, lastPosY;
short startPosX, startPosY;
int state;
unsigned short pressure; // 0 to 65535.
};
void simulateTouch (const TouchPacket *packet)
{
const TouchPacket::e_touchType type = packet->touchType();
const Qt::TouchPointStates states = static_cast<Qt::TouchPointStates>(packet->touchStates());
const Qt::KeyboardModifiers modifiers = packet->getQtModifiers();
const int numPoints = static_cast<int> ( packet->touchPoints().size() );
QList< QTouchEvent::TouchPoint > points;
points.reserve( numPoints );
const int width = this->mainWindow->width();
const int height = this->mainWindow->height();
QWidget *parent = this->mainWindow;
while (parent->parentWidget() != 0) {
parent = parent->parentWidget();
}
// need the position of the top level widget (position is relative to desktop and not parent widget)
const QPoint pos = parent->pos();
for (int i(0); i<numPoints; ++i) {
const TouchPacket::TouchPoint & pkPoint( packet->touchPoints()[i] );
nextPt.setRect (QRectF());
nextPt.setScreenRect (QRectF());
nextPt.setNormalizedPos(QPointF(pkPoint.posX / qreal(width), pkPoint.posY / qreal(height)));
nextPt.setLastNormalizedPos(QPointF(pkPoint.lastPosX / qreal(width), pkPoint.lastPosY / qreal(height)));
nextPt.setStartNormalizedPos(QPointF(pkPoint.startPosX / qreal(width), pkPoint.startPosY / qreal(height)));
nextPt.setPos( QPointF(pkPoint.posX, pkPoint.posY) );
nextPt.setScenePos (nextPt.pos());
nextPt.setScreenPos(pos + nextPt.pos());
nextPt.setLastPos( QPointF(pkPoint.lastPosX, pkPoint.lastPosY));
nextPt.setLastScenePos (nextPt.lastPos());
nextPt.setLastScreenPos(pos + nextPt.lastPos());
nextPt.setStartPos(QPointF(pkPoint.startPosX, pkPoint.startPosY));
nextPt.setStartScenePos(nextPt.startPos());
nextPt.setStartScreenPos(pos + nextPt.startPos());
nextPt.setPressure( 1.0 ); //((double)pkPoint.pressure ) / 65535. ) ;
nextPt.setState (static_cast<Qt::TouchPointStates>(pkPoint.state));
points.push_back(nextPt);
//qDebug() << nextPt.pos() << nextPt.normalizedPos() << nextPt.state() << nextPt.pressure() << nextPt.screenRect();
}
QTouchEvent * tevent = NULL;
switch (type) {
case TouchPacket::TouchBegin:
tevent = new QTouchEvent( QEvent::TouchBegin, &this->touchDevice, modifiers, states, points );
break;
case TouchPacket::TouchCancel:
tevent = new QTouchEvent( QEvent::TouchCancel, &this->touchDevice, modifiers, states, points );
break;
case TouchPacket::TouchEnd:
tevent = new QTouchEvent( QEvent::TouchEnd, &this->touchDevice, modifiers, states, points );
break;
case TouchPacket::TouchUpdate:
tevent = new QTouchEvent( QEvent::TouchUpdate, &this->touchDevice, modifiers, states, points );
break;
default:
qWarning() << "Unknown touch packet" << type;
}
if (tevent) {
// The post event queue will take ownership of the event and delete it once it has been posted
QWidget *currentWidget = this->mainWindow->childAt (points.at(0).pos().toPoint());
//qDebug() << "posting to" << currentWidget << "with" << tevent->touchPoints().count() << "points" << states;
QApplication::postEvent (currentWidget, tevent);
}
}
To copy to clipboard, switch view to plain text mode
struct TouchPoint {
int id;
short posX, posY;
short lastPosX, lastPosY;
short startPosX, startPosY;
int state;
unsigned short pressure; // 0 to 65535
};
struct TouchPoint {
int id;
short posX, posY;
short lastPosX, lastPosY;
short startPosX, startPosY;
int state;
unsigned short pressure; // 0 to 65535
};
To copy to clipboard, switch view to plain text mode
void simulateTouch (const TouchPacket *packet)
{
const TouchPacket::e_touchType type = packet->touchType();
const Qt::TouchPointStates states = static_cast<Qt::TouchPointStates>(packet->touchStates());
const Qt::KeyboardModifiers modifiers = packet->getQtModifiers();
const int numPoints = static_cast<int> ( packet->touchPoints().size() );
QList< QTouchEvent::TouchPoint > points;
points.reserve( numPoints );
const int width = this->mainWindow->width();
const int height = this->mainWindow->height();
QWidget *parent
= this
->mainWindow;
while (parent->parentWidget() != 0) {
parent = parent->parentWidget();
}
// need the position of the top level widget (position is relative to desktop and not parent widget)
const QPoint pos
= parent
->pos
();
for (int i(0); i<numPoints; ++i) {
const TouchPacket::TouchPoint & pkPoint( packet->touchPoints()[i] );
QTouchEvent::TouchPoint nextPt( pkPoint.id );
// Assign state based on touch type
QEventPoint::State pointState = QEventPoint::State::Unknown;
switch (type) {
case TouchPacket::TouchBegin:
pointState = QEventPoint::State::Pressed;
break;
case TouchPacket::TouchUpdate:
pointState = QEventPoint::State::Updated;
break;
case TouchPacket::TouchEnd:
pointState = QEventPoint::State::Released;
break;
case TouchPacket::TouchCancel:
pointState = QEventPoint::State::Stationary;
break;
default:
break;
}
QEventPoint nextPtNew
(pkPoint.
id, pointState,
QPointF(pkPoint.
posX, pkPoint.
posY),
QPointF(pkPoint.
posX + pos.
x(), pkPoint.
posY + pos.
y()));
QMutableEventPoint::setPressure(nextPtNew, pkPoint.pressure);
QMutableEventPoint::setState(nextPtNew, pointState);
QMutableEventPoint
::setGlobalLastPosition(nextPtNew,
QPointF(pkPoint.
posX + pos.
x(), pkPoint.
posY + pos.
y()));
QMutableEventPoint
::setScenePosition(nextPtNew,
QPointF(pkPoint.
posX + pos.
x(), pkPoint.
posY + pos.
y()));
points.push_back(nextPtNew);
}
QTouchEvent * tevent = NULL;
switch (type) {
case TouchPacket::TouchBegin:
//tevent = new QTouchEvent( QEvent::TouchBegin, &this->touchDevice, modifiers, states, points );
tevent
= new QTouchEvent
(QEvent::TouchBegin,
&this
->touchDevice, modifiers, points
);
break;
case TouchPacket::TouchCancel:
//tevent = new QTouchEvent( QEvent::TouchCancel, &this->touchDevice, modifiers, states, points );
tevent
= new QTouchEvent
(QEvent::TouchCancel,
&this
->touchDevice, modifiers, points
);
break;
case TouchPacket::TouchEnd:
//tevent = new QTouchEvent( QEvent::TouchEnd, &this->touchDevice, modifiers, states, points );
tevent
= new QTouchEvent
(QEvent::TouchEnd,
&this
->touchDevice, modifiers, points
);
break;
case TouchPacket::TouchUpdate:
//tevent = new QTouchEvent( QEvent::TouchUpdate, &this->touchDevice, modifiers, states, points );
tevent
= new QTouchEvent
(QEvent::TouchUpdate,
&this
->touchDevice, modifiers, points
);
break;
default:
qWarning() << "Unknown touch packet" << type;
}
if (tevent && !points.isEmpty()) {
// The post event queue will take ownership of the event and delete it once it has been posted
QWidget *currentWidget
= this
->mainWindow
->childAt
(points.
at(0).
pos().
toPoint());
//qDebug() << "posting to" << currentWidget << "with" << tevent->touchPoints().count() << "points" << states;
}
}
void simulateTouch (const TouchPacket *packet)
{
const TouchPacket::e_touchType type = packet->touchType();
const Qt::TouchPointStates states = static_cast<Qt::TouchPointStates>(packet->touchStates());
const Qt::KeyboardModifiers modifiers = packet->getQtModifiers();
const int numPoints = static_cast<int> ( packet->touchPoints().size() );
QList< QTouchEvent::TouchPoint > points;
points.reserve( numPoints );
const int width = this->mainWindow->width();
const int height = this->mainWindow->height();
QWidget *parent = this->mainWindow;
while (parent->parentWidget() != 0) {
parent = parent->parentWidget();
}
// need the position of the top level widget (position is relative to desktop and not parent widget)
const QPoint pos = parent->pos();
for (int i(0); i<numPoints; ++i) {
const TouchPacket::TouchPoint & pkPoint( packet->touchPoints()[i] );
QTouchEvent::TouchPoint nextPt( pkPoint.id );
// Assign state based on touch type
QEventPoint::State pointState = QEventPoint::State::Unknown;
switch (type) {
case TouchPacket::TouchBegin:
pointState = QEventPoint::State::Pressed;
break;
case TouchPacket::TouchUpdate:
pointState = QEventPoint::State::Updated;
break;
case TouchPacket::TouchEnd:
pointState = QEventPoint::State::Released;
break;
case TouchPacket::TouchCancel:
pointState = QEventPoint::State::Stationary;
break;
default:
break;
}
QEventPoint nextPtNew(pkPoint.id, pointState, QPointF(pkPoint.posX, pkPoint.posY),
QPointF(pkPoint.posX + pos.x(), pkPoint.posY + pos.y()));
QMutableEventPoint::setPressure(nextPtNew, pkPoint.pressure);
QMutableEventPoint::setState(nextPtNew, pointState);
QMutableEventPoint::setGlobalLastPosition(nextPtNew, QPointF(pkPoint.posX + pos.x(), pkPoint.posY + pos.y()));
QMutableEventPoint::setScenePosition(nextPtNew, QPointF(pkPoint.posX + pos.x(), pkPoint.posY + pos.y()));
points.push_back(nextPtNew);
}
QTouchEvent * tevent = NULL;
switch (type) {
case TouchPacket::TouchBegin:
//tevent = new QTouchEvent( QEvent::TouchBegin, &this->touchDevice, modifiers, states, points );
tevent = new QTouchEvent(QEvent::TouchBegin, &this->touchDevice, modifiers, points);
break;
case TouchPacket::TouchCancel:
//tevent = new QTouchEvent( QEvent::TouchCancel, &this->touchDevice, modifiers, states, points );
tevent = new QTouchEvent(QEvent::TouchCancel, &this->touchDevice, modifiers, points);
break;
case TouchPacket::TouchEnd:
//tevent = new QTouchEvent( QEvent::TouchEnd, &this->touchDevice, modifiers, states, points );
tevent = new QTouchEvent(QEvent::TouchEnd, &this->touchDevice, modifiers, points);
break;
case TouchPacket::TouchUpdate:
//tevent = new QTouchEvent( QEvent::TouchUpdate, &this->touchDevice, modifiers, states, points );
tevent = new QTouchEvent(QEvent::TouchUpdate, &this->touchDevice, modifiers, points);
break;
default:
qWarning() << "Unknown touch packet" << type;
}
if (tevent && !points.isEmpty()) {
// The post event queue will take ownership of the event and delete it once it has been posted
QWidget *currentWidget = this->mainWindow->childAt (points.at(0).pos().toPoint());
//qDebug() << "posting to" << currentWidget << "with" << tevent->touchPoints().count() << "points" << states;
QApplication::postEvent (currentWidget, tevent);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks