summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2016-10-24 16:07:52 +0300
committerAntti Määttä <antti.maatta@qt.io>2017-01-24 16:20:50 +0000
commit1a3b74a1794e727457df8dcd1d42754d584c7562 (patch)
tree8c0137ea9fc766421ca5bbdff410d199f8f46a82
parentb5af580c823372e3d6f956a860e092018a066766 (diff)
downloadqt3d-1a3b74a1794e727457df8dcd1d42754d584c7562.tar.gz
Add QEventForward frontend node
Implementation of QEventForward frontend node. It sends events from the object picker to the receiving object. This is needed in order to interact with the QScene2D QML. Change-Id: Icd464e28387ec5a362d6371ebdbaba6d0cd8e5d7 Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/picking/picking.pri7
-rw-r--r--src/render/picking/qeventforward.cpp227
-rw-r--r--src/render/picking/qeventforward.h97
-rw-r--r--src/render/picking/qeventforward_p.h97
4 files changed, 426 insertions, 2 deletions
diff --git a/src/render/picking/picking.pri b/src/render/picking/picking.pri
index c4c188a82..29eabe15d 100644
--- a/src/render/picking/picking.pri
+++ b/src/render/picking/picking.pri
@@ -7,11 +7,14 @@ HEADERS += \
$$PWD/qpicktriangleevent.h \
$$PWD/objectpicker_p.h \
$$PWD/pickeventfilter_p.h \
- $$PWD/qobjectpicker_p.h
+ $$PWD/qobjectpicker_p.h \
+ $$PWD/qeventforward.h \
+ $$PWD/qeventforward_p.h
SOURCES += \
$$PWD/qobjectpicker.cpp \
$$PWD/qpickevent.cpp \
$$PWD/qpicktriangleevent.cpp \
$$PWD/objectpicker.cpp \
- $$PWD/pickeventfilter.cpp
+ $$PWD/pickeventfilter.cpp \
+ $$PWD/qeventforward.cpp
diff --git a/src/render/picking/qeventforward.cpp b/src/render/picking/qeventforward.cpp
new file mode 100644
index 000000000..74b52989e
--- /dev/null
+++ b/src/render/picking/qeventforward.cpp
@@ -0,0 +1,227 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** 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 "qeventforward.h"
+#include "qeventforward_p.h"
+
+#include <Qt3DCore/qpropertyupdatedchange.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+/*!
+ \class Qt3DRender::QEventForward
+ \inmodule Qt3DRender
+
+ \brief The QEventForward class instantiates a node that can
+ be used to forward events from the scene.
+
+ An QEventForward class can be used to forward pick events and keyboard events
+ from entities having a QObjectPicker. When the QObjectPicker handles pick event,
+ it hands it to the QEventForward, which converts it to QMouseEvent. The event
+ mouse coordinates are calculated by interpolating the given coordinate attribute
+ on the position the pick ray intersected the triangle, and then multiplying the
+ interpolated coordinate with the given transformation matrix. The event is then
+ sent and to the target object.
+
+ \since 5.9
+*/
+
+/*!
+ \qmltype EventForward
+ \instantiates Qt3DRender::QEventForward
+ \inherits Node
+ \inqmlmodule Qt3D.Render
+ \brief The EventForward type instantiates a node that can
+ be used to forward events from the scene.
+
+ An EventForward type can be used to forward pick events and keyboard events
+ from entities having a ObjectPicker. When the ObjectPicker handles pick event,
+ it hands it to the EventForward, which converts it to MouseEvent. The event
+ mouse coordinates are calculated by interpolating the given coordinate attribute
+ on the position the pick ray intersected the triangle, and then multiplying the
+ interpolated coordinate with the given transformation matrix. The event is then
+ sent and to the target object.
+
+ */
+
+/*!
+ \qmlproperty Object Qt3D.Render::EventForward::target
+ Holds the object the events are sent to.
+*/
+/*!
+ \qmlproperty bool Qt3D.Render::EventForward::forwardMouseEvents
+ Holds whether mouse event forwarding is enabled.
+*/
+/*!
+ \qmlproperty bool Qt3D.Render::EventForward::forwardKeyboardEvents
+ Holds whether keyboard event forwarding is enabled.
+*/
+/*!
+ \qmlproperty Matrix4x4 Qt3D.Render::EventForward::coordinateTransform
+ Holds the coordinate transformation.
+*/
+/*!
+ \qmlproperty string Qt3D.Render::EventForward::coordinateAttribute
+ Holds the name of the coordinate attribute the mouse coordinates are calculated from.
+*/
+
+/*!
+ \property QEventForward::target
+ Holds the object the events are sent to.
+*/
+/*!
+ \property QEventForward::forwardMouseEvents
+ Holds whether mouse event forwarding is enabled.
+*/
+/*!
+ \property QEventForward::forwardKeyboardEvents
+ Holds whether keyboard event forwarding is enabled.
+*/
+/*!
+ \property QEventForward::coordinateTransform
+ Holds the coordinate transformation.
+*/
+/*!
+ \property QEventForward::coordinateAttribute
+ Holds the name of the coordinate attribute the mouse coordinates are calculated from.
+*/
+
+QEventForward::QEventForward(Qt3DCore::QNode *parent)
+ : Qt3DCore::QNode(*new QEventForwardPrivate(), parent)
+{
+}
+
+/*! \internal */
+QEventForward::~QEventForward()
+{
+}
+
+QObject *QEventForward::target() const
+{
+ Q_D(const QEventForward);
+ return d->m_target;
+}
+
+void QEventForward::setTarget(QObject *target)
+{
+ Q_D(QEventForward);
+ if (target != d->m_target) {
+ d->m_target = target;
+ emit targetChanged(target);
+ }
+}
+
+QMatrix4x4 QEventForward::coordinateTransform() const
+{
+ Q_D(const QEventForward);
+ return d->m_transform;
+}
+
+void QEventForward::setCoordinateTransform(const QMatrix4x4 &coordinateTransform)
+{
+ Q_D(QEventForward);
+ if (coordinateTransform != d->m_transform) {
+ d->m_transform = coordinateTransform;
+ emit coordinateTransformChanged(coordinateTransform);
+ }
+}
+
+QString QEventForward::coordinateAttribute() const
+{
+ Q_D(const QEventForward);
+ return d->m_attribute;
+}
+
+void QEventForward::setCoordinateAttribute(const QString &coordinateAttribute)
+{
+ Q_D(QEventForward);
+ if (coordinateAttribute != d->m_attribute) {
+ d->m_attribute = coordinateAttribute;
+ emit coordinateAttributeChanged(coordinateAttribute);
+ }
+}
+
+bool QEventForward::forwardMouseEvents() const
+{
+ Q_D(const QEventForward);
+ return d->m_forwardMouseEvents;
+}
+
+void QEventForward::setForwardMouseEvents(bool forward)
+{
+ Q_D(QEventForward);
+ if (forward != d->m_forwardMouseEvents) {
+ d->m_forwardMouseEvents = forward;
+ emit forwardMouseEventsChanged(forward);
+ }
+}
+
+bool QEventForward::forwardKeyboardEvents() const
+{
+ Q_D(const QEventForward);
+ return d->m_forwardKeyboardEvents;
+}
+
+void QEventForward::setForwardKeyboardEvents(bool forward)
+{
+ Q_D(QEventForward);
+ if (forward != d->m_forwardKeyboardEvents) {
+ d->m_forwardKeyboardEvents = forward;
+ emit forwardKeyboardEventsChanged(forward);
+ }
+}
+
+/*!
+ \internal
+ */
+Qt3DCore::QNodeCreatedChangeBasePtr QEventForward::createNodeCreationChange() const
+{
+ auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QEventForwardData>::create(this);
+ auto &data = creationChange->data;
+ Q_D(const QEventForward);
+ data.target = d->m_target;
+ data.coordinateTransform = d->m_transform;
+ data.coordinateAttribute = d->m_attribute;
+ data.forwardMouseEvents = d->m_forwardMouseEvents;
+ data.forwardKeyboardEvents = d->m_forwardKeyboardEvents;
+ return creationChange;
+}
+
+} // Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/picking/qeventforward.h b/src/render/picking/qeventforward.h
new file mode 100644
index 000000000..694ad0d2d
--- /dev/null
+++ b/src/render/picking/qeventforward.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** 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 QT3DRENDER_QEVENTFORWARD_H
+#define QT3DRENDER_QEVENTFORWARD_H
+
+#include <Qt3DRender/qt3drender_global.h>
+
+#include <Qt3DCore/qnode.h>
+
+#include <QtGui/qmatrix4x4.h>
+#include <QtCore/qstring.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+class QEventForwardPrivate;
+
+class QT3DRENDERSHARED_EXPORT QEventForward : public Qt3DCore::QNode
+{
+ Q_OBJECT
+ Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged)
+ Q_PROPERTY(bool forwardMouseEvents READ forwardMouseEvents WRITE setForwardMouseEvents NOTIFY forwardMouseEventsChanged)
+ Q_PROPERTY(bool forwardKeyboardEvents READ forwardKeyboardEvents WRITE setForwardKeyboardEvents NOTIFY forwardKeyboardEventsChanged)
+ Q_PROPERTY(QMatrix4x4 coordinateTransform READ coordinateTransform WRITE setCoordinateTransform NOTIFY coordinateTransformChanged)
+ Q_PROPERTY(QString coordinateAttribute READ coordinateAttribute WRITE setCoordinateAttribute NOTIFY coordinateAttributeChanged)
+
+public:
+ explicit QEventForward(Qt3DCore::QNode *parent = nullptr);
+ ~QEventForward();
+
+ QObject *target() const;
+ QMatrix4x4 coordinateTransform() const;
+ QString coordinateAttribute() const;
+ bool forwardMouseEvents() const;
+ bool forwardKeyboardEvents() const;
+
+public Q_SLOTS:
+ void setTarget(QObject *target);
+ void setCoordinateTransform(const QMatrix4x4 &coordinateTransform);
+ void setCoordinateAttribute(const QString &coordinateAttribute);
+ void setForwardMouseEvents(bool forward);
+ void setForwardKeyboardEvents(bool forward);
+
+Q_SIGNALS:
+ void targetChanged(QObject *target);
+ void coordinateTransformChanged(const QMatrix4x4 &coordinateTransform);
+ void coordinateAttributeChanged(const QString &coordinateAttribute);
+ void forwardMouseEventsChanged(bool forward);
+ void forwardKeyboardEventsChanged(bool forward);
+
+private:
+ Q_DECLARE_PRIVATE(QEventForward)
+ Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE;
+};
+
+} // Qt3DRender
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(Qt3DRender::QEventForward*)
+
+#endif // QT3DRENDER_QEVENTFORWARD_H
diff --git a/src/render/picking/qeventforward_p.h b/src/render/picking/qeventforward_p.h
new file mode 100644
index 000000000..be2e832d8
--- /dev/null
+++ b/src/render/picking/qeventforward_p.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** 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 QT3DRENDER_QEVENTFORWARD_P_H
+#define QT3DRENDER_QEVENTFORWARD_P_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 <private/qnode_p.h>
+#include <Qt3DCore/qnodeid.h>
+#include <qmatrix4x4.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+/*!
+ \internal
+*/
+class QEventForwardPrivate : public Qt3DCore::QNodePrivate
+{
+public:
+ QEventForwardPrivate()
+ : QNodePrivate()
+ , m_target(nullptr)
+ , m_attribute("default")
+ , m_forwardMouseEvents(true)
+ , m_forwardKeyboardEvents(false)
+ {
+
+ }
+
+ Q_DECLARE_PUBLIC(QEventForward)
+
+ QObject *m_target;
+ QMatrix4x4 m_transform;
+ QString m_attribute;
+ bool m_forwardMouseEvents;
+ bool m_forwardKeyboardEvents;
+};
+
+struct QEventForwardData
+{
+ QObject *target;
+ QMatrix4x4 coordinateTransform;
+ QString coordinateAttribute;
+ bool forwardMouseEvents;
+ bool forwardKeyboardEvents;
+};
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_QEVENTFORWARD_P_H