From 29807dbcd23b47940311e45bbb789f1be1b8f66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Tue, 25 Oct 2016 13:14:52 +0300 Subject: Add focus to EventForward MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I6e8d2c65bfbc3ba0373a119b6c244eb2a634be28 Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- src/render/picking/eventforward.cpp | 15 +++++++++++++++ src/render/picking/eventforward_p.h | 3 +++ src/render/picking/qeventforward.cpp | 27 +++++++++++++++++++++++++++ src/render/picking/qeventforward.h | 4 ++++ src/render/picking/qeventforward_p.h | 3 +++ 5 files changed, 52 insertions(+) (limited to 'src') diff --git a/src/render/picking/eventforward.cpp b/src/render/picking/eventforward.cpp index 7e24557ab..132e022ce 100644 --- a/src/render/picking/eventforward.cpp +++ b/src/render/picking/eventforward.cpp @@ -54,6 +54,7 @@ EventForward::EventForward() : m_target(nullptr) , m_forwardMouseEvents(false) , m_forwardKeyboardEvents(false) + , m_focus(false) { } @@ -71,6 +72,7 @@ void EventForward::cleanup() m_coordinateTransform.setToIdentity(); m_forwardMouseEvents = false; m_forwardKeyboardEvents = false; + m_focus = false; } QObject *EventForward::target() const @@ -98,6 +100,11 @@ bool EventForward::forwardKeyboardEvents() const return m_forwardKeyboardEvents; } +bool EventForward::focus() const +{ + return m_focus; +} + void EventForward::setTarget(QObject *target) { m_target = target; @@ -123,6 +130,11 @@ void EventForward::setForwardKeyboardEvents(bool enabled) m_forwardKeyboardEvents = enabled; } +void EventForward::setFocus(bool focus) +{ + m_focus = focus; +} + void EventForward::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) { const auto typedChange = qSharedPointerCast>(change); @@ -132,6 +144,7 @@ void EventForward::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr setCoordinateTransform(data.coordinateTransform); setForwardMouseEvents(data.forwardMouseEvents); setForwardKeyboardEvents(data.forwardKeyboardEvents); + setFocus(data.focus); } void EventForward::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) @@ -150,6 +163,8 @@ void EventForward::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) setForwardMouseEvents(propertyChange->value().toBool()); else if (propertyChange->propertyName() == QByteArrayLiteral("forwardKeyboardEvents")) setForwardKeyboardEvents(propertyChange->value().toBool()); + else if (propertyChange->propertyName() == QByteArrayLiteral("focus")) + setFocus(propertyChange->value().toBool()); } BackendNode::sceneChangeEvent(e); diff --git a/src/render/picking/eventforward_p.h b/src/render/picking/eventforward_p.h index 1fc56ead2..e090ba5e4 100644 --- a/src/render/picking/eventforward_p.h +++ b/src/render/picking/eventforward_p.h @@ -74,12 +74,14 @@ public: QMatrix4x4 coordinateTransform() const; bool forwardMouseEvents() const; bool forwardKeyboardEvents() const; + bool focus() const; void setTarget(QObject *target); void setCoordinateTransform(const QMatrix4x4 &transform); void setCoordinateAttribute(const QString &attribute); void setForwardMouseEvents(bool enabled); void setForwardKeyboardEvents(bool enabled); + void setFocus(bool focus); void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_FINAL; @@ -94,6 +96,7 @@ private: QMatrix4x4 m_coordinateTransform; bool m_forwardMouseEvents; bool m_forwardKeyboardEvents; + bool m_focus; }; } // Render diff --git a/src/render/picking/qeventforward.cpp b/src/render/picking/qeventforward.cpp index 74b52989e..8aa22e276 100644 --- a/src/render/picking/qeventforward.cpp +++ b/src/render/picking/qeventforward.cpp @@ -99,6 +99,10 @@ namespace Qt3DRender { \qmlproperty string Qt3D.Render::EventForward::coordinateAttribute Holds the name of the coordinate attribute the mouse coordinates are calculated from. */ +/*! + \qmlproperty bool Qt3D.Render::EventForward::focus + Holds whether the QObjectPicker has focus. +*/ /*! \property QEventForward::target @@ -120,7 +124,14 @@ namespace Qt3DRender { \property QEventForward::coordinateAttribute Holds the name of the coordinate attribute the mouse coordinates are calculated from. */ +/*! + \property QEventForward::focus + Holds whether the ObjectPicker has focus. + */ +/*! + + */ QEventForward::QEventForward(Qt3DCore::QNode *parent) : Qt3DCore::QNode(*new QEventForwardPrivate(), parent) { @@ -206,6 +217,21 @@ void QEventForward::setForwardKeyboardEvents(bool forward) } } +bool QEventForward::focus() const +{ + Q_D(const QEventForward); + return d->m_focus; +} + +void QEventForward::setFocus(bool focus) +{ + Q_D(QEventForward); + if (d->m_focus != focus) { + d->m_focus = focus; + emit focusChanged(focus); + } +} + /*! \internal */ @@ -219,6 +245,7 @@ Qt3DCore::QNodeCreatedChangeBasePtr QEventForward::createNodeCreationChange() co data.coordinateAttribute = d->m_attribute; data.forwardMouseEvents = d->m_forwardMouseEvents; data.forwardKeyboardEvents = d->m_forwardKeyboardEvents; + data.focus = d->m_focus; return creationChange; } diff --git a/src/render/picking/qeventforward.h b/src/render/picking/qeventforward.h index 694ad0d2d..28659606b 100644 --- a/src/render/picking/qeventforward.h +++ b/src/render/picking/qeventforward.h @@ -58,6 +58,7 @@ class QT3DRENDERSHARED_EXPORT QEventForward : public Qt3DCore::QNode 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) + Q_PROPERTY(bool focus READ focus WRITE setFocus NOTIFY focusChanged) public: explicit QEventForward(Qt3DCore::QNode *parent = nullptr); @@ -68,6 +69,7 @@ public: QString coordinateAttribute() const; bool forwardMouseEvents() const; bool forwardKeyboardEvents() const; + bool focus() const; public Q_SLOTS: void setTarget(QObject *target); @@ -75,6 +77,7 @@ public Q_SLOTS: void setCoordinateAttribute(const QString &coordinateAttribute); void setForwardMouseEvents(bool forward); void setForwardKeyboardEvents(bool forward); + void setFocus(bool focus); Q_SIGNALS: void targetChanged(QObject *target); @@ -82,6 +85,7 @@ Q_SIGNALS: void coordinateAttributeChanged(const QString &coordinateAttribute); void forwardMouseEventsChanged(bool forward); void forwardKeyboardEventsChanged(bool forward); + void focusChanged(bool focus); private: Q_DECLARE_PRIVATE(QEventForward) diff --git a/src/render/picking/qeventforward_p.h b/src/render/picking/qeventforward_p.h index be2e832d8..4aa6834df 100644 --- a/src/render/picking/qeventforward_p.h +++ b/src/render/picking/qeventforward_p.h @@ -68,6 +68,7 @@ public: , m_attribute("default") , m_forwardMouseEvents(true) , m_forwardKeyboardEvents(false) + , m_focus(false) { } @@ -79,6 +80,7 @@ public: QString m_attribute; bool m_forwardMouseEvents; bool m_forwardKeyboardEvents; + bool m_focus; }; struct QEventForwardData @@ -88,6 +90,7 @@ struct QEventForwardData QString coordinateAttribute; bool forwardMouseEvents; bool forwardKeyboardEvents; + bool focus; }; } // namespace Qt3DRender -- cgit v1.2.3