From 0ddf665b86d4e6f6481817b7dd4a4bd83e218e5b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 27 Oct 2014 12:56:48 -0700 Subject: [PATCH] add an HFMetaEvent class as super class for meta events --- interface/CMakeLists.txt | 2 +- interface/src/Application.cpp | 13 +++++----- interface/src/{ => events}/HFActionEvent.cpp | 8 +++--- interface/src/{ => events}/HFActionEvent.h | 6 ++--- interface/src/events/HFMetaEvent.cpp | 20 +++++++++++++++ interface/src/events/HFMetaEvent.h | 27 ++++++++++++++++++++ 6 files changed, 62 insertions(+), 14 deletions(-) rename interface/src/{ => events}/HFActionEvent.cpp (71%) rename interface/src/{ => events}/HFActionEvent.h (85%) create mode 100644 interface/src/events/HFMetaEvent.cpp create mode 100644 interface/src/events/HFMetaEvent.h diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 9c4eeff65b..0867f15ac8 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -45,7 +45,7 @@ configure_file(InterfaceVersion.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceVe # grab the implementation and header files from src dirs file(GLOB INTERFACE_SRCS src/*.cpp src/*.h) -foreach(SUBDIR avatar devices renderer ui starfield location scripting voxels particles entities gpu) +foreach(SUBDIR avatar devices events renderer ui starfield location scripting voxels particles entities gpu) file(GLOB_RECURSE SUBDIR_SRCS src/${SUBDIR}/*.cpp src/${SUBDIR}/*.h) set(INTERFACE_SRCS ${INTERFACE_SRCS} "${SUBDIR_SRCS}") endforeach(SUBDIR) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 22371ce7d0..91ff7c3563 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -67,7 +67,6 @@ #include #include "Application.h" -#include "HFActionEvent.h" #include "InterfaceVersion.h" #include "Menu.h" #include "ModelUploader.h" @@ -78,6 +77,8 @@ #include "devices/OculusManager.h" #include "devices/TV3DManager.h" +#include "events/HFActionEvent.h" + #include "renderer/ProgramObject.h" #include "scripting/AccountScriptingInterface.h" @@ -139,6 +140,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _glWidget(new GLCanvas()), _nodeThread(new QThread(this)), _datagramProcessor(), + _undoStack(), + _undoStackScriptingInterface(&_undoStack), _frameCount(0), _fps(60.0f), _justStarted(true), @@ -175,8 +178,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _nodeBoundsDisplay(this), _previousScriptLocation(), _applicationOverlay(), - _undoStack(), - _undoStackScriptingInterface(&_undoStack), _runningScriptsWidget(NULL), _runningScriptsWidgetWasVisible(false), _trayIcon(new QSystemTrayIcon(_window)), @@ -835,7 +836,7 @@ bool Application::event(QEvent* event) { return false; } - + return QApplication::event(event); } @@ -1245,7 +1246,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { // nobody handled this - make it an action event on the _window object HFActionEvent actionEvent(HFActionEvent::startType(), event->localPos()); - sendEvent(_window, &actionEvent); + sendEvent(this, &actionEvent); } else if (event->button() == Qt::RightButton) { // right click items here @@ -1276,7 +1277,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { // fire an action end event HFActionEvent actionEvent(HFActionEvent::endType(), event->localPos()); - sendEvent(_window, &actionEvent); + sendEvent(this, &actionEvent); } } } diff --git a/interface/src/HFActionEvent.cpp b/interface/src/events/HFActionEvent.cpp similarity index 71% rename from interface/src/HFActionEvent.cpp rename to interface/src/events/HFActionEvent.cpp index 2ab2001ba4..e393a2f332 100644 --- a/interface/src/HFActionEvent.cpp +++ b/interface/src/events/HFActionEvent.cpp @@ -1,6 +1,6 @@ // // HFActionEvent.cpp -// interface/src +// interface/src/events // // Created by Stephen Birarda on 2014-10-27. // Copyright 2014 High Fidelity, Inc. @@ -12,19 +12,19 @@ #include "HFActionEvent.h" HFActionEvent::HFActionEvent(QEvent::Type type, const QPointF& localPosition) : - QEvent(type), + HFMetaEvent(type), _localPosition(localPosition) { } QEvent::Type HFActionEvent::startType() { - static QEvent::Type startType = static_cast(QEvent::registerEventType()); + static QEvent::Type startType = HFMetaEvent::newEventType(); return startType; } QEvent::Type HFActionEvent::endType() { - static QEvent::Type endType = static_cast(QEvent::registerEventType()); + static QEvent::Type endType = HFMetaEvent::newEventType(); return endType; } diff --git a/interface/src/HFActionEvent.h b/interface/src/events/HFActionEvent.h similarity index 85% rename from interface/src/HFActionEvent.h rename to interface/src/events/HFActionEvent.h index 2c7d323dc9..3371312755 100644 --- a/interface/src/HFActionEvent.h +++ b/interface/src/events/HFActionEvent.h @@ -1,6 +1,6 @@ // // HFActionEvent.h -// interface/src +// interface/src/events // // Created by Stephen Birarda on 2014-10-27. // Copyright 2014 High Fidelity, Inc. @@ -12,9 +12,9 @@ #ifndef hifi_HFActionEvent_h #define hifi_HFActionEvent_h -#include +#include "HFMetaEvent.h" -class HFActionEvent : public QEvent { +class HFActionEvent : public HFMetaEvent { public: HFActionEvent(QEvent::Type type, const QPointF& localPosition); diff --git a/interface/src/events/HFMetaEvent.cpp b/interface/src/events/HFMetaEvent.cpp new file mode 100644 index 0000000000..c9d77868cd --- /dev/null +++ b/interface/src/events/HFMetaEvent.cpp @@ -0,0 +1,20 @@ +// +// HFMetaEvent.cpp +// interface/src/events +// +// 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 "HFMetaEvent.h" + +QSet HFMetaEvent::_types = QSet(); + +QEvent::Type HFMetaEvent::newEventType() { + QEvent::Type newType = static_cast(QEvent::registerEventType()); + _types.insert(newType); + return newType; +} \ No newline at end of file diff --git a/interface/src/events/HFMetaEvent.h b/interface/src/events/HFMetaEvent.h new file mode 100644 index 0000000000..8fbdfab1fa --- /dev/null +++ b/interface/src/events/HFMetaEvent.h @@ -0,0 +1,27 @@ +// +// HFMetaEvent.h +// interface/src/events +// +// 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_HFMetaEvent_h +#define hifi_HFMetaEvent_h + +#include + +class HFMetaEvent : public QEvent { +public: + HFMetaEvent(QEvent::Type type) : QEvent(type) {}; + static const QSet& types() { return HFMetaEvent::_types; } +protected: + static QEvent::Type newEventType(); + + static QSet _types; +}; + +#endif // hifi_HFMetaEvent_h \ No newline at end of file