From 0b2d0a0b0776b5a6a5e3b64a49203266fa16de25 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 5 Sep 2014 17:30:19 -0700 Subject: [PATCH] Fix for mouse events. --- interface/src/Application.cpp | 30 ++++++++++++++++-------------- interface/src/Application.h | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6fff0bf171..12bd4331ba 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1151,7 +1151,8 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { showMouse = false; } - _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts + QMouseEvent deviceEvent = getDeviceEvent(event, deviceID); + _controllerScriptingInterface.emitMouseMoveEvent(&deviceEvent, deviceID); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { @@ -1166,11 +1167,13 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { _seenMouseMove = true; } - setMousePosition(event, deviceID); + _mouseX = deviceEvent.x(); + _mouseY = deviceEvent.y(); } void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { - _controllerScriptingInterface.emitMousePressEvent(event); // send events to any registered scripts + QMouseEvent deviceEvent = getDeviceEvent(event, deviceID); + _controllerScriptingInterface.emitMousePressEvent(&deviceEvent); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { @@ -1180,7 +1183,8 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { - setMousePosition(event, deviceID); + _mouseX = deviceEvent.x(); + _mouseY = deviceEvent.y(); _mouseDragStartedX = _mouseX; _mouseDragStartedY = _mouseY; _mousePressed = true; @@ -1202,7 +1206,8 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { } void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { - _controllerScriptingInterface.emitMouseReleaseEvent(event); // send events to any registered scripts + QMouseEvent deviceEvent = getDeviceEvent(event, deviceID); + _controllerScriptingInterface.emitMouseReleaseEvent(&deviceEvent); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { @@ -1211,7 +1216,8 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { - setMousePosition(event, deviceID); + _mouseX = deviceEvent.x(); + _mouseY = deviceEvent.y(); _mousePressed = false; checkBandwidthMeterClick(); if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { @@ -2325,16 +2331,12 @@ int Application::sendNackPackets() { return packetsSent; } -void Application::setMousePosition(QMouseEvent* event, unsigned int deviceID) { +QMouseEvent Application::getDeviceEvent(QMouseEvent* event, unsigned int deviceID) { if (deviceID > 0) { - // simulated events are in device coordinates - _mouseX = event->x(); - _mouseY = event->y(); - - } else { - _mouseX = _glWidget->getDeviceX(event->x()); - _mouseY = _glWidget->getDeviceY(event->y()); + return *event; } + return QMouseEvent(event->type(), QPointF(_glWidget->getDeviceX(event->x()), _glWidget->getDeviceY(event->y())), + event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers()); } void Application::queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 73f8555dbb..14d74012b5 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -435,7 +435,7 @@ private: int sendNackPackets(); - void setMousePosition(QMouseEvent* event, unsigned int deviceID); + QMouseEvent getDeviceEvent(QMouseEvent* event, unsigned int deviceID); MainWindow* _window; GLCanvas* _glWidget; // our GLCanvas has a couple extra features