summaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorRĂ©mi Benoit <remi.benoit@kdab.com>2015-02-11 18:40:44 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-08-03 14:43:58 +0000
commit5be0ec8da8a63d75b0dd9c70119fc01e908f8618 (patch)
tree8b7f7f3fb44f7438fc61ff64f2331f745e2d9933 /src/input
parent01a380405e05ad18251ec6635c096392c89633a7 (diff)
MouseInput API and example mockup
The meaning of exclusiveFocus is not set in stone for now. We know some kind of exclusive focus will be needed but defining it precisely will be done as the input aspect takes shape. QMouseController -> dispatch events to QMouseInput, specify the camera to be used to perform the picks. QMouseInput -> Component that offers a way to react to mouse events Q3DMouseEvent/Q3DWheelEvent -> Qt3D mapping of QMouseEvent/QWheelEvent Change-Id: I462bea2932d4bad6595d04a75ea1e0a67c7c8ba0 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r--src/input/input.pri12
-rw-r--r--src/input/q3dmouseevent.cpp261
-rw-r--r--src/input/q3dmouseevent.h156
-rw-r--r--src/input/qmousecontroller.cpp79
-rw-r--r--src/input/qmousecontroller.h72
-rw-r--r--src/input/qmousecontroller_p.h61
-rw-r--r--src/input/qmouseinput.cpp176
-rw-r--r--src/input/qmouseinput.h98
-rw-r--r--src/input/qmouseinput_p.h65
9 files changed, 978 insertions, 2 deletions
diff --git a/src/input/input.pri b/src/input/input.pri
index e83bc69f5..fef8289d0 100644
--- a/src/input/input.pri
+++ b/src/input/input.pri
@@ -14,7 +14,12 @@ HEADERS += \
$$PWD/keyboardeventfilter_p.h \
$$PWD/assignkeyboardfocusjob_p.h \
$$PWD/keyeventdispatcherjob_p.h \
- $$PWD/q3dkeyevent.h
+ $$PWD/q3dkeyevent.h \
+ $$PWD/qmousecontroller.h \
+ $$PWD/qmouseinput.h \
+ $$PWD/qmouseinput_p.h \
+ $$PWD/qmousecontroller_p.h \
+ $$PWD/q3dmouseevent.h
SOURCES += \
$$PWD/cameracontroller.cpp \
@@ -27,6 +32,9 @@ SOURCES += \
$$PWD/keyboardeventfilter.cpp \
$$PWD/assignkeyboardfocusjob.cpp \
$$PWD/keyeventdispatcherjob.cpp \
- $$PWD/q3dkeyevent.cpp
+ $$PWD/q3dkeyevent.cpp \
+ $$PWD/qmouseinput.cpp \
+ $$PWD/qmousecontroller.cpp \
+ $$PWD/q3dmouseevent.cpp
INCLUDEPATH += $$PWD
diff --git a/src/input/q3dmouseevent.cpp b/src/input/q3dmouseevent.cpp
new file mode 100644
index 000000000..e1adfd803
--- /dev/null
+++ b/src/input/q3dmouseevent.cpp
@@ -0,0 +1,261 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 "q3dmouseevent.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+// Notes:
+// Maybe we should provide the world pos of the intersection
+// The distance t along the segment line at which the intersection occurs
+// Screen Pos / Mouse Pos / Viewport Pos
+// The intersection Ray
+// These can always be added in follow up commits once the input API takes shape
+
+/*!
+ * \class Qt3D::Q3DMouseEvent
+ *
+ * \brief The Qt3D::Q3DMouseEvent contains parameters that describe a mouse event.
+ *
+ * Mouse events occur when a mouse button is pressed and the ray
+ * traversing the view, originating from the mouse position intersects with one
+ * or more elements of the scene.
+ *
+ * \since 5.5
+ *
+ * \sa Qt3D::Q3DKeyEvent, Qt3D::Q3DWheelEvent, Qt3D::QMouseInput
+ *
+ */
+
+/*!
+ * \fn int Qt3D::Q3DMouseEvent::x() const
+ *
+ * Returns the x position of the mouse event.
+ */
+
+/*!
+ * \fn int Qt3D::Q3DMouseEvent::y() const
+ *
+ * Returns the y position of the mouse event.
+ */
+
+/*!
+ * \fn bool Qt3D::Q3DMouseEvent::isAccepted() const
+ *
+ * Returns whether the event was accepted.
+ */
+
+/*!
+ * \fn void Qt3D::Q3DMouseEvent::setAccepted(bool accepted)
+ *
+ * Sets the event as accepted if \a accepted is true.
+ *
+ * \note When an event is accepted, it will prevent further propagation to other
+ * listeners.
+ */
+
+/*!
+ * \fn QEvent::Type Qt3D::Q3DMouseEvent::type() const
+ *
+ * Returns the QEvent::Type of the event.
+ */
+
+/*!
+ * Constructs a new Qt3D::Q3DMouseEvent instance for the QMouseEvent \a e.
+ */
+Q3DMouseEvent::Q3DMouseEvent(const QMouseEvent &e)
+ : QObject()
+ , m_event(e)
+{
+}
+
+Q3DMouseEvent::~Q3DMouseEvent()
+{
+}
+
+/*!
+ * Returns the mouse button of the mouse event.
+ */
+Q3DMouseEvent::Buttons Q3DMouseEvent::button() const
+{
+ switch (m_event.button()) {
+ case Qt::MouseButton::LeftButton:
+ return Q3DMouseEvent::Buttons::LeftButton;
+ case Qt::MouseButton::RightButton:
+ return Q3DMouseEvent::Buttons::RightButton;
+ case Qt::MouseButton::MiddleButton:
+ return Q3DMouseEvent::Buttons::MiddleButton;
+ case Qt::MouseButton::BackButton:
+ return Q3DMouseEvent::Buttons::BackButton;
+ default:
+ return Q3DMouseEvent::Buttons::NoButton;
+ }
+}
+
+/*!
+ * Returns a bitfield to be used to check for mouse buttons that may be
+ * accompanying the mouse event.
+ */
+int Q3DMouseEvent::buttons() const
+{
+ return m_event.buttons();
+}
+
+/*!
+ * Returns the keyboard modifier that may be accompanying the mouse event.
+ */
+Q3DMouseEvent::Modifiers Q3DMouseEvent::modifier() const
+{
+ switch (m_event.modifiers()) {
+ case Qt::ShiftModifier:
+ return Q3DMouseEvent::Modifiers::ShiftModifier;
+ case Qt::ControlModifier:
+ return Q3DMouseEvent::Modifiers::ControlModifier;
+ case Qt::AltModifier:
+ return Q3DMouseEvent::Modifiers::AltModifier;
+ case Qt::MetaModifier:
+ return Q3DMouseEvent::Modifiers::MetaModifier;
+ case Qt::KeypadModifier:
+ return Q3DMouseEvent::Modifiers::KeypadModifier;
+ default:
+ return Q3DMouseEvent::Modifiers::NoModifier;
+ }
+}
+
+
+/*!
+ * \class Qt3D::Q3DWheelEvent
+ *
+ * \brief The Qt3D::Q3DWheelEvent contains parameters that describe a mouse wheel event.
+ *
+ * Mouse wheel events occur when the mouse is rotated.
+ *
+ * \since 5.5
+ *
+ * \sa Qt3D::Q3DKeyEvent, Qt3D::Q3DMouseEvent, Qt3D::QMouseInput
+ *
+ */
+
+/*!
+ * \fn int Qt3D::Q3DWheelEvent::x() const
+ *
+ * Returns the x position of the mouse event.
+ */
+
+/*!
+ * \fn int Qt3D::Q3DWheelEvent::y() const
+ *
+ * Returns the x position of the mouse event.
+ */
+
+/*!
+ * \fn QPoint Qt3D::Q3DWheelEvent::angleDelta() const
+ *
+ * Returns the distance that the wheel is rotated, in eighths of a degree. A
+ * positive value indicates that the wheel was rotated forward (away from the
+ * user), a negative value indicates the wheel was rotated backward (toward the
+ * user).
+ */
+
+/*!
+ * \fn bool Qt3D::Q3DWheelEvent::isAccepted() const
+ *
+ * Returns whether the event was accepted.
+ */
+
+/*!
+ * \fn void Qt3D::Q3DWheelEvent::setAccepted(bool accepted)
+ *
+ * Sets the event as accepted if \a accepted is true.
+ *
+ * \note When an event is accepted, it will prevent further propagation to other
+ * listeners.
+ */
+
+/*!
+ * \fn QEvent::Type Qt3D::Q3DWheelEvent::type() const
+ *
+ * Returns the QEvent::Type of the event.
+ */
+
+/*!
+ * Constructs a new Qt3D::Q3DWheelEvent instance from the QWheelEvent \a e.
+ */
+Q3DWheelEvent::Q3DWheelEvent(const QWheelEvent &e)
+ : QObject()
+ , m_event(e)
+{
+}
+
+Q3DWheelEvent::~Q3DWheelEvent()
+{
+}
+
+/*!
+ * Returns a bitfield to be used to check for mouse buttons that may be
+ * accompanying the wheel event.
+ */
+int Q3DWheelEvent::buttons() const
+{
+ return m_event.buttons();
+}
+
+/*!
+ * Returns the keyboard modifier that may be accompanying the wheel event.
+ */
+Q3DWheelEvent::Modifiers Q3DWheelEvent::modifier() const
+{
+ switch (m_event.modifiers()) {
+ case Qt::ShiftModifier:
+ return Q3DWheelEvent::Modifiers::ShiftModifier;
+ case Qt::ControlModifier:
+ return Q3DWheelEvent::Modifiers::ControlModifier;
+ case Qt::AltModifier:
+ return Q3DWheelEvent::Modifiers::AltModifier;
+ case Qt::MetaModifier:
+ return Q3DWheelEvent::Modifiers::MetaModifier;
+ case Qt::KeypadModifier:
+ return Q3DWheelEvent::Modifiers::KeypadModifier;
+ default:
+ return Q3DWheelEvent::Modifiers::NoModifier;
+ }
+}
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/input/q3dmouseevent.h b/src/input/q3dmouseevent.h
new file mode 100644
index 000000000..517d016b8
--- /dev/null
+++ b/src/input/q3dmouseevent.h
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 QT3D_Q3DMOUSEEVENT_H
+#define QT3D_Q3DMOUSEEVENT_H
+
+#include <Qt3DInput/qt3dinput_global.h>
+#include <QObject>
+#include <QMouseEvent>
+#include <QtGlobal>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QT3DINPUTSHARED_EXPORT Q3DMouseEvent : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int x READ x CONSTANT)
+ Q_PROPERTY(int y READ y CONSTANT)
+ Q_PROPERTY(bool wasHeld READ wasHeld CONSTANT)
+ Q_PROPERTY(Qt3D::Q3DMouseEvent::Buttons button READ button CONSTANT)
+ Q_PROPERTY(int buttons READ buttons CONSTANT)
+ Q_PROPERTY(Qt3D::Q3DMouseEvent::Modifiers modifier READ modifier CONSTANT)
+ Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
+
+public:
+ enum Buttons {
+ LeftButton = Qt::MouseButton::LeftButton,
+ RightButton = Qt::MouseButton::RightButton,
+ MiddleButton = Qt::MouseButton::MiddleButton,
+ BackButton = Qt::MouseButton::BackButton,
+ NoButton = Qt::MouseButton::NoButton
+ };
+ Q_ENUM(Buttons)
+
+ enum Modifiers {
+ NoModifier = Qt::NoModifier,
+ ShiftModifier = Qt::ShiftModifier,
+ ControlModifier = Qt::ControlModifier,
+ AltModifier = Qt::AltModifier,
+ MetaModifier = Qt::MetaModifier,
+ KeypadModifier = Qt::KeypadModifier
+ };
+ Q_ENUM(Modifiers)
+
+ explicit Q3DMouseEvent(const QMouseEvent &e);
+ ~Q3DMouseEvent();
+
+ inline int x() const { return m_event.x(); }
+ inline int y() const { return m_event.y(); }
+ inline bool wasHeld() const { return static_cast<Qt::GestureType>(m_event.type()) == Qt::TapAndHoldGesture; }
+ Buttons button() const;
+ int buttons() const;
+ Modifiers modifier() const;
+
+ inline bool isAccepted() const { return m_event.isAccepted(); }
+ inline void setAccepted(bool accepted) { m_event.setAccepted(accepted); }
+ inline QEvent::Type type() const { return m_event.type(); }
+
+private:
+ QMouseEvent m_event;
+};
+
+typedef QSharedPointer<Q3DMouseEvent> Q3DMouseEventPtr;
+
+class QT3DINPUTSHARED_EXPORT Q3DWheelEvent : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int x READ x CONSTANT)
+ Q_PROPERTY(int y READ y CONSTANT)
+ Q_PROPERTY(QPoint angleDelta READ angleDelta CONSTANT)
+ Q_PROPERTY(int buttons READ buttons CONSTANT)
+ Q_PROPERTY(Qt3D::Q3DWheelEvent::Modifiers modifier READ modifier CONSTANT)
+ Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
+
+public:
+ enum Buttons {
+ LeftButton = Qt::MouseButton::LeftButton,
+ RightButton = Qt::MouseButton::RightButton,
+ MiddleButton = Qt::MouseButton::MiddleButton,
+ BackButton = Qt::MouseButton::BackButton,
+ NoButton = Qt::MouseButton::NoButton
+ };
+ Q_ENUM(Buttons)
+
+ enum Modifiers {
+ NoModifier = Qt::NoModifier,
+ ShiftModifier = Qt::ShiftModifier,
+ ControlModifier = Qt::ControlModifier,
+ AltModifier = Qt::AltModifier,
+ MetaModifier = Qt::MetaModifier,
+ KeypadModifier = Qt::KeypadModifier
+ };
+ Q_ENUM(Modifiers)
+
+ explicit Q3DWheelEvent(const QWheelEvent &e);
+ ~Q3DWheelEvent();
+
+ inline int x() const { return m_event.x(); }
+ inline int y() const { return m_event.y(); }
+ inline QPoint angleDelta() const { return m_event.angleDelta(); }
+ int buttons() const;
+ Modifiers modifier() const;
+
+ inline bool isAccepted() const { return m_event.isAccepted(); }
+ inline void setAccepted(bool accepted) { m_event.setAccepted(accepted); }
+ inline QEvent::Type type() const { return m_event.type(); }
+
+private:
+ QWheelEvent m_event;
+};
+
+typedef QSharedPointer<Q3DWheelEvent> Q3DWheelEventPtr;
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(Qt3D::Q3DMouseEvent*)
+Q_DECLARE_METATYPE(Qt3D::Q3DWheelEvent*)
+
+#endif // QT3D_Q3DMOUSEEVENT_H
diff --git a/src/input/qmousecontroller.cpp b/src/input/qmousecontroller.cpp
new file mode 100644
index 000000000..7fd585091
--- /dev/null
+++ b/src/input/qmousecontroller.cpp
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 "qmousecontroller.h"
+#include "qmousecontroller_p.h"
+
+#include <Qt3DCore/qentity.h>
+
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+QMouseControllerPrivate::QMouseControllerPrivate()
+ : QNodePrivate()
+{
+}
+
+/*!
+ * \class Qt3D::QMouseController
+ *
+ * \brief Qt3D::QMouseController is in charge of dispatching mouse events to
+ * attached Qt3D::QMouseInput objects.
+ *
+ * \since 5.5
+ * \sa Qt3D::QMouseInput
+ */
+QMouseController::QMouseController(QNode *parent)
+ : QNode(*new QMouseControllerPrivate, parent)
+{
+}
+
+QMouseController::QMouseController(QMouseControllerPrivate &dd, QNode *parent)
+ : QNode(dd, parent)
+{
+}
+
+void QMouseController::sceneChangeEvent(const QSceneChangePtr &change)
+{
+ Q_UNUSED(change);
+ // TODO: To be completed as the mouse input aspect takes shape
+}
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/input/qmousecontroller.h b/src/input/qmousecontroller.h
new file mode 100644
index 000000000..89f99c022
--- /dev/null
+++ b/src/input/qmousecontroller.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 QT3D_QMOUSECONTROLLER_H
+#define QT3D_QMOUSECONTROLLER_H
+
+#include <Qt3DInput/qt3dinput_global.h>
+#include <Qt3DCore/qnode.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QMouseControllerPrivate;
+class QMouseInput;
+
+class QT3DINPUTSHARED_EXPORT QMouseController : public QNode
+{
+ Q_OBJECT
+
+public:
+ explicit QMouseController(QNode *parent = 0);
+
+protected:
+ QMouseController(QMouseControllerPrivate &dd, QNode *parent = 0);
+ void sceneChangeEvent(const QSceneChangePtr &change) Q_DECL_OVERRIDE;
+
+private:
+ Q_DECLARE_PRIVATE(QMouseController)
+ QT3D_CLONEABLE(QMouseController)
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(Qt3D::QMouseController*)
+
+#endif // QT3D_QMOUSECONTROLLER_H
diff --git a/src/input/qmousecontroller_p.h b/src/input/qmousecontroller_p.h
new file mode 100644
index 000000000..7c00ef566
--- /dev/null
+++ b/src/input/qmousecontroller_p.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 QT3D_QMOUSECONTROLLER_P_H
+#define QT3D_QMOUSECONTROLLER_P_H
+
+#include <private/qnode_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QMouseController;
+
+class QMouseControllerPrivate : public QNodePrivate
+{
+public:
+ QMouseControllerPrivate();
+
+ Q_DECLARE_PUBLIC(QMouseController)
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QMOUSECONTROLLER_P_H
+
diff --git a/src/input/qmouseinput.cpp b/src/input/qmouseinput.cpp
new file mode 100644
index 000000000..dbaa1ebc4
--- /dev/null
+++ b/src/input/qmouseinput.cpp
@@ -0,0 +1,176 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 "qmouseinput.h"
+#include "qmouseinput_p.h"
+#include "qmousecontroller.h"
+#include "q3dmouseevent.h"
+#include <Qt3DCore/qbackendscenepropertychange.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+QMouseInputPrivate::QMouseInputPrivate()
+ : QComponentPrivate()
+ , m_controller(Q_NULLPTR)
+ , m_containsMouse(false)
+{
+ m_shareable = false;
+}
+
+/*!
+ * \class Qt3D::QMouseInput
+ *
+ * \brief Provides a mean of being notified about mouse events when attached to
+ * a Qt3D::QMouseController instance.
+ *
+ * \since 5.5
+ *
+ * \note Qt3D::QMouseInput components shouldn't be shared, not respecting that
+ * condition will most likely result in undefined behaviors.
+ *
+ * \sa Qt3D::QMouseController
+ */
+
+/*!
+ * Constructs a new Qt3D::QMouseInput instance with parent \a parent.
+ */
+QMouseInput::QMouseInput(QNode *parent)
+ : QComponent(*new QMouseInputPrivate, parent)
+{
+}
+
+QMouseInput::QMouseInput(QMouseInputPrivate &dd, QNode *parent)
+ : QComponent(dd, parent)
+{
+}
+
+/*!
+ * Sets the mouse controller of the Qt3D::QMouseInput instance to \a controller.
+ */
+void QMouseInput::setController(QMouseController *controller)
+{
+ Q_D(QMouseInput);
+ if (d->m_controller != controller) {
+ d->m_controller = controller;
+ emit controllerChanged();
+ }
+}
+
+/*!
+ * Returns the current mouse controller of the QMouseInput instance.
+ */
+QMouseController *QMouseInput::controller() const
+{
+ Q_D(const QMouseInput);
+ return d->m_controller;
+}
+
+/*!
+ * Returns true if the QMouseInput currently contains the mouse.
+ *
+ * \note: In this context, contains mean that the ray originating from the
+ * mouse is intersecting with the Qt3D::QEntity that aggregates the current
+ * Qt3D::QMouseInput instance component.
+ */
+bool QMouseInput::containsMouse() const
+{
+ Q_D(const QMouseInput);
+ return d->m_containsMouse;
+}
+
+void QMouseInput::copy(const QNode *ref)
+{
+ Q_D(QMouseInput);
+ const QMouseInput *refInput = static_cast<const QMouseInput *>(ref);
+ d->m_containsMouse = refInput->containsMouse();
+ if (refInput)
+ d->m_controller = static_cast<QMouseController *>(QNode::clone(refInput->controller()));
+}
+
+void QMouseInput::sceneChangeEvent(const QSceneChangePtr &change)
+{
+ QBackendScenePropertyChangePtr e = qSharedPointerCast<QBackendScenePropertyChange>(change);
+ if (e->type() == NodeUpdated) {
+ if (e->propertyName() == QByteArrayLiteral("mouse")) {
+ Q3DMouseEventPtr ev = e->value().value<Q3DMouseEventPtr>();
+ mouseEvent(ev.data());
+ } else if (e->propertyName() == QByteArrayLiteral("wheel")) {
+ Q3DWheelEventPtr ev = e->value().value<Q3DWheelEventPtr>();
+ emit wheel(ev.data());
+ }
+ }
+}
+
+void QMouseInput::mouseEvent(Q3DMouseEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::MouseButtonPress:
+ if (event->wasHeld())
+ emit pressAndHold(event);
+ else
+ emit pressed(event);
+ break;
+ case QEvent::MouseButtonRelease:
+ emit released(event);
+ break;
+ case Qt::TapGesture:
+ emit clicked(event);
+ break;
+ case QEvent::MouseButtonDblClick:
+ emit doubleClicked(event);
+ break;
+ case QEvent::MouseMove:
+ emit positionChanged(event);
+ break;
+ default:
+ break;
+ }
+}
+
+void QMouseInput::setContainsMouse(bool contains)
+{
+ Q_D(QMouseInput);
+ if (contains != d->m_containsMouse) {
+ d->m_containsMouse = contains;
+ emit containsMouseChanged();
+ }
+}
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/input/qmouseinput.h b/src/input/qmouseinput.h
new file mode 100644
index 000000000..0f7ae5d6a
--- /dev/null
+++ b/src/input/qmouseinput.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 QT3D_QMOUSEINPUT_H
+#define QT3D_QMOUSEINPUT_H
+
+#include <Qt3DInput/qt3dinput_global.h>
+#include <Qt3DInput/q3dmouseevent.h>
+#include <Qt3DCore/qcomponent.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QMouseController;
+class QMouseInputPrivate;
+
+class QT3DINPUTSHARED_EXPORT QMouseInput : public QComponent
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt3D::QMouseController *controller READ controller WRITE setController NOTIFY controllerChanged)
+ Q_PROPERTY(bool containsMouse READ containsMouse NOTIFY containsMouseChanged)
+
+public:
+ explicit QMouseInput(QNode *parent = 0);
+
+ void setController(QMouseController *controller);
+ QMouseController *controller() const;
+
+ bool containsMouse() const;
+
+Q_SIGNALS:
+ void controllerChanged();
+ void containsMouseChanged();
+
+ void clicked(Qt3D::Q3DMouseEvent *mouse);
+ void doubleClicked(Qt3D::Q3DMouseEvent *mouse);
+
+ void entered();
+ void exited();
+
+ void pressed(Qt3D::Q3DMouseEvent *mouse);
+ void released(Qt3D::Q3DMouseEvent *mouse);
+ void pressAndHold(Qt3D::Q3DMouseEvent *mouse);
+ void positionChanged(Qt3D::Q3DMouseEvent *mouse);
+
+ void wheel(Qt3D::Q3DWheelEvent *wheel);
+
+protected:
+ QMouseInput(QMouseInputPrivate &dd, QNode *parent = 0);
+ void copy(const QNode *ref) Q_DECL_OVERRIDE;
+ void sceneChangeEvent(const QSceneChangePtr &change) Q_DECL_OVERRIDE;
+ void mouseEvent(Q3DMouseEvent *event);
+ void setContainsMouse(bool contains);
+
+private:
+ Q_DECLARE_PRIVATE(QMouseInput)
+ QT3D_CLONEABLE(QMouseInput)
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QMOUSEINPUT_H
diff --git a/src/input/qmouseinput_p.h b/src/input/qmouseinput_p.h
new file mode 100644
index 000000000..981223b34
--- /dev/null
+++ b/src/input/qmouseinput_p.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 QT3D_QMOUSEINPUT_P_H
+#define QT3D_QMOUSEINPUT_P_H
+
+#include <private/qcomponent_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QMouseInput;
+class QMouseController;
+
+class QMouseInputPrivate : public QComponentPrivate
+{
+public:
+ QMouseInputPrivate();
+
+ QMouseController *m_controller;
+ bool m_containsMouse;
+
+ Q_DECLARE_PUBLIC(QMouseInput)
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QMOUSEINPUT_P_H
+