Merge pull request #10101 from ctrlaltdavid/21252

Fix tablet scrolling getting stuck to mouse pointer
This commit is contained in:
Seth Alves 2017-04-03 09:52:45 -07:00 committed by GitHub
commit 98a54d9119
2 changed files with 31 additions and 11 deletions

View file

@ -363,6 +363,16 @@ void Web3DOverlay::handlePointerEventAsTouch(const PointerEvent& event) {
QEvent::Type touchType; QEvent::Type touchType;
Qt::TouchPointState touchPointState; Qt::TouchPointState touchPointState;
QEvent::Type mouseType; QEvent::Type mouseType;
Qt::MouseButton button = Qt::NoButton;
Qt::MouseButtons buttons = Qt::NoButton;
if (event.getButton() == PointerEvent::PrimaryButton) {
button = Qt::LeftButton;
}
if (event.getButtons() & PointerEvent::PrimaryButton) {
buttons |= Qt::LeftButton;
}
switch (event.getType()) { switch (event.getType()) {
case PointerEvent::Press: case PointerEvent::Press:
touchType = QEvent::TouchBegin; touchType = QEvent::TouchBegin;
@ -378,6 +388,26 @@ void Web3DOverlay::handlePointerEventAsTouch(const PointerEvent& event) {
touchType = QEvent::TouchUpdate; touchType = QEvent::TouchUpdate;
touchPointState = Qt::TouchPointMoved; touchPointState = Qt::TouchPointMoved;
mouseType = QEvent::MouseMove; mouseType = QEvent::MouseMove;
if (((event.getButtons() & PointerEvent::PrimaryButton) > 0) != this->_pressed) {
// Mouse was pressed/released while off the overlay; convert touch and mouse events to press/release to reflect
// current mouse/touch status.
this->_pressed = !this->_pressed;
if (this->_pressed) {
touchType = QEvent::TouchBegin;
touchPointState = Qt::TouchPointPressed;
mouseType = QEvent::MouseButtonPress;
} else {
touchType = QEvent::TouchEnd;
touchPointState = Qt::TouchPointReleased;
mouseType = QEvent::MouseButtonRelease;
}
button = Qt::LeftButton;
buttons |= Qt::LeftButton;
}
break; break;
default: default:
return; return;
@ -403,16 +433,6 @@ void Web3DOverlay::handlePointerEventAsTouch(const PointerEvent& event) {
// FIXME: Scroll bar dragging is a bit unstable in the tablet (content can jump up and down at times). // 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". // 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); QMouseEvent* mouseEvent = new QMouseEvent(mouseType, windowPoint, windowPoint, windowPoint, button, buttons, Qt::NoModifier);
QCoreApplication::postEvent(_webSurface->getWindow(), mouseEvent); QCoreApplication::postEvent(_webSurface->getWindow(), mouseEvent);
} }

View file

@ -64,7 +64,7 @@ private:
glm::vec3 _normal; // surface normal glm::vec3 _normal; // surface normal
glm::vec3 _direction; // incoming direction of pointer ray. glm::vec3 _direction; // incoming direction of pointer ray.
Button _button { NoButtons }; // button assosiated with this event, (if type is Press, this will be the button that is pressed) Button _button { NoButtons }; // button associated with this event, (if type is Press, this will be the button that is pressed)
uint32_t _buttons { NoButtons }; // the current state of all the buttons. uint32_t _buttons { NoButtons }; // the current state of all the buttons.
Qt::KeyboardModifiers _keyboardModifiers; // set of keys held when event was generated Qt::KeyboardModifiers _keyboardModifiers; // set of keys held when event was generated
}; };