summaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kdab.com>2016-01-14 14:25:46 +0200
committerBogDan Vatra <bogdan@kdab.com>2016-01-16 14:15:39 +0000
commit43e55cd54635a5ef1eb09fe9cff701f7eb16cd7a (patch)
tree5b2280d76d6a36bbcb161a4a5fc23c5bdd0aadb4 /src/input
parent8cf683d61c4af3dc2199ea1bede24438b6c042d7 (diff)
Say hello to GenericDevice
GenericDevice can be used to deliver events to Qt3D from any device which is not handled already by Qt3D. What the user need to do is to instantiate a GenericDevice object, set GenericDevice::axesMap and GenericDevice::buttonsMap properties, then use GenericDevice::axisEvent and GenericDevice::buttonEvent signals to deliver the events. [ChangeLog][Input] added GenericDevice Change-Id: Iaef3ff8fabf5002de41d55587ddf1352e6a3e458 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r--src/input/backend/backend.pri6
-rw-r--r--src/input/backend/genericdevicebackendnode.cpp125
-rw-r--r--src/input/backend/genericdevicebackendnode_p.h102
-rw-r--r--src/input/backend/handle_types_p.h2
-rw-r--r--src/input/backend/inputhandler.cpp13
-rw-r--r--src/input/backend/inputhandler_p.h8
-rw-r--r--src/input/backend/inputmanagers_p.h11
-rw-r--r--src/input/backend/keyboardmousegenericdeviceintegration.cpp (renamed from src/input/backend/keyboardmousedeviceintegration.cpp)18
-rw-r--r--src/input/backend/keyboardmousegenericdeviceintegration_p.h (renamed from src/input/backend/keyboardmousedeviceintegration_p.h)12
-rw-r--r--src/input/frontend/frontend.pri2
-rw-r--r--src/input/frontend/qabstractphysicaldevice.cpp65
-rw-r--r--src/input/frontend/qabstractphysicaldevice.h15
-rw-r--r--src/input/frontend/qabstractphysicaldevice_p.h4
-rw-r--r--src/input/frontend/qgenericinputdevice.cpp102
-rw-r--r--src/input/frontend/qgenericinputdevice.h72
-rw-r--r--src/input/frontend/qinputaspect.cpp7
-rw-r--r--src/input/frontend/qinputaspect_p.h4
17 files changed, 540 insertions, 28 deletions
diff --git a/src/input/backend/backend.pri b/src/input/backend/backend.pri
index 4a9ee79d0..ee23ea208 100644
--- a/src/input/backend/backend.pri
+++ b/src/input/backend/backend.pri
@@ -26,7 +26,8 @@ HEADERS += \
$$PWD/axisactionhandler_p.h \
$$PWD/updatehandlerjob_p.h \
$$PWD/axisactionpayload_p.h \
- $$PWD/keyboardmousedeviceintegration_p.h
+ $$PWD/keyboardmousegenericdeviceintegration_p.h \
+ $$PWD/genericdevicebackendnode_p.h
SOURCES += \
$$PWD/cameracontroller.cpp \
@@ -51,6 +52,7 @@ SOURCES += \
$$PWD/updateaxisactionjob.cpp \
$$PWD/axisactionhandler.cpp \
$$PWD/updatehandlerjob.cpp \
- $$PWD/keyboardmousedeviceintegration.cpp
+ $$PWD/keyboardmousegenericdeviceintegration.cpp \
+ $$PWD/genericdevicebackendnode.cpp
INCLUDEPATH += $$PWD
diff --git a/src/input/backend/genericdevicebackendnode.cpp b/src/input/backend/genericdevicebackendnode.cpp
new file mode 100644
index 000000000..85c1f2da1
--- /dev/null
+++ b/src/input/backend/genericdevicebackendnode.cpp
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "genericdevicebackendnode_p.h"
+#include "inputhandler_p.h"
+#include "inputmanagers_p.h"
+
+#include <Qt3DCore/qscenepropertychange.h>
+#include <Qt3DInput/qabstractphysicaldevice.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DInput {
+namespace Input {
+
+GenericDeviceBackendNode::GenericDeviceBackendNode(QBackendNode::Mode mode)
+ : QAbstractPhysicalDeviceBackendNode(mode)
+ , m_mutex(new QMutex)
+{
+}
+
+GenericDeviceBackendNode::~GenericDeviceBackendNode()
+{
+}
+
+void GenericDeviceBackendNode::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+{
+ Qt3DCore::QScenePropertyChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QScenePropertyChange>(e);
+ if (e->type() == Qt3DCore::NodeUpdated) {
+ if (propertyChange->propertyName() == QByteArrayLiteral("axisEvent")) {
+ QPair<int, qreal> val = propertyChange->value().value<QPair<int, qreal>>();
+ QMutexLocker lock(m_mutex.data());
+ m_axesValues[val.first] = val.second;
+ } else if (propertyChange->propertyName() == QByteArrayLiteral("buttonEvent")) {
+ QPair<int, qreal> val = propertyChange->value().value<QPair<int, qreal>>();
+ QMutexLocker lock(m_mutex.data());
+ m_buttonsValues[val.first] = val.second;
+ }
+ }
+}
+
+void GenericDeviceBackendNode::cleanup()
+{
+ QMutexLocker lock(m_mutex.data());
+ m_axesValues.clear();
+ m_buttonsValues.clear();
+ QAbstractPhysicalDeviceBackendNode::cleanup();
+}
+
+float GenericDeviceBackendNode::axisValue(int axisIdentifier) const
+{
+ QMutexLocker lock(m_mutex.data());
+ return m_axesValues[axisIdentifier];
+}
+
+bool GenericDeviceBackendNode::isButtonPressed(int buttonIdentifier) const
+{
+ QMutexLocker lock(m_mutex.data());
+ return m_buttonsValues[buttonIdentifier];
+}
+
+GenericDeviceBackendFunctor::GenericDeviceBackendFunctor(QInputAspect *inputaspect, InputHandler *handler)
+ : m_inputAspect(inputaspect)
+ , m_handler(handler)
+{
+}
+
+Qt3DCore::QBackendNode *GenericDeviceBackendFunctor::create(Qt3DCore::QNode *frontend, const Qt3DCore::QBackendNodeFactory *factory) const
+{
+ GenericDeviceBackendNode *backendNode = m_handler->genericDeviceBackendNodeManager()->getOrCreateResource(frontend->id());
+ backendNode->setFactory(factory);
+ backendNode->setInputAspect(m_inputAspect);
+ backendNode->setPeer(frontend);
+ m_handler->appendGenericDevice(m_handler->genericDeviceBackendNodeManager()->lookupHandle(frontend->id()));
+ return backendNode;
+}
+
+Qt3DCore::QBackendNode *GenericDeviceBackendFunctor::get(const Qt3DCore::QNodeId &id) const
+{
+ return m_handler->genericDeviceBackendNodeManager()->lookupResource(id);
+}
+
+void GenericDeviceBackendFunctor::destroy(const Qt3DCore::QNodeId &id) const
+{
+ m_handler->removeGenericDevice(m_handler->genericDeviceBackendNodeManager()->lookupHandle(id));
+ m_handler->genericDeviceBackendNodeManager()->releaseResource(id);
+}
+
+} // namespace Input
+} // namespace Qt3DInput
+
+QT_END_NAMESPACE
diff --git a/src/input/backend/genericdevicebackendnode_p.h b/src/input/backend/genericdevicebackendnode_p.h
new file mode 100644
index 000000000..52ac913d2
--- /dev/null
+++ b/src/input/backend/genericdevicebackendnode_p.h
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GENERICDEVICEBACKENDNODE_H
+#define GENERICDEVICEBACKENDNODE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <Qt3DInput/qabstractphysicaldevicebackendnode.h>
+#include <QHash>
+#include <QMutex>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DInput {
+
+class QAbstractPhysicalDevice;
+
+namespace Input {
+class InputHandler;
+class GenericDeviceBackendNodeData;
+class GenericDeviceBackendNode : public QAbstractPhysicalDeviceBackendNode
+{
+public:
+ explicit GenericDeviceBackendNode(QBackendNode::Mode mode = QBackendNode::ReadWrite);
+ ~GenericDeviceBackendNode();
+ void updateEvents();
+
+ // QAbstractPhysicalDeviceBackendNode interface
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE;
+ void cleanup() Q_DECL_OVERRIDE;
+ float axisValue(int axisIdentifier) const Q_DECL_OVERRIDE;
+ bool isButtonPressed(int buttonIdentifier) const Q_DECL_OVERRIDE;
+
+private:
+ QHash<int, qreal> m_axesValues;
+ QHash<int, qreal> m_buttonsValues;
+ mutable QSharedPointer<QMutex> m_mutex;
+};
+
+class GenericDeviceBackendFunctor : public Qt3DCore::QBackendNodeFunctor
+{
+public:
+ explicit GenericDeviceBackendFunctor(QInputAspect *inputaspect, InputHandler *handler);
+
+ Qt3DCore::QBackendNode *create(Qt3DCore::QNode *frontend, const Qt3DCore::QBackendNodeFactory *factory) const Q_DECL_OVERRIDE;
+ Qt3DCore::QBackendNode *get(const Qt3DCore::QNodeId &id) const Q_DECL_OVERRIDE;
+ void destroy(const Qt3DCore::QNodeId &id) const Q_DECL_OVERRIDE;
+
+private:
+ QInputAspect *m_inputAspect;
+ InputHandler *m_handler;
+};
+
+} // namespace Input
+} // namespace Qt3DInput
+
+QT_END_NAMESPACE
+
+#endif // GENERICDEVICEBACKENDNODE_H
diff --git a/src/input/backend/handle_types_p.h b/src/input/backend/handle_types_p.h
index 03d8dee3c..77c72289d 100644
--- a/src/input/backend/handle_types_p.h
+++ b/src/input/backend/handle_types_p.h
@@ -66,6 +66,7 @@ class AxisSetting;
class Action;
class ActionInput;
class LogicalDevice;
+class GenericDeviceBackendNode;
typedef Qt3DCore::QHandle<KeyboardController, 8> HKeyboardController;
typedef Qt3DCore::QHandle<KeyboardInput, 16> HKeyboardInput;
@@ -78,6 +79,7 @@ typedef Qt3DCore::QHandle<Action, 16> HAction;
typedef Qt3DCore::QHandle<AxisInput, 16> HAxisInput;
typedef Qt3DCore::QHandle<ActionInput, 16> HActionInput;
typedef Qt3DCore::QHandle<LogicalDevice, 16> HLogicalDevice;
+typedef Qt3DCore::QHandle<GenericDeviceBackendNode, 8> HGenericDeviceBackendNode;
} // namespace Input
} // namespace Qt3DInput
diff --git a/src/input/backend/inputhandler.cpp b/src/input/backend/inputhandler.cpp
index f81015dfe..ea3fbf9f6 100644
--- a/src/input/backend/inputhandler.cpp
+++ b/src/input/backend/inputhandler.cpp
@@ -64,6 +64,7 @@ InputHandler::InputHandler()
, m_axisSettingManager(new AxisSettingManager())
, m_actionInputManager(new ActionInputManager())
, m_logicalDeviceManager(new LogicalDeviceManager())
+ , m_genericPhysicalDeviceBackendNodeManager(new GenericDeviceBackendNodeManager)
{
m_keyboardEventFilter->setInputHandler(this);
m_mouseEventFilter->setInputHandler(this);
@@ -142,6 +143,16 @@ void InputHandler::removeMouseController(HMouseController controller)
m_activeMouseControllers.removeAll(controller);
}
+void Qt3DInput::Input::InputHandler::appendGenericDevice(HGenericDeviceBackendNode device)
+{
+ m_activeGenericPhysicalDevices.append(device);
+}
+
+void Qt3DInput::Input::InputHandler::removeGenericDevice(HGenericDeviceBackendNode device)
+{
+ m_activeGenericPhysicalDevices.removeAll(device);
+}
+
// Return a vector of jobs to be performed for keyboard events
// Handles all dependencies between jobs
QVector<Qt3DCore::QAspectJobPtr> InputHandler::keyboardJobs()
@@ -152,8 +163,8 @@ QVector<Qt3DCore::QAspectJobPtr> InputHandler::keyboardJobs()
Q_FOREACH (const HKeyboardController cHandle, m_activeKeyboardControllers) {
KeyboardController *controller = m_keyboardControllerManager->data(cHandle);
- controller->updateKeyEvents(events);
if (controller) {
+ controller->updateKeyEvents(events);
QAspectJobPtr focusChangeJob;
if (controller->lastKeyboardInputRequester() != controller->currentFocusItem()) {
AssignKeyboardFocusJob *job = new AssignKeyboardFocusJob(controller->peerUuid());
diff --git a/src/input/backend/inputhandler_p.h b/src/input/backend/inputhandler_p.h
index e08e916e7..6c55614d0 100644
--- a/src/input/backend/inputhandler_p.h
+++ b/src/input/backend/inputhandler_p.h
@@ -79,6 +79,8 @@ class AxisInputManager;
class AxisSettingManager;
class ActionInputManager;
class LogicalDeviceManager;
+class GenericPhysicalDeviceManager;
+class GenericDeviceBackendNodeManager;
class InputHandler
{
@@ -98,6 +100,7 @@ public:
inline AxisSettingManager *axisSettingManager() const { return m_axisSettingManager; }
inline ActionInputManager *actionInputManager() const { return m_actionInputManager; }
inline LogicalDeviceManager *logicalDeviceManager() const { return m_logicalDeviceManager; }
+ inline GenericDeviceBackendNodeManager *genericDeviceBackendNodeManager() const { return m_genericPhysicalDeviceBackendNodeManager; }
void appendKeyEvent(const QT_PREPEND_NAMESPACE(QKeyEvent) &event);
QList<QT_PREPEND_NAMESPACE(QKeyEvent)> pendingKeyEvents();
@@ -113,6 +116,9 @@ public:
void appendMouseController(HMouseController controller);
void removeMouseController(HMouseController controller);
+ void appendGenericDevice(HGenericDeviceBackendNode device);
+ void removeGenericDevice(HGenericDeviceBackendNode device);
+
QVector<Qt3DCore::QAspectJobPtr> keyboardJobs();
QVector<Qt3DCore::QAspectJobPtr> mouseJobs();
@@ -127,6 +133,7 @@ private:
QVector<HKeyboardController> m_activeKeyboardControllers;
QVector<HMouseController> m_activeMouseControllers;
+ QVector<HGenericDeviceBackendNode> m_activeGenericPhysicalDevices;
KeyboardEventFilter *m_keyboardEventFilter;
QList<QT_PREPEND_NAMESPACE(QKeyEvent)> m_pendingEvents;
MouseEventFilter *m_mouseEventFilter;
@@ -140,6 +147,7 @@ private:
AxisSettingManager *m_axisSettingManager;
ActionInputManager *m_actionInputManager;
LogicalDeviceManager *m_logicalDeviceManager;
+ GenericDeviceBackendNodeManager *m_genericPhysicalDeviceBackendNodeManager;
QVector<Qt3DInput::QInputDeviceIntegration *> m_inputDeviceIntegrations;
};
diff --git a/src/input/backend/inputmanagers_p.h b/src/input/backend/inputmanagers_p.h
index eb7cc8800..f6c5408c2 100644
--- a/src/input/backend/inputmanagers_p.h
+++ b/src/input/backend/inputmanagers_p.h
@@ -62,6 +62,7 @@
#include <Qt3DInput/private/axisactionhandler_p.h>
#include <Qt3DInput/private/axissetting_p.h>
#include <Qt3DInput/private/logicaldevice_p.h>
+#include <Qt3DInput/private/genericdevicebackendnode_p.h>
QT_BEGIN_NAMESPACE
@@ -192,6 +193,16 @@ private:
QVector<HLogicalDevice> m_activeDevices;
};
+class GenericDeviceBackendNodeManager : public Qt3DCore::QResourceManager<
+ GenericDeviceBackendNode,
+ Qt3DCore::QNodeId,
+ 8,
+ Qt3DCore::ArrayAllocatingPolicy>
+{
+public:
+ GenericDeviceBackendNodeManager() {}
+};
+
} // namespace Input
} // namespace Qt3DInput
diff --git a/src/input/backend/keyboardmousedeviceintegration.cpp b/src/input/backend/keyboardmousegenericdeviceintegration.cpp
index f7cc02bf5..3a22be92e 100644
--- a/src/input/backend/keyboardmousedeviceintegration.cpp
+++ b/src/input/backend/keyboardmousegenericdeviceintegration.cpp
@@ -34,7 +34,7 @@
**
****************************************************************************/
-#include "keyboardmousedeviceintegration_p.h"
+#include "keyboardmousegenericdeviceintegration_p.h"
#include <Qt3DInput/private/inputhandler_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
@@ -44,43 +44,45 @@ namespace Qt3DInput {
namespace Input {
-KeyboardMouseDeviceIntegration::KeyboardMouseDeviceIntegration(InputHandler *handler)
+KeyboardMouseGenericDeviceIntegration::KeyboardMouseGenericDeviceIntegration(InputHandler *handler)
: Qt3DInput::QInputDeviceIntegration()
, m_handler(handler)
{
}
-KeyboardMouseDeviceIntegration::~KeyboardMouseDeviceIntegration()
+KeyboardMouseGenericDeviceIntegration::~KeyboardMouseGenericDeviceIntegration()
{
}
-void KeyboardMouseDeviceIntegration::onInitialize()
+void KeyboardMouseGenericDeviceIntegration::onInitialize()
{
}
-QVector<Qt3DCore::QAspectJobPtr> KeyboardMouseDeviceIntegration::jobsToExecute(qint64 time)
+QVector<Qt3DCore::QAspectJobPtr> KeyboardMouseGenericDeviceIntegration::jobsToExecute(qint64 time)
{
Q_UNUSED(time)
return QVector<Qt3DCore::QAspectJobPtr>();
}
-QAbstractPhysicalDevice *KeyboardMouseDeviceIntegration::createPhysicalDevice(const QString &name)
+QAbstractPhysicalDevice *KeyboardMouseGenericDeviceIntegration::createPhysicalDevice(const QString &name)
{
Q_UNUSED(name)
return Q_NULLPTR;
}
-QVector<Qt3DCore::QNodeId> KeyboardMouseDeviceIntegration::physicalDevices() const
+QVector<Qt3DCore::QNodeId> KeyboardMouseGenericDeviceIntegration::physicalDevices() const
{
// TO DO: could return the ids of active KeyboardController/MouseController
return QVector<Qt3DCore::QNodeId>();
}
-QAbstractPhysicalDeviceBackendNode *KeyboardMouseDeviceIntegration::physicalDevice(Qt3DCore::QNodeId id) const
+QAbstractPhysicalDeviceBackendNode *KeyboardMouseGenericDeviceIntegration::physicalDevice(Qt3DCore::QNodeId id) const
{
QAbstractPhysicalDeviceBackendNode *device = m_handler->keyboardControllerManager()->lookupResource(id);
if (!device)
device = m_handler->mouseControllerManager()->lookupResource(id);
+ if (!device)
+ device = m_handler->genericDeviceBackendNodeManager()->lookupResource(id);
return device;
}
diff --git a/src/input/backend/keyboardmousedeviceintegration_p.h b/src/input/backend/keyboardmousegenericdeviceintegration_p.h
index 5cbbcd9d5..648abb02a 100644
--- a/src/input/backend/keyboardmousedeviceintegration_p.h
+++ b/src/input/backend/keyboardmousegenericdeviceintegration_p.h
@@ -34,8 +34,8 @@
**
****************************************************************************/
-#ifndef QT3DINPUT_INPUT_KEYBOARDMOUSEDEVICEINTEGRATION_P_H
-#define QT3DINPUT_INPUT_KEYBOARDMOUSEDEVICEINTEGRATION_P_H
+#ifndef QT3DINPUT_INPUT_KEYBOARDMOUSEGENERICDEVICEINTEGRATION_P_H
+#define QT3DINPUT_INPUT_KEYBOARDMOUSEGENERICDEVICEINTEGRATION_P_H
//
// W A R N I N G
@@ -58,12 +58,12 @@ namespace Input {
class InputHandler;
-class KeyboardMouseDeviceIntegration : public Qt3DInput::QInputDeviceIntegration
+class KeyboardMouseGenericDeviceIntegration : public Qt3DInput::QInputDeviceIntegration
{
Q_OBJECT
public:
- explicit KeyboardMouseDeviceIntegration(InputHandler *handleer);
- ~KeyboardMouseDeviceIntegration();
+ explicit KeyboardMouseGenericDeviceIntegration(InputHandler *handleer);
+ ~KeyboardMouseGenericDeviceIntegration();
QVector<Qt3DCore::QAspectJobPtr> jobsToExecute(qint64 time) Q_DECL_FINAL;
QAbstractPhysicalDevice *createPhysicalDevice(const QString &name) Q_DECL_FINAL;
@@ -82,4 +82,4 @@ private:
QT_END_NAMESPACE
-#endif // QT3DINPUT_INPUT_KEYBOARDMOUSEDEVICEINTEGRATION_P_H
+#endif // QT3DINPUT_INPUT_KEYBOARDMOUSEGENERICDEVICEINTEGRATION_P_H
diff --git a/src/input/frontend/frontend.pri b/src/input/frontend/frontend.pri
index 3860716c1..4c9a016d7 100644
--- a/src/input/frontend/frontend.pri
+++ b/src/input/frontend/frontend.pri
@@ -25,6 +25,7 @@ HEADERS += \
$$PWD/qabstractphysicaldevice_p.h \
$$PWD/qaxisactionhandler_p.h \
$$PWD/qaxisactionhandler.h \
+ $$PWD/qgenericinputdevice.h \
$$PWD/qabstractactioninput.h \
$$PWD/qabstractaggregateactioninput.h \
$$PWD/qinputchord.h \
@@ -50,6 +51,7 @@ SOURCES += \
$$PWD/qinputdeviceintegrationfactory.cpp \
$$PWD/qaxissetting.cpp \
$$PWD/qaxisactionhandler.cpp \
+ $$PWD/qgenericinputdevice.cpp \
$$PWD/qabstractactioninput.cpp \
$$PWD/qabstractaggregateactioninput.cpp \
$$PWD/qinputchord.cpp \
diff --git a/src/input/frontend/qabstractphysicaldevice.cpp b/src/input/frontend/qabstractphysicaldevice.cpp
index 61236e215..fffbd4538 100644
--- a/src/input/frontend/qabstractphysicaldevice.cpp
+++ b/src/input/frontend/qabstractphysicaldevice.cpp
@@ -36,6 +36,7 @@
#include "qabstractphysicaldevice.h"
#include "qabstractphysicaldevice_p.h"
+#include <Qt3DCore/qscenepropertychange.h>
#include <Qt3DCore/private/qnode_p.h>
QT_BEGIN_NAMESPACE
@@ -62,6 +63,48 @@ QAbstractPhysicalDevice::~QAbstractPhysicalDevice()
Q_ASSERT_X(Qt3DCore::QNodePrivate::get(this)->m_wasCleanedUp, Q_FUNC_INFO, "QNode::cleanup should have been called by now. A Qt3DInput::QAbstractPhysicalDevice subclass didn't call QNode::cleanup in its destructor");
}
+int QAbstractPhysicalDevice::axisCount() const
+{
+ Q_D(const QAbstractPhysicalDevice);
+ return d->m_axesHash.size();
+}
+
+int QAbstractPhysicalDevice::buttonCount() const
+{
+ Q_D(const QAbstractPhysicalDevice);
+ return d->m_buttonsHash.size();
+}
+
+QStringList QAbstractPhysicalDevice::axisNames() const
+{
+ Q_D(const QAbstractPhysicalDevice);
+ return d->m_axesHash.keys();
+}
+
+QStringList QAbstractPhysicalDevice::buttonNames() const
+{
+ Q_D(const QAbstractPhysicalDevice);
+ return d->m_buttonsHash.keys();
+}
+
+int QAbstractPhysicalDevice::axisIdentifier(const QString &name) const
+{
+ Q_D(const QAbstractPhysicalDevice);
+ auto it = d->m_axesHash.find(name);
+ if (it != d->m_axesHash.end())
+ return *it;
+ return -1;
+}
+
+int QAbstractPhysicalDevice::buttonIdentifier(const QString &name) const
+{
+ Q_D(const QAbstractPhysicalDevice);
+ auto it = d->m_buttonsHash.find(name);
+ if (it != d->m_buttonsHash.end())
+ return *it;
+ return -1;
+}
+
void QAbstractPhysicalDevice::addAxisSetting(QAxisSetting *axisSetting)
{
Q_D(QAbstractPhysicalDevice);
@@ -82,11 +125,31 @@ QVector<QAxisSetting *> QAbstractPhysicalDevice::axisSettings() const
return d->m_axisSettings;
}
+void QAbstractPhysicalDevice::postAxisEvent(int axis, qreal value)
+{
+ Q_D(QAbstractPhysicalDevice);
+ Qt3DCore::QScenePropertyChangePtr change(new Qt3DCore::QScenePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, id()));
+ change->setPropertyName("axisEvent");
+ change->setValue(QVariant::fromValue(QPair<int, qreal>(axis, value)));
+ d->notifyObservers(change);
+}
+
+void QAbstractPhysicalDevice::postButtonEvent(int button, qreal value)
+{
+ Q_D(QAbstractPhysicalDevice);
+ Qt3DCore::QScenePropertyChangePtr change(new Qt3DCore::QScenePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, id()));
+ change->setPropertyName("buttonEvent");
+ change->setValue(QVariant::fromValue(QPair<int, qreal>(button, value)));
+ d->notifyObservers(change);
+}
+
void QAbstractPhysicalDevice::copy(const QNode *ref)
{
QNode::copy(ref);
const QAbstractPhysicalDevice *physicalDevice = static_cast<const QAbstractPhysicalDevice *>(ref);
- d_func()->m_axisSettings = physicalDevice->axisSettings();
+ d_func()->m_axisSettings = physicalDevice->d_func()->m_axisSettings;
+ d_func()->m_axesHash = physicalDevice->d_func()->m_axesHash;
+ d_func()->m_buttonsHash = physicalDevice->d_func()->m_buttonsHash;
}
}
diff --git a/src/input/frontend/qabstractphysicaldevice.h b/src/input/frontend/qabstractphysicaldevice.h
index 8056a195b..163f48f9c 100644
--- a/src/input/frontend/qabstractphysicaldevice.h
+++ b/src/input/frontend/qabstractphysicaldevice.h
@@ -57,18 +57,21 @@ public:
explicit QAbstractPhysicalDevice(Qt3DCore::QNode *parent = 0);
~QAbstractPhysicalDevice();
- virtual int axisCount() const = 0;
- virtual int buttonCount() const = 0;
- virtual QStringList axisNames() const = 0;
- virtual QStringList buttonNames() const = 0;
+ virtual int axisCount() const;
+ virtual int buttonCount() const;
+ virtual QStringList axisNames() const;
+ virtual QStringList buttonNames() const;
- virtual int axisIdentifier(const QString &name) const = 0;
- virtual int buttonIdentifier(const QString &name) const = 0;
+ virtual int axisIdentifier(const QString &name) const;
+ virtual int buttonIdentifier(const QString &name) const;
void addAxisSetting(QAxisSetting *axisSetting);
void removeAxisSetting(QAxisSetting *axisSetting);
QVector<QAxisSetting *> axisSettings() const;
+ Q_INVOKABLE void postAxisEvent(int axis, qreal value);
+ Q_INVOKABLE void postButtonEvent(int button, qreal value);
+
protected:
QAbstractPhysicalDevice(QAbstractPhysicalDevicePrivate &dd, Qt3DCore::QNode *parent = 0);
Q_DECLARE_PRIVATE(QAbstractPhysicalDevice)
diff --git a/src/input/frontend/qabstractphysicaldevice_p.h b/src/input/frontend/qabstractphysicaldevice_p.h
index 6900fc54a..1e890b46a 100644
--- a/src/input/frontend/qabstractphysicaldevice_p.h
+++ b/src/input/frontend/qabstractphysicaldevice_p.h
@@ -50,6 +50,8 @@
#include <Qt3DInput/qt3dinput_global.h>
#include <Qt3DCore/private/qnode_p.h>
+#include <QtCore/qhash.h>
+#include <QtCore/qmutex.h>
#include <QtCore/qvector.h>
#include <Qt3DInput/private/qt3dinput_global_p.h>
@@ -66,6 +68,8 @@ public:
Q_DECLARE_PUBLIC(QAbstractPhysicalDevice)
QVector<QAxisSetting *> m_axisSettings;
+ QHash<QString, int> m_axesHash;
+ QHash<QString, int> m_buttonsHash;
};
}
diff --git a/src/input/frontend/qgenericinputdevice.cpp b/src/input/frontend/qgenericinputdevice.cpp
new file mode 100644
index 000000000..b76cc40cc
--- /dev/null
+++ b/src/input/frontend/qgenericinputdevice.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgenericinputdevice.h"
+
+#include "qabstractphysicaldevice_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DInput {
+
+
+QGenericInputDevice::QGenericInputDevice(Qt3DCore::QNode *parent)
+ : QAbstractPhysicalDevice(parent)
+{}
+
+QGenericInputDevice::~QGenericInputDevice()
+{
+ QAbstractPhysicalDevice::cleanup();
+}
+
+static void setHashFromVariantMap(QHash<QString, int> &hash, const QVariantMap &map)
+{
+ hash.clear();
+ for (QVariantMap::const_iterator it = map.cbegin(); it != map.cend(); ++it) {
+ bool ok;
+ int value = it.value().toInt(&ok);
+ if (ok)
+ hash[it.key()] = value;
+ }
+}
+
+static QVariantMap hash2VariantMap(const QHash<QString, int> &hash)
+{
+ QVariantMap ret;
+ for (QHash<QString, int>::const_iterator it = hash.cbegin(); it != hash.cend(); ++it)
+ ret[it.key()] = it.value();
+ return ret;
+}
+
+QVariantMap QGenericInputDevice::axesMap() const
+{
+ Q_D(const QAbstractPhysicalDevice);
+ return hash2VariantMap(d->m_axesHash);
+}
+
+void QGenericInputDevice::setAxesMap(const QVariantMap &axesMap)
+{
+ Q_D(QAbstractPhysicalDevice);
+ setHashFromVariantMap(d->m_axesHash, axesMap);
+ emit axesMapChanged();
+}
+
+QVariantMap QGenericInputDevice::buttonsMap() const
+{
+ Q_D(const QAbstractPhysicalDevice);
+ return hash2VariantMap(d->m_buttonsHash);
+}
+
+void QGenericInputDevice::setButtonsMap(const QVariantMap &buttonsMap)
+{
+ Q_D(QAbstractPhysicalDevice);
+ setHashFromVariantMap(d->m_buttonsHash, buttonsMap);
+ emit axesMapChanged();
+}
+
+} // Qt3DInput
+
+QT_END_NAMESPACE
diff --git a/src/input/frontend/qgenericinputdevice.h b/src/input/frontend/qgenericinputdevice.h
new file mode 100644
index 000000000..93c3a1043
--- /dev/null
+++ b/src/input/frontend/qgenericinputdevice.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GENERICDEVICE_H
+#define GENERICDEVICE_H
+
+#include <Qt3DInput/qabstractphysicaldevice.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DInput {
+
+class QT3DINPUTSHARED_EXPORT QGenericInputDevice : public QAbstractPhysicalDevice
+{
+ Q_OBJECT
+ Q_PROPERTY(QVariantMap axesMap READ axesMap WRITE setAxesMap NOTIFY axesMapChanged)
+ Q_PROPERTY(QVariantMap buttonsMap READ buttonsMap WRITE setButtonsMap NOTIFY buttonsMapChanged)
+public:
+ QGenericInputDevice(Qt3DCore::QNode *parent = Q_NULLPTR);
+ ~QGenericInputDevice();
+
+ QVariantMap axesMap() const;
+ void setAxesMap(const QVariantMap &axesMap);
+ QVariantMap buttonsMap() const;
+ void setButtonsMap(const QVariantMap &buttonsMap);
+
+Q_SIGNALS:
+ void axesMapChanged();
+ void buttonsMapChanged();
+
+protected:
+ QT3D_CLONEABLE(QGenericInputDevice)
+};
+
+} // Qt3DInput
+
+QT_END_NAMESPACE
+
+#endif // GENERICDEVICE_H
diff --git a/src/input/frontend/qinputaspect.cpp b/src/input/frontend/qinputaspect.cpp
index 46e6615e7..4c6c9d340 100644
--- a/src/input/frontend/qinputaspect.cpp
+++ b/src/input/frontend/qinputaspect.cpp
@@ -47,6 +47,7 @@
#include <Qt3DInput/qmousecontroller.h>
#include <Qt3DInput/qmouseinput.h>
#include <Qt3DInput/qinputdeviceintegration.h>
+#include <Qt3DInput/qgenericinputdevice.h>
#include <Qt3DInput/private/qinputdeviceintegrationfactory_p.h>
#include <Qt3DCore/private/qservicelocator_p.h>
#include <Qt3DCore/private/qeventfilterservice_p.h>
@@ -74,7 +75,8 @@
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/updateaxisactionjob_p.h>
#include <Qt3DInput/private/updatehandlerjob_p.h>
-#include <Qt3DInput/private/keyboardmousedeviceintegration_p.h>
+#include <Qt3DInput/private/keyboardmousegenericdeviceintegration_p.h>
+#include <Qt3DInput/private/genericdevicebackendnode_p.h>
QT_BEGIN_NAMESPACE
@@ -90,7 +92,7 @@ QInputAspectPrivate::QInputAspectPrivate()
: QAbstractAspectPrivate()
, m_inputHandler(new Input::InputHandler())
, m_cameraController(new Input::CameraController())
- , m_keyboardMouseIntegration(new Input::KeyboardMouseDeviceIntegration(m_inputHandler.data()))
+ , m_keyboardMouseIntegration(new Input::KeyboardMouseGenericDeviceIntegration(m_inputHandler.data()))
{
}
@@ -114,6 +116,7 @@ QInputAspect::QInputAspect(QObject *parent)
registerBackendType<QActionInput>(QBackendNodeFunctorPtr(new Input::InputNodeFunctor<Input::ActionInput, Input::ActionInputManager>(d_func()->m_inputHandler->actionInputManager())));
registerBackendType<Qt3DInput::QAxisActionHandler>(QBackendNodeFunctorPtr(new Input::AxisActionHandlerNodeFunctor(d_func()->m_inputHandler->axisActionHandlerManager())));
registerBackendType<QLogicalDevice>(QBackendNodeFunctorPtr(new Input::LogicalDeviceNodeFunctor(d_func()->m_inputHandler->logicalDeviceManager())));
+ registerBackendType<QGenericInputDevice>(QBackendNodeFunctorPtr(new Input::GenericDeviceBackendFunctor(this, d_func()->m_inputHandler.data())));
// Plugins are QInputDeviceIntegration instances
loadInputDevicePlugins();
diff --git a/src/input/frontend/qinputaspect_p.h b/src/input/frontend/qinputaspect_p.h
index e4adfad0a..4a21cb253 100644
--- a/src/input/frontend/qinputaspect_p.h
+++ b/src/input/frontend/qinputaspect_p.h
@@ -59,7 +59,7 @@ class QInputAspect;
namespace Input {
class CameraController;
class InputHandler;
-class KeyboardMouseDeviceIntegration;
+class KeyboardMouseGenericDeviceIntegration;
}
class QInputAspectPrivate : public Qt3DCore::QAbstractAspectPrivate
@@ -70,7 +70,7 @@ public:
Q_DECLARE_PUBLIC(QInputAspect)
QScopedPointer<Input::InputHandler> m_inputHandler;
QScopedPointer<Input::CameraController> m_cameraController;
- QScopedPointer<Input::KeyboardMouseDeviceIntegration> m_keyboardMouseIntegration;
+ QScopedPointer<Input::KeyboardMouseGenericDeviceIntegration> m_keyboardMouseIntegration;
};
} // namespace Qt3DInput