update TouchscreenDevice

* fix threading issue with zoom gesture
* KeyboardMouseDevice touchpad disabled to prevent interference
* device supported based on QTouchDevice::devices().count()
This commit is contained in:
Triplelexx 2016-06-27 21:01:06 +01:00
parent 90cd335bda
commit aae3555b63
5 changed files with 84 additions and 77 deletions

View file

@ -961,7 +961,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
// Setup the _keyboardMouseDevice, _touchscreenDevice and the user input mapper with the default bindings
userInputMapper->registerDevice(_keyboardMouseDevice->getInputDevice());
// if the _touchscreenDevice is not supported it will not be registered
if (_touchscreenDevice) {
userInputMapper->registerDevice(_touchscreenDevice->getInputDevice());
}
// force the model the look at the correct directory (weird order of operations issue)
scriptEngines->setScriptsLocation(scriptEngines->getScriptsLocation());
@ -2712,7 +2715,7 @@ void Application::touchUpdateEvent(QTouchEvent* event) {
if (_keyboardMouseDevice->isActive()) {
_keyboardMouseDevice->touchUpdateEvent(event);
}
if (Menu::getInstance()->isOptionChecked(TouchscreenDevice::NAME)) {
if (_touchscreenDevice->isActive()) {
_touchscreenDevice->touchUpdateEvent(event);
}
}
@ -2733,7 +2736,7 @@ void Application::touchBeginEvent(QTouchEvent* event) {
if (_keyboardMouseDevice->isActive()) {
_keyboardMouseDevice->touchBeginEvent(event);
}
if (Menu::getInstance()->isOptionChecked(TouchscreenDevice::NAME)) {
if (_touchscreenDevice->isActive()) {
_touchscreenDevice->touchBeginEvent(event);
}
@ -2753,7 +2756,7 @@ void Application::touchEndEvent(QTouchEvent* event) {
if (_keyboardMouseDevice->isActive()) {
_keyboardMouseDevice->touchEndEvent(event);
}
if (Menu::getInstance()->isOptionChecked(TouchscreenDevice::NAME)) {
if (_touchscreenDevice->isActive()) {
_touchscreenDevice->touchEndEvent(event);
}
@ -2761,7 +2764,7 @@ void Application::touchEndEvent(QTouchEvent* event) {
}
void Application::touchGestureEvent(QGestureEvent* event) {
if (Menu::getInstance()->isOptionChecked(TouchscreenDevice::NAME)) {
if (_touchscreenDevice->isActive()) {
_touchscreenDevice->touchGestureEvent(event);
}
}

View file

@ -19,7 +19,7 @@
#include <NumericalConstants.h>
const QString KeyboardMouseDevice::NAME = "Keyboard/Mouse";
bool KeyboardMouseDevice::_enableMouse = true;
bool KeyboardMouseDevice::_enableTouchpad = true;
void KeyboardMouseDevice::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
@ -62,7 +62,6 @@ void KeyboardMouseDevice::keyReleaseEvent(QKeyEvent* event) {
}
void KeyboardMouseDevice::mousePressEvent(QMouseEvent* event) {
if (_enableMouse) {
auto input = _inputDevice->makeInput((Qt::MouseButton) event->button());
auto result = _inputDevice->_buttonPressedMap.insert(input.getChannel());
if (!result.second) {
@ -74,10 +73,8 @@ void KeyboardMouseDevice::mousePressEvent(QMouseEvent* event) {
eraseMouseClicked();
}
}
void KeyboardMouseDevice::mouseReleaseEvent(QMouseEvent* event) {
if (_enableMouse) {
auto input = _inputDevice->makeInput((Qt::MouseButton) event->button());
_inputDevice->_buttonPressedMap.erase(input.getChannel());
@ -89,7 +86,6 @@ void KeyboardMouseDevice::mouseReleaseEvent(QMouseEvent* event) {
_inputDevice->_buttonPressedMap.insert(_inputDevice->makeInput((Qt::MouseButton) event->button(), true).getChannel());
}
}
}
void KeyboardMouseDevice::eraseMouseClicked() {
_inputDevice->_buttonPressedMap.erase(_inputDevice->makeInput(Qt::LeftButton, true).getChannel());
@ -98,7 +94,6 @@ void KeyboardMouseDevice::eraseMouseClicked() {
}
void KeyboardMouseDevice::mouseMoveEvent(QMouseEvent* event) {
if (_enableMouse) {
QPoint currentPos = event->pos();
QPoint currentMove = currentPos - _lastCursor;
@ -116,7 +111,6 @@ void KeyboardMouseDevice::mouseMoveEvent(QMouseEvent* event) {
eraseMouseClicked();
}
}
void KeyboardMouseDevice::wheelEvent(QWheelEvent* event) {
auto currentMove = event->angleDelta() / 120.0f;
@ -139,24 +133,30 @@ glm::vec2 evalAverageTouchPoints(const QList<QTouchEvent::TouchPoint>& points) {
}
void KeyboardMouseDevice::touchBeginEvent(const QTouchEvent* event) {
if (_enableTouchpad) {
_isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);
_lastTouch = evalAverageTouchPoints(event->touchPoints());
_lastTouchTime = _clock.now();
}
}
void KeyboardMouseDevice::touchEndEvent(const QTouchEvent* event) {
if (_enableTouchpad) {
_isTouching = false;
_lastTouch = evalAverageTouchPoints(event->touchPoints());
_lastTouchTime = _clock.now();
}
}
void KeyboardMouseDevice::touchUpdateEvent(const QTouchEvent* event) {
if (_enableTouchpad) {
auto currentPos = evalAverageTouchPoints(event->touchPoints());
_lastTouchTime = _clock.now();
if (!_isTouching) {
_isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);
} else {
}
else {
auto currentMove = currentPos - _lastTouch;
_inputDevice->_axisStateMap[_inputDevice->makeInput(TOUCH_AXIS_X_POS).getChannel()] = (currentMove.x > 0 ? currentMove.x : 0.0f);
@ -168,6 +168,7 @@ void KeyboardMouseDevice::touchUpdateEvent(const QTouchEvent* event) {
_lastTouch = currentPos;
}
}
controller::Input KeyboardMouseDevice::InputDevice::makeInput(Qt::Key code) const {
auto shortCode = (uint16_t)(code & KEYBOARD_MASK);

View file

@ -85,7 +85,7 @@ public:
void wheelEvent(QWheelEvent* event);
static void enableMouse(bool enableMouse) { _enableMouse = enableMouse; }
static void enableTouchpad(bool enableTouchpad) { _enableTouchpad = enableTouchpad; }
static const QString NAME;
@ -125,7 +125,7 @@ protected:
std::chrono::high_resolution_clock _clock;
std::chrono::high_resolution_clock::time_point _lastTouchTime;
static bool _enableMouse;
static bool _enableTouchpad;
};
#endif // hifi_KeyboardMouseDevice_h

View file

@ -51,6 +51,13 @@ void TouchscreenDevice::pluginUpdate(float deltaTime, const controller::InputCal
distanceScaleY = (_currentTouchVec.y - _firstTouchVec.y) / DPI_SCALE_Y;
_inputDevice->_axisStateMap[_inputDevice->makeInput(TOUCH_AXIS_Y_NEG).getChannel()] = distanceScaleY;
}
} else if (_touchPointCount == 2) {
if (_scaleFactor > _lastPinchScale && _scaleFactor != 0) {
_inputDevice->_axisStateMap[_inputDevice->makeInput(TOUCH_GESTURE_PINCH_POS).getChannel()] = 1.0f;
} else if (_scaleFactor != 0) {
_inputDevice->_axisStateMap[_inputDevice->makeInput(TOUCH_GESTURE_PINCH_NEG).getChannel()] = 1.0f;
}
_lastPinchScale = _scaleFactor;
}
}
@ -64,12 +71,12 @@ void TouchscreenDevice::InputDevice::focusOutEvent() {
void TouchscreenDevice::touchBeginEvent(const QTouchEvent* event) {
const QTouchEvent::TouchPoint& point = event->touchPoints().at(0);
_firstTouchVec = glm::vec2(point.pos().x(), point.pos().y());
KeyboardMouseDevice::enableMouse(false);
KeyboardMouseDevice::enableTouchpad(false);
}
void TouchscreenDevice::touchEndEvent(const QTouchEvent* event) {
_touchPointCount = 0;
KeyboardMouseDevice::enableMouse(true);
KeyboardMouseDevice::enableTouchpad(true);
}
void TouchscreenDevice::touchUpdateEvent(const QTouchEvent* event) {
@ -81,13 +88,7 @@ void TouchscreenDevice::touchUpdateEvent(const QTouchEvent* event) {
void TouchscreenDevice::touchGestureEvent(const QGestureEvent* event) {
if (QGesture* gesture = event->gesture(Qt::PinchGesture)) {
QPinchGesture* pinch = static_cast<QPinchGesture*>(gesture);
qreal scaleFactor = pinch->totalScaleFactor();
if (scaleFactor > _lastPinchScale && scaleFactor != 0) {
_inputDevice->_axisStateMap[_inputDevice->makeInput(TOUCH_GESTURE_PINCH_POS).getChannel()] = 1.0f;
} else if (scaleFactor != 0) {
_inputDevice->_axisStateMap[_inputDevice->makeInput(TOUCH_GESTURE_PINCH_NEG).getChannel()] = 1.0f;
}
_lastPinchScale = scaleFactor;
_scaleFactor = pinch->totalScaleFactor();
}
}

View file

@ -14,6 +14,7 @@
#include <controllers/InputDevice.h>
#include "InputPlugin.h"
#include <QtGui/qtouchdevice.h>
class QTouchEvent;
class QGestureEvent;
@ -35,7 +36,7 @@ public:
};
// Plugin functions
virtual bool isSupported() const override { return true; }
virtual bool isSupported() const override { return QTouchDevice::devices().count() > 0; }
virtual const QString& getName() const override { return NAME; }
virtual void pluginFocusOutEvent() override { _inputDevice->focusOutEvent(); }
@ -71,6 +72,7 @@ public:
protected:
qreal _lastPinchScale;
qreal _scaleFactor;
glm::vec2 _firstTouchVec;
glm::vec2 _currentTouchVec;
int _touchPointCount;