added isPinching and isPinchOpening to touch events

This commit is contained in:
ZappoMan 2014-02-09 02:02:42 -08:00
parent 120807f9ba
commit d2b3e74f5d
6 changed files with 56 additions and 11 deletions

View file

@ -125,6 +125,7 @@ Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
function printTouchEvent(eventName, event) {
print(eventName);
print(" event.x,y=" + event.x + ", " + event.y);
print(" event.isPressed=" + event.isPressed);
print(" event.isMoved=" + event.isMoved);
@ -135,9 +136,11 @@ function printTouchEvent(eventName, event) {
print(" event.isMeta=" + event.isMeta);
print(" event.isAlt=" + event.isAlt);
for (var i = 0; i < event.points.length; i++) {
print(" event.points[" + i + "].x.y:" + event.points[i].x + ", " + event.points[i].y);
print(" event.points[" + i + "].x.y:" + event.points[i].x + ", " + event.points[i].y);
}
print(" event.radius=" + event.radius);
print(" event.isPinching=" + event.isPinching);
print(" event.isPinchOpening=" + event.isPinchOpening);
}

View file

@ -1324,7 +1324,9 @@ void Application::mouseReleaseEvent(QMouseEvent* event) {
}
void Application::touchUpdateEvent(QTouchEvent* event) {
_controllerScriptingInterface.emitTouchUpdateEvent(event); // send events to any registered scripts
TouchEvent thisEvent(*event, _lastTouchEvent);
_controllerScriptingInterface.emitTouchUpdateEvent(thisEvent); // send events to any registered scripts
_lastTouchEvent = thisEvent;
// if one of our scripts have asked to capture this event, then stop processing it
if (_controllerScriptingInterface.isTouchCaptured()) {
@ -1355,9 +1357,10 @@ void Application::touchUpdateEvent(QTouchEvent* event) {
}
void Application::touchBeginEvent(QTouchEvent* event) {
_controllerScriptingInterface.emitTouchBeginEvent(event); // send events to any registered scripts
TouchEvent thisEvent(*event, _lastTouchEvent);
_controllerScriptingInterface.emitTouchBeginEvent(thisEvent); // send events to any registered scripts
touchUpdateEvent(event);
_lastTouchEvent = thisEvent;
// if one of our scripts have asked to capture this event, then stop processing it
if (_controllerScriptingInterface.isTouchCaptured()) {
@ -1371,7 +1374,9 @@ void Application::touchBeginEvent(QTouchEvent* event) {
}
void Application::touchEndEvent(QTouchEvent* event) {
_controllerScriptingInterface.emitTouchEndEvent(event); // send events to any registered scripts
TouchEvent thisEvent(*event, _lastTouchEvent);
_controllerScriptingInterface.emitTouchEndEvent(thisEvent); // send events to any registered scripts
_lastTouchEvent = thisEvent;
// if one of our scripts have asked to capture this event, then stop processing it
if (_controllerScriptingInterface.isTouchCaptured()) {

View file

@ -490,6 +490,8 @@ private:
void displayUpdateDialog();
bool shouldSkipVersion(QString latestVersion);
void takeSnapshot();
TouchEvent _lastTouchEvent;
};
#endif /* defined(__interface__Application__) */

View file

@ -28,9 +28,10 @@ public:
void emitMousePressEvent(QMouseEvent* event) { emit mousePressEvent(MouseEvent(*event)); }
void emitMouseReleaseEvent(QMouseEvent* event) { emit mouseReleaseEvent(MouseEvent(*event)); }
void emitTouchBeginEvent(QTouchEvent* event) { emit touchBeginEvent(*event); }
void emitTouchEndEvent(QTouchEvent* event) { emit touchEndEvent(*event); }
void emitTouchUpdateEvent(QTouchEvent* event) { emit touchUpdateEvent(*event); }
void emitTouchBeginEvent(const TouchEvent& event) { emit touchBeginEvent(event); }
void emitTouchEndEvent(const TouchEvent& event) { emit touchEndEvent(event); }
void emitTouchUpdateEvent(const TouchEvent& event) { emit touchUpdateEvent(event); }
void emitWheelEvent(QWheelEvent* event) { emit wheelEvent(*event); }
bool isKeyCaptured(QKeyEvent* event) const;

View file

@ -324,12 +324,22 @@ TouchEvent::TouchEvent() :
isMeta(false),
isAlt(false),
points(),
radius(0)
radius(0),
isPinching(false),
isPinchOpening(false)
{
};
TouchEvent::TouchEvent(const QTouchEvent& event) {
initWithQTouchEvent(event);
}
TouchEvent::TouchEvent(const QTouchEvent& event, const TouchEvent& other) {
initWithQTouchEvent(event);
calculateMetaAttributes(other);
}
void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) {
// convert the touch points into an average
const QList<QTouchEvent::TouchPoint>& tPoints = event.touchPoints();
float touchAvgX = 0.0f;
@ -366,7 +376,6 @@ TouchEvent::TouchEvent(const QTouchEvent& event) {
}
}
radius = maxRadius;
isPressed = event.touchPointStates().testFlag(Qt::TouchPointPressed);
isMoved = event.touchPointStates().testFlag(Qt::TouchPointMoved);
@ -380,6 +389,21 @@ TouchEvent::TouchEvent(const QTouchEvent& event) {
isAlt = event.modifiers().testFlag(Qt::AltModifier);
}
void TouchEvent::calculateMetaAttributes(const TouchEvent& other) {
// calculate comparative event attributes...
if (other.radius > radius) {
isPinching = true;
isPinchOpening = false;
} else if (other.radius < radius) {
isPinchOpening = true;
isPinching = false;
} else {
isPinching = other.isPinching;
isPinchOpening = other.isPinchOpening;
}
}
QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& event) {
QScriptValue obj = engine->newObject();
obj.setProperty("x", event.x);
@ -402,6 +426,8 @@ QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& ev
}
obj.setProperty("points", pointsObj);
obj.setProperty("radius", event.radius);
obj.setProperty("isPinching", event.isPinching);
obj.setProperty("isPinchOpening", event.isPinchOpening);
return obj;
}

View file

@ -55,6 +55,8 @@ class TouchEvent {
public:
TouchEvent();
TouchEvent(const QTouchEvent& event);
TouchEvent(const QTouchEvent& event, const TouchEvent& other);
float x;
float y;
bool isPressed;
@ -67,6 +69,12 @@ public:
bool isAlt;
QVector<glm::vec2> points;
float radius;
bool isPinching;
bool isPinchOpening;
private:
void initWithQTouchEvent(const QTouchEvent& event);
void calculateMetaAttributes(const TouchEvent& other);
};
class WheelEvent {