move WheelEvent out of EventTypes into its own file

This commit is contained in:
Stephen Birarda 2014-10-27 14:41:23 -07:00
parent e72409bf39
commit 818c97fcaf
5 changed files with 118 additions and 83 deletions

View file

@ -21,6 +21,7 @@
#include "KeyEvent.h"
#include "MouseEvent.h"
#include "TouchEvent.h"
#include "WheelEvent.h"
class AbstractInputController : public QObject {
Q_OBJECT

View file

@ -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(),

View file

@ -18,23 +18,6 @@
#include <QWheelEvent>
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);

View file

@ -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 <qscriptengine.h>
#include <qscriptvalue.h>
#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...
}

View file

@ -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 <QWheelEvent>
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