Showing the changes to libraries/script-engine/src/EventTypes.cpp (1 of 7 files). Show all
Unified · Split
| @@ -10,6 +10,51 @@ · 9 unmodified lines | ||
| 10 | 10 | |
| 11 | 11 | #include "EventTypes.h" |
| 12 | 12 | |
| 13 | + | |
| 14 | +KeyEvent::KeyEvent() { | |
| 15 | + key = 0; | |
| 16 | + isShifted = false; | |
| 17 | + isMeta = false; | |
| 18 | + isValid = false; | |
| 19 | +} | |
| 20 | + | |
| 21 | + | |
| 22 | +KeyEvent::KeyEvent(const QKeyEvent& event) { | |
| 23 | + key = event.key(); | |
| 24 | + isShifted = event.modifiers().testFlag(Qt::ShiftModifier); | |
| 25 | + isMeta = event.modifiers().testFlag(Qt::ControlModifier); | |
| 26 | + isValid = true; | |
| 27 | +} | |
| 28 | + | |
| 29 | +MouseEvent::MouseEvent(const QMouseEvent& event) { | |
| 30 | + x = event.x(); | |
| 31 | + y = event.y(); | |
| 32 | +} | |
| 33 | + | |
| 34 | +TouchEvent::TouchEvent(const QTouchEvent& event) { | |
| 35 | + // convert the touch points into an average | |
| 36 | + const QList<QTouchEvent::TouchPoint>& tPoints = event.touchPoints(); | |
| 37 | + float touchAvgX = 0.0f; | |
| 38 | + float touchAvgY = 0.0f; | |
| 39 | + int numTouches = tPoints.count(); | |
| 40 | + if (numTouches > 1) { | |
| 41 | + for (int i = 0; i < numTouches; ++i) { | |
| 42 | + touchAvgX += tPoints[i].pos().x(); | |
| 43 | + touchAvgY += tPoints[i].pos().y(); | |
| 44 | + } | |
| 45 | + touchAvgX /= (float)(numTouches); | |
| 46 | + touchAvgY /= (float)(numTouches); | |
| 47 | + } | |
| 48 | + x = touchAvgX; | |
| 49 | + y = touchAvgY; | |
| 50 | +} | |
| 51 | + | |
| 52 | +WheelEvent::WheelEvent(const QWheelEvent& event) { | |
| 53 | + x = event.x(); | |
| 54 | + y = event.y(); | |
| 55 | +} | |
| 56 | + | |
| 57 | + | |
| 13 | 58 | void registerEventTypes(QScriptEngine* engine) { |
| 14 | 59 | qScriptRegisterMetaType(engine, keyEventToScriptValue, keyEventFromScriptValue); |
| 15 | 60 | qScriptRegisterMetaType(engine, mouseEventToScriptValue, mouseEventFromScriptValue); |
| @@ -19,28 +64,23 @@ void registerEventTypes(QScriptEngine* engine) { · 3 unmodified lines | ||
| 19 | 64 | |
| 20 | 65 | QScriptValue keyEventToScriptValue(QScriptEngine* engine, const KeyEvent& event) { |
| 21 | 66 | QScriptValue obj = engine->newObject(); |
| 22 | − /* | |
| 23 | − obj.setProperty("key", event.key()); | |
| 24 | − obj.setProperty("isAutoRepeat", event.isAutoRepeat()); | |
| 25 | − | |
| 26 | − bool isShifted = event.modifiers().testFlag(Qt::ShiftModifier); | |
| 27 | − bool isMeta = event.modifiers().testFlag(Qt::ControlModifier); | |
| 28 | − | |
| 29 | − obj.setProperty("isShifted", isShifted); | |
| 30 | − obj.setProperty("isMeta", isMeta); | |
| 31 | − */ | |
| 32 | − | |
| 67 | + obj.setProperty("key", event.key); | |
| 68 | + obj.setProperty("isShifted", event.isShifted); | |
| 69 | + obj.setProperty("isMeta", event.isMeta); | |
| 33 | 70 | return obj; |
| 34 | 71 | } |
| 35 | 72 | |
| 36 | 73 | void keyEventFromScriptValue(const QScriptValue &object, KeyEvent& event) { |
| 37 | − // nothing for now... | |
| 74 | + event.key = object.property("key").toVariant().toInt(); | |
| 75 | + event.isShifted = object.property("isShifted").toVariant().toBool(); | |
| 76 | + event.isMeta = object.property("isMeta").toVariant().toBool(); | |
| 77 | + event.isValid = object.property("key").isValid(); | |
| 38 | 78 | } |
| 39 | 79 | |
| 40 | 80 | QScriptValue mouseEventToScriptValue(QScriptEngine* engine, const MouseEvent& event) { |
| 41 | 81 | QScriptValue obj = engine->newObject(); |
| 42 | − obj.setProperty("x", event.x()); | |
| 43 | − obj.setProperty("y", event.y()); | |
| 82 | + obj.setProperty("x", event.x); | |
| 83 | + obj.setProperty("y", event.y); | |
| 44 | 84 | return obj; |
| 45 | 85 | } |
| 46 | 86 | |
| @@ -50,23 +90,8 @@ void mouseEventFromScriptValue(const QScriptValue &object, MouseEvent& event) { · 3 unmodified lines | ||
| 50 | 90 | |
| 51 | 91 | QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& event) { |
| 52 | 92 | QScriptValue obj = engine->newObject(); |
| 53 | − | |
| 54 | − // convert the touch points into an average | |
| 55 | − const QList<QTouchEvent::TouchPoint>& tPoints = event.touchPoints(); | |
| 56 | − float touchAvgX = 0.0f; | |
| 57 | − float touchAvgY = 0.0f; | |
| 58 | − int numTouches = tPoints.count(); | |
| 59 | − if (numTouches > 1) { | |
| 60 | − for (int i = 0; i < numTouches; ++i) { | |
| 61 | − touchAvgX += tPoints[i].pos().x(); | |
| 62 | − touchAvgY += tPoints[i].pos().y(); | |
| 63 | − } | |
| 64 | − touchAvgX /= (float)(numTouches); | |
| 65 | − touchAvgY /= (float)(numTouches); | |
| 66 | − } | |
| 67 | − | |
| 68 | − obj.setProperty("averageX", touchAvgX); | |
| 69 | − obj.setProperty("averageY", touchAvgY); | |
| 93 | + obj.setProperty("x", event.x); | |
| 94 | + obj.setProperty("y", event.y); | |
| 70 | 95 | return obj; |
| 71 | 96 | } |
| 72 | 97 | |
| @@ -76,8 +101,8 @@ void touchEventFromScriptValue(const QScriptValue &object, TouchEvent& event) { · 3 unmodified lines | ||
| 76 | 101 | |
| 77 | 102 | QScriptValue wheelEventToScriptValue(QScriptEngine* engine, const WheelEvent& event) { |
| 78 | 103 | QScriptValue obj = engine->newObject(); |
| 79 | − obj.setProperty("x", event.x()); | |
| 80 | − obj.setProperty("y", event.y()); | |
| 104 | + obj.setProperty("x", event.x); | |
| 105 | + obj.setProperty("y", event.y); | |
| 81 | 106 | return obj; |
| 82 | 107 | } |
| 83 | 108 | |