summaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire350@gmail.com>2015-10-22 22:40:13 +0200
committerSean Harmer <sean.harmer@kdab.com>2015-10-24 16:36:29 +0000
commit25990ea51fd00ae6ea62dd5ec0f03d5d9a1427f7 (patch)
treef2e85e6f64276ea8965d28f4ac9ccca7858d5cdc /src/input
parent72bca7a747b05f14d1db4fe3205860a46edf2d54 (diff)
Make aspects use the QEventFilterService
Change-Id: Ieb1d985b919b50844a236959250e1a2e80972aa1 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r--src/input/inputhandler.cpp22
-rw-r--r--src/input/inputhandler_p.h8
-rw-r--r--src/input/keyboardeventfilter.cpp2
-rw-r--r--src/input/mouseeventfilter.cpp3
-rw-r--r--src/input/qinputaspect.cpp14
5 files changed, 19 insertions, 30 deletions
diff --git a/src/input/inputhandler.cpp b/src/input/inputhandler.cpp
index fd83a16df..13d32b956 100644
--- a/src/input/inputhandler.cpp
+++ b/src/input/inputhandler.cpp
@@ -41,6 +41,7 @@
#include "assignkeyboardfocusjob_p.h"
#include "keyeventdispatcherjob_p.h"
#include "mouseeventdispatcherjob_p.h"
+#include <Qt3DCore/qeventfilterservice.h>
QT_BEGIN_NAMESPACE
@@ -54,7 +55,6 @@ InputHandler::InputHandler()
, m_keyboardInputManager(new KeyboardInputManager())
, m_mouseControllerManager(new MouseControllerManager())
, m_mouseInputManager(new MouseInputManager())
- , m_eventSource(Q_NULLPTR)
, m_keyboardEventFilter(new KeyboardEventFilter())
, m_mouseEventFilter(new MouseEventFilter())
{
@@ -63,23 +63,13 @@ InputHandler::InputHandler()
}
// Called in MainThread
-void InputHandler::setEventSource(QObject *object)
+void InputHandler::registerEventFilters(QEventFilterService *service)
{
- if (object != m_eventSource) {
- if (m_eventSource) {
- m_eventSource->removeEventFilter(m_keyboardEventFilter);
- m_eventSource->removeEventFilter(m_mouseEventFilter);
- }
-
- clearPendingKeyEvents();
- clearPendingMouseEvents();
+ clearPendingKeyEvents();
+ clearPendingMouseEvents();
- m_eventSource = object;
- if (m_eventSource) {
- m_eventSource->installEventFilter(m_keyboardEventFilter);
- m_eventSource->installEventFilter(m_mouseEventFilter);
- }
- }
+ service->registerEventFilter(m_keyboardEventFilter, 512);
+ service->registerEventFilter(m_mouseEventFilter, 512);
}
// Called by the keyboardEventFilter in the main thread
diff --git a/src/input/inputhandler_p.h b/src/input/inputhandler_p.h
index c23ea3894..b6806b5b6 100644
--- a/src/input/inputhandler_p.h
+++ b/src/input/inputhandler_p.h
@@ -56,6 +56,10 @@
QT_BEGIN_NAMESPACE
+namespace Qt3DCore {
+class QEventFilterService;
+}
+
namespace Qt3DInput {
namespace Input {
@@ -71,8 +75,7 @@ class InputHandler
public:
InputHandler();
- void setEventSource(QObject *object);
- inline QObject *eventSource() const { return m_eventSource; }
+ void registerEventFilters(Qt3DCore::QEventFilterService *service);
inline KeyboardControllerManager *keyboardControllerManager() const { return m_keyboardControllerManager; }
inline KeyboardInputManager *keyboardInputManager() const { return m_keyboardInputManager; }
@@ -103,7 +106,6 @@ private:
MouseInputManager *m_mouseInputManager;
QVector<HKeyboardController> m_activeKeyboardControllers;
QVector<HMouseController> m_activeMouseControllers;
- QObject *m_eventSource;
KeyboardEventFilter *m_keyboardEventFilter;
QList<QKeyEvent> m_pendingEvents;
MouseEventFilter *m_mouseEventFilter;
diff --git a/src/input/keyboardeventfilter.cpp b/src/input/keyboardeventfilter.cpp
index 34c4dc580..4f42de7a7 100644
--- a/src/input/keyboardeventfilter.cpp
+++ b/src/input/keyboardeventfilter.cpp
@@ -63,7 +63,7 @@ bool KeyboardEventFilter::eventFilter(QObject *obj, QEvent *e)
// Store event to be processed later on in an InputAspect job
m_inputHandler->appendKeyEvent(QKeyEvent(*static_cast<QKeyEvent *>(e)));
}
- return QObject::eventFilter(obj, e);
+ return false;
}
} // namespace Input
diff --git a/src/input/mouseeventfilter.cpp b/src/input/mouseeventfilter.cpp
index 076ecd8ce..1c52bd46e 100644
--- a/src/input/mouseeventfilter.cpp
+++ b/src/input/mouseeventfilter.cpp
@@ -66,12 +66,11 @@ bool MouseEventFilter::eventFilter(QObject *obj, QEvent *e)
// Store event to be processed later on in an InputAspect job
m_inputHandler->appendMouseEvent(QMouseEvent(*static_cast<QMouseEvent *>(e)));
break;
-
default:
break;
}
- return QObject::eventFilter(obj, e);
+ return false;
}
} // namespace Input
diff --git a/src/input/qinputaspect.cpp b/src/input/qinputaspect.cpp
index 12ad16c1a..f28cc41e1 100644
--- a/src/input/qinputaspect.cpp
+++ b/src/input/qinputaspect.cpp
@@ -49,6 +49,8 @@
#include <Qt3DInput/qkeyboardinput.h>
#include <Qt3DInput/qmousecontroller.h>
#include <Qt3DInput/qmouseinput.h>
+#include <Qt3DCore/qservicelocator.h>
+#include <Qt3DCore/qeventfilterservice.h>
QT_BEGIN_NAMESPACE
@@ -130,16 +132,12 @@ void QInputAspect::setRootEntity(Qt3DCore::QEntity *rootObject)
visitor.traverse(rootObject, this, &QInputAspect::visitNode);
}
-void QInputAspect::onInitialize(const QVariantMap &data)
+void QInputAspect::onInitialize(const QVariantMap &)
{
- QObject *object = Q_NULLPTR;
- const QVariant &v = data.value(QStringLiteral("eventSource"));
- if (v.isValid())
- object = v.value<QObject *>();
Q_D(QInputAspect);
- if (object)
- object->installEventFilter(d->m_cameraController.data());
- d->m_inputHandler->setEventSource(object);
+ Qt3DCore::QEventFilterService *eventService = services()->eventFilterService();
+ eventService->registerEventFilter(d->m_cameraController.data(), 128);
+ d->m_inputHandler->registerEventFilters(eventService);
}
void QInputAspect::onStartup()