Fix controls in HTML pages not responding to mouse events on tablet

This commit is contained in:
David Rowe 2017-04-01 10:40:06 +13:00
parent 8d4982d794
commit b03fd44240

View file

@ -350,38 +350,31 @@ void Web3DOverlay::handlePointerEventAsTouch(const PointerEvent& event) {
glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi); glm::vec2 windowPos = event.getPos2D() * (METERS_TO_INCHES * _dpi);
QPointF windowPoint(windowPos.x, windowPos.y); QPointF windowPoint(windowPos.x, windowPos.y);
if (event.getType() == PointerEvent::Move) {
// Forward a mouse move event to the Web surface so that hover events are generated.
// Must send a mouse move event that matches up with touch move event in order for scroll bars to work.
// Scroll bar dragging is a bit unstable in the tablet (content can jump up and down at times).
// This may be improved in Qt 5.8. Release notes: "Cleaned up touch and mouse event delivery".
QMouseEvent* mouseEvent = new QMouseEvent(QEvent::MouseMove, windowPoint, windowPoint, windowPoint, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
QCoreApplication::postEvent(_webSurface->getWindow(), mouseEvent);
}
if (event.getType() == PointerEvent::Press && event.getButton() == PointerEvent::PrimaryButton) { if (event.getType() == PointerEvent::Press && event.getButton() == PointerEvent::PrimaryButton) {
this->_pressed = true; this->_pressed = true;
} else if (event.getType() == PointerEvent::Release && event.getButton() == PointerEvent::PrimaryButton) { } else if (event.getType() == PointerEvent::Release && event.getButton() == PointerEvent::PrimaryButton) {
this->_pressed = false; this->_pressed = false;
} }
QEvent::Type type; QEvent::Type touchType;
Qt::TouchPointState touchPointState; Qt::TouchPointState touchPointState;
QEvent::Type mouseType;
switch (event.getType()) { switch (event.getType()) {
case PointerEvent::Press: case PointerEvent::Press:
type = QEvent::TouchBegin; touchType = QEvent::TouchBegin;
touchPointState = Qt::TouchPointPressed; touchPointState = Qt::TouchPointPressed;
mouseType = QEvent::MouseButtonPress;
break; break;
case PointerEvent::Release: case PointerEvent::Release:
type = QEvent::TouchEnd; touchType = QEvent::TouchEnd;
touchPointState = Qt::TouchPointReleased; touchPointState = Qt::TouchPointReleased;
mouseType = QEvent::MouseButtonRelease;
break; break;
case PointerEvent::Move: case PointerEvent::Move:
default: default:
type = QEvent::TouchUpdate; touchType = QEvent::TouchUpdate;
touchPointState = Qt::TouchPointMoved; touchPointState = Qt::TouchPointMoved;
mouseType = QEvent::MouseMove;
break; break;
} }
@ -393,13 +386,30 @@ void Web3DOverlay::handlePointerEventAsTouch(const PointerEvent& event) {
QList<QTouchEvent::TouchPoint> touchPoints; QList<QTouchEvent::TouchPoint> touchPoints;
touchPoints.push_back(point); touchPoints.push_back(point);
QTouchEvent* touchEvent = new QTouchEvent(type, &_touchDevice, event.getKeyboardModifiers()); QTouchEvent* touchEvent = new QTouchEvent(touchType, &_touchDevice, event.getKeyboardModifiers());
touchEvent->setWindow(_webSurface->getWindow()); touchEvent->setWindow(_webSurface->getWindow());
touchEvent->setTarget(_webSurface->getRootItem()); touchEvent->setTarget(_webSurface->getRootItem());
touchEvent->setTouchPoints(touchPoints); touchEvent->setTouchPoints(touchPoints);
touchEvent->setTouchPointStates(touchPointState); touchEvent->setTouchPointStates(touchPointState);
QCoreApplication::postEvent(_webSurface->getWindow(), touchEvent); QCoreApplication::postEvent(_webSurface->getWindow(), touchEvent);
// Send mouse events to the Web surface so that HTML dialog elements work with mouse press and hover.
// FIXME: Scroll bar dragging is a bit unstable in the tablet (content can jump up and down at times).
// This may be improved in Qt 5.8. Release notes: "Cleaned up touch and mouse event delivery".
Qt::MouseButtons buttons = Qt::NoButton;
if (event.getButtons() & PointerEvent::PrimaryButton) {
buttons |= Qt::LeftButton;
}
Qt::MouseButton button = Qt::NoButton;
if (event.getButton() == PointerEvent::PrimaryButton) {
button = Qt::LeftButton;
}
QMouseEvent* mouseEvent = new QMouseEvent(mouseType, windowPoint, windowPoint, windowPoint, button, buttons, Qt::NoModifier);
QCoreApplication::postEvent(_webSurface->getWindow(), mouseEvent);
} }
void Web3DOverlay::handlePointerEventAsMouse(const PointerEvent& event) { void Web3DOverlay::handlePointerEventAsMouse(const PointerEvent& event) {
@ -421,11 +431,12 @@ void Web3DOverlay::handlePointerEventAsMouse(const PointerEvent& event) {
buttons |= Qt::LeftButton; buttons |= Qt::LeftButton;
} }
QEvent::Type type;
Qt::MouseButton button = Qt::NoButton; Qt::MouseButton button = Qt::NoButton;
if (event.getButton() == PointerEvent::PrimaryButton) { if (event.getButton() == PointerEvent::PrimaryButton) {
button = Qt::LeftButton; button = Qt::LeftButton;
} }
QEvent::Type type;
switch (event.getType()) { switch (event.getType()) {
case PointerEvent::Press: case PointerEvent::Press:
type = QEvent::MouseButtonPress; type = QEvent::MouseButtonPress;