History

move MouseEvent out of EventTypes into its own file

Stephen Birarda committed 12 years ago

Commit 3aa7c3c1 parent 5a390da5 files · +126 −92Browse files

Showing the changes to libraries/script-engine/src/EventTypes.cpp (1 of 5 files). Show all

Unified · Split

libraries/script-engine/src/EventTypes.cpp+2−71
@@ -13,87 +13,18 @@ · 12 unmodified lines
1313 #include <RegisteredMetaTypes.h>
1414
1515 #include "KeyEvent.h"
16+#include "MouseEvent.h"
1617
1718 #include "EventTypes.h"
1819
19−
2020 void registerEventTypes(QScriptEngine* engine) {
2121 qScriptRegisterMetaType(engine, KeyEvent::toScriptValue, KeyEvent::fromScriptValue);
22− qScriptRegisterMetaType(engine, mouseEventToScriptValue, mouseEventFromScriptValue);
22+ qScriptRegisterMetaType(engine, MouseEvent::toScriptValue, MouseEvent::fromScriptValue);
2323 qScriptRegisterMetaType(engine, touchEventToScriptValue, touchEventFromScriptValue);
2424 qScriptRegisterMetaType(engine, wheelEventToScriptValue, wheelEventFromScriptValue);
2525 qScriptRegisterMetaType(engine, spatialEventToScriptValue, spatialEventFromScriptValue);
2626 }
2727
28−
29−
30−MouseEvent::MouseEvent() :
31− x(0.0f),
32− y(0.0f),
33− isLeftButton(false),
34− isRightButton(false),
35− isMiddleButton(false),
36− isShifted(false),
37− isControl(false),
38− isMeta(false),
39− isAlt(false)
40−{
41−};
42−
43−
44−MouseEvent::MouseEvent(const QMouseEvent& event, const unsigned int deviceID) :
45− x(event.x()),
46− y(event.y()),
47− deviceID(deviceID),
48− isLeftButton(event.buttons().testFlag(Qt::LeftButton)),
49− isRightButton(event.buttons().testFlag(Qt::RightButton)),
50− isMiddleButton(event.buttons().testFlag(Qt::MiddleButton)),
51− isShifted(event.modifiers().testFlag(Qt::ShiftModifier)),
52− isControl(event.modifiers().testFlag(Qt::ControlModifier)),
53− isMeta(event.modifiers().testFlag(Qt::MetaModifier)),
54− isAlt(event.modifiers().testFlag(Qt::AltModifier))
55−{
56− // single button that caused the event
57− switch (event.button()) {
58− case Qt::LeftButton:
59− button = "LEFT";
60− isLeftButton = true;
61− break;
62− case Qt::RightButton:
63− button = "RIGHT";
64− isRightButton = true;
65− break;
66− case Qt::MiddleButton:
67− button = "MIDDLE";
68− isMiddleButton = true;
69− break;
70− default:
71− button = "NONE";
72− break;
73− }
74−}
75−
76−QScriptValue mouseEventToScriptValue(QScriptEngine* engine, const MouseEvent& event) {
77− QScriptValue obj = engine->newObject();
78− obj.setProperty("x", event.x);
79− obj.setProperty("y", event.y);
80− obj.setProperty("button", event.button);
81− obj.setProperty("deviceID", event.deviceID);
82− obj.setProperty("isLeftButton", event.isLeftButton);
83− obj.setProperty("isRightButton", event.isRightButton);
84− obj.setProperty("isMiddleButton", event.isMiddleButton);
85− obj.setProperty("isShifted", event.isShifted);
86− obj.setProperty("isMeta", event.isMeta);
87− obj.setProperty("isControl", event.isControl);
88− obj.setProperty("isAlt", event.isAlt);
89−
90− return obj;
91−}
92−
93−void mouseEventFromScriptValue(const QScriptValue& object, MouseEvent& event) {
94− // nothing for now...
95−}
96−
9728 TouchEvent::TouchEvent() :
9829 x(0.0f),
9930 y(0.0f),