From 818c97fcafcce411e8d4b0c9a943f97a3916c968 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 27 Oct 2014 14:41:23 -0700 Subject: [PATCH] move WheelEvent out of EventTypes into its own file --- .../AbstractControllerScriptingInterface.h | 1 + libraries/script-engine/src/EventTypes.cpp | 64 +--------------- libraries/script-engine/src/EventTypes.h | 21 ------ libraries/script-engine/src/WheelEvent.cpp | 75 +++++++++++++++++++ libraries/script-engine/src/WheelEvent.h | 40 ++++++++++ 5 files changed, 118 insertions(+), 83 deletions(-) create mode 100644 libraries/script-engine/src/WheelEvent.cpp create mode 100644 libraries/script-engine/src/WheelEvent.h diff --git a/libraries/script-engine/src/AbstractControllerScriptingInterface.h b/libraries/script-engine/src/AbstractControllerScriptingInterface.h index b594d07f3e..589cbbb089 100644 --- a/libraries/script-engine/src/AbstractControllerScriptingInterface.h +++ b/libraries/script-engine/src/AbstractControllerScriptingInterface.h @@ -21,6 +21,7 @@ #include "KeyEvent.h" #include "MouseEvent.h" #include "TouchEvent.h" +#include "WheelEvent.h" class AbstractInputController : public QObject { Q_OBJECT diff --git a/libraries/script-engine/src/EventTypes.cpp b/libraries/script-engine/src/EventTypes.cpp index 0bb4d2fd9c..e2a868eb8d 100644 --- a/libraries/script-engine/src/EventTypes.cpp +++ b/libraries/script-engine/src/EventTypes.cpp @@ -15,6 +15,7 @@ #include "KeyEvent.h" #include "MouseEvent.h" #include "TouchEvent.h" +#include "WheelEvent.h" #include "EventTypes.h" @@ -22,71 +23,10 @@ void registerEventTypes(QScriptEngine* engine) { qScriptRegisterMetaType(engine, KeyEvent::toScriptValue, KeyEvent::fromScriptValue); qScriptRegisterMetaType(engine, MouseEvent::toScriptValue, MouseEvent::fromScriptValue); qScriptRegisterMetaType(engine, TouchEvent::toScriptValue, TouchEvent::fromScriptValue); - qScriptRegisterMetaType(engine, wheelEventToScriptValue, wheelEventFromScriptValue); + qScriptRegisterMetaType(engine, WheelEvent::toScriptValue, WheelEvent::fromScriptValue); qScriptRegisterMetaType(engine, spatialEventToScriptValue, spatialEventFromScriptValue); } -WheelEvent::WheelEvent() : - x(0.0f), - y(0.0f), - delta(0.0f), - orientation("UNKNOwN"), - isLeftButton(false), - isRightButton(false), - isMiddleButton(false), - isShifted(false), - isControl(false), - isMeta(false), - isAlt(false) -{ -}; - -WheelEvent::WheelEvent(const QWheelEvent& event) { - x = event.x(); - y = event.y(); - - delta = event.delta(); - if (event.orientation() == Qt::Horizontal) { - orientation = "HORIZONTAL"; - } else { - orientation = "VERTICAL"; - } - - // button pressed state - isLeftButton = (event.buttons().testFlag(Qt::LeftButton)); - isRightButton = (event.buttons().testFlag(Qt::RightButton)); - isMiddleButton = (event.buttons().testFlag(Qt::MiddleButton)); - - // keyboard modifiers - isShifted = event.modifiers().testFlag(Qt::ShiftModifier); - isMeta = event.modifiers().testFlag(Qt::MetaModifier); - isControl = event.modifiers().testFlag(Qt::ControlModifier); - isAlt = event.modifiers().testFlag(Qt::AltModifier); -} - - -QScriptValue wheelEventToScriptValue(QScriptEngine* engine, const WheelEvent& event) { - QScriptValue obj = engine->newObject(); - obj.setProperty("x", event.x); - obj.setProperty("y", event.y); - obj.setProperty("delta", event.delta); - obj.setProperty("orientation", event.orientation); - obj.setProperty("isLeftButton", event.isLeftButton); - obj.setProperty("isRightButton", event.isRightButton); - obj.setProperty("isMiddleButton", event.isMiddleButton); - obj.setProperty("isShifted", event.isShifted); - obj.setProperty("isMeta", event.isMeta); - obj.setProperty("isControl", event.isControl); - obj.setProperty("isAlt", event.isAlt); - return obj; -} - -void wheelEventFromScriptValue(const QScriptValue& object, WheelEvent& event) { - // nothing for now... -} - - - SpatialEvent::SpatialEvent() : locTranslation(0.0f), locRotation(), diff --git a/libraries/script-engine/src/EventTypes.h b/libraries/script-engine/src/EventTypes.h index 54c2934c42..d08d704587 100644 --- a/libraries/script-engine/src/EventTypes.h +++ b/libraries/script-engine/src/EventTypes.h @@ -18,23 +18,6 @@ #include -class WheelEvent { -public: - WheelEvent(); - WheelEvent(const QWheelEvent& event); - int x; - int y; - int delta; - QString orientation; - bool isLeftButton; - bool isRightButton; - bool isMiddleButton; - bool isShifted; - bool isControl; - bool isMeta; - bool isAlt; -}; - class SpatialEvent { public: SpatialEvent(); @@ -48,15 +31,11 @@ public: private: }; -Q_DECLARE_METATYPE(WheelEvent) Q_DECLARE_METATYPE(SpatialEvent) void registerEventTypes(QScriptEngine* engine); -QScriptValue wheelEventToScriptValue(QScriptEngine* engine, const WheelEvent& event); -void wheelEventFromScriptValue(const QScriptValue& object, WheelEvent& event); - QScriptValue spatialEventToScriptValue(QScriptEngine* engine, const SpatialEvent& event); void spatialEventFromScriptValue(const QScriptValue& object, SpatialEvent& event); diff --git a/libraries/script-engine/src/WheelEvent.cpp b/libraries/script-engine/src/WheelEvent.cpp new file mode 100644 index 0000000000..b329ef58c8 --- /dev/null +++ b/libraries/script-engine/src/WheelEvent.cpp @@ -0,0 +1,75 @@ +// +// WheelEvent.cpp +// script-engine/src +// +// Created by Stephen Birarda on 2014-10-27. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include + +#include "WheelEvent.h" + +WheelEvent::WheelEvent() : + x(0.0f), + y(0.0f), + delta(0.0f), + orientation("UNKNOwN"), + isLeftButton(false), + isRightButton(false), + isMiddleButton(false), + isShifted(false), + isControl(false), + isMeta(false), + isAlt(false) +{ + +} + +WheelEvent::WheelEvent(const QWheelEvent& event) { + x = event.x(); + y = event.y(); + + delta = event.delta(); + if (event.orientation() == Qt::Horizontal) { + orientation = "HORIZONTAL"; + } else { + orientation = "VERTICAL"; + } + + // button pressed state + isLeftButton = (event.buttons().testFlag(Qt::LeftButton)); + isRightButton = (event.buttons().testFlag(Qt::RightButton)); + isMiddleButton = (event.buttons().testFlag(Qt::MiddleButton)); + + // keyboard modifiers + isShifted = event.modifiers().testFlag(Qt::ShiftModifier); + isMeta = event.modifiers().testFlag(Qt::MetaModifier); + isControl = event.modifiers().testFlag(Qt::ControlModifier); + isAlt = event.modifiers().testFlag(Qt::AltModifier); +} + + +QScriptValue WheelEvent::toScriptValue(QScriptEngine* engine, const WheelEvent& event) { + QScriptValue obj = engine->newObject(); + obj.setProperty("x", event.x); + obj.setProperty("y", event.y); + obj.setProperty("delta", event.delta); + obj.setProperty("orientation", event.orientation); + obj.setProperty("isLeftButton", event.isLeftButton); + obj.setProperty("isRightButton", event.isRightButton); + obj.setProperty("isMiddleButton", event.isMiddleButton); + obj.setProperty("isShifted", event.isShifted); + obj.setProperty("isMeta", event.isMeta); + obj.setProperty("isControl", event.isControl); + obj.setProperty("isAlt", event.isAlt); + return obj; +} + +void WheelEvent::fromScriptValue(const QScriptValue& object, WheelEvent& event) { + // nothing for now... +} \ No newline at end of file diff --git a/libraries/script-engine/src/WheelEvent.h b/libraries/script-engine/src/WheelEvent.h new file mode 100644 index 0000000000..edac4bc3c3 --- /dev/null +++ b/libraries/script-engine/src/WheelEvent.h @@ -0,0 +1,40 @@ +// +// WheelEvent.h +// script-engine/src +// +// Created by Stephen Birarda on 2014-10-27. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_WheelEvent_h +#define hifi_WheelEvent_h + +#include + +class WheelEvent { +public: + WheelEvent(); + WheelEvent(const QWheelEvent& event); + + static QScriptValue toScriptValue(QScriptEngine* engine, const WheelEvent& event); + static void fromScriptValue(const QScriptValue& object, WheelEvent& event); + + int x; + int y; + int delta; + QString orientation; + bool isLeftButton; + bool isRightButton; + bool isMiddleButton; + bool isShifted; + bool isControl; + bool isMeta; + bool isAlt; +}; + +Q_DECLARE_METATYPE(WheelEvent) + +#endif // hifi_WheelEvent_h \ No newline at end of file