diff options
author | Robert Brock <robert.brock@kdab.com> | 2016-04-29 08:18:06 +0200 |
---|---|---|
committer | Kevin Ottens <kevin.ottens@kdab.com> | 2016-05-02 10:26:25 +0000 |
commit | f63397953d052dc2a35bcc0ec32eaff0ebd80f05 (patch) | |
tree | 869d1bd567a7a8a6d399a2ecb4e6d9e561c6b557 /src | |
parent | 617e4c768616868a3e306668630efdfca69604d7 (diff) |
Splitting of QAxisInput
Placed buttons and scale into a new class
named QButtonAxisInput
Change-Id: I0e8407dc361d9d6eda38973a8950f77b17119467
Task-number: QTBUG-51474
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
24 files changed, 563 insertions, 101 deletions
diff --git a/src/extras/defaults/qfirstpersoncameracontroller.cpp b/src/extras/defaults/qfirstpersoncameracontroller.cpp index 2558dc7b6..0a69dc2ca 100644 --- a/src/extras/defaults/qfirstpersoncameracontroller.cpp +++ b/src/extras/defaults/qfirstpersoncameracontroller.cpp @@ -53,6 +53,7 @@ #include <Qt3DRender/QCamera> #include <Qt3DInput/QAxis> #include <Qt3DInput/QAxisInput> +#include <Qt3DInput/QButtonAxisInput> #include <Qt3DInput/QAction> #include <Qt3DInput/QActionInput> #include <Qt3DInput/QLogicalDevice> @@ -79,12 +80,12 @@ QFirstPersonCameraControllerPrivate::QFirstPersonCameraControllerPrivate() , m_fineMotionKeyInput(new Qt3DInput::QActionInput()) , m_mouseRxInput(new Qt3DInput::QAxisInput()) , m_mouseRyInput(new Qt3DInput::QAxisInput()) - , m_keyboardTxPosInput(new Qt3DInput::QAxisInput()) - , m_keyboardTyPosInput(new Qt3DInput::QAxisInput()) - , m_keyboardTzPosInput(new Qt3DInput::QAxisInput()) - , m_keyboardTxNegInput(new Qt3DInput::QAxisInput()) - , m_keyboardTyNegInput(new Qt3DInput::QAxisInput()) - , m_keyboardTzNegInput(new Qt3DInput::QAxisInput()) + , m_keyboardTxPosInput(new Qt3DInput::QButtonAxisInput()) + , m_keyboardTyPosInput(new Qt3DInput::QButtonAxisInput()) + , m_keyboardTzPosInput(new Qt3DInput::QButtonAxisInput()) + , m_keyboardTxNegInput(new Qt3DInput::QButtonAxisInput()) + , m_keyboardTyNegInput(new Qt3DInput::QButtonAxisInput()) + , m_keyboardTzNegInput(new Qt3DInput::QButtonAxisInput()) , m_keyboardDevice(new Qt3DInput::QKeyboardDevice()) , m_mouseDevice(new Qt3DInput::QMouseDevice()) , m_logicalDevice(new Qt3DInput::QLogicalDevice()) diff --git a/src/extras/defaults/qfirstpersoncameracontroller_p.h b/src/extras/defaults/qfirstpersoncameracontroller_p.h index 9e62b8e19..756ab668d 100644 --- a/src/extras/defaults/qfirstpersoncameracontroller_p.h +++ b/src/extras/defaults/qfirstpersoncameracontroller_p.h @@ -85,6 +85,7 @@ class QAction; class QActionInput; class QAxis; class QAxisInput; +class QButtonAxisInput; class QAxisActionHandler; } @@ -114,12 +115,12 @@ public: Qt3DInput::QAxisInput *m_mouseRxInput; Qt3DInput::QAxisInput *m_mouseRyInput; - Qt3DInput::QAxisInput *m_keyboardTxPosInput; - Qt3DInput::QAxisInput *m_keyboardTyPosInput; - Qt3DInput::QAxisInput *m_keyboardTzPosInput; - Qt3DInput::QAxisInput *m_keyboardTxNegInput; - Qt3DInput::QAxisInput *m_keyboardTyNegInput; - Qt3DInput::QAxisInput *m_keyboardTzNegInput; + Qt3DInput::QButtonAxisInput *m_keyboardTxPosInput; + Qt3DInput::QButtonAxisInput *m_keyboardTyPosInput; + Qt3DInput::QButtonAxisInput *m_keyboardTzPosInput; + Qt3DInput::QButtonAxisInput *m_keyboardTxNegInput; + Qt3DInput::QButtonAxisInput *m_keyboardTyNegInput; + Qt3DInput::QButtonAxisInput *m_keyboardTzNegInput; Qt3DInput::QKeyboardDevice *m_keyboardDevice; Qt3DInput::QMouseDevice *m_mouseDevice; diff --git a/src/extras/defaults/qorbitcontrol.cpp b/src/extras/defaults/qorbitcontrol.cpp index fbcaa9902..7c1c5e6f8 100644 --- a/src/extras/defaults/qorbitcontrol.cpp +++ b/src/extras/defaults/qorbitcontrol.cpp @@ -40,6 +40,7 @@ #include <Qt3DRender/QCamera> #include <Qt3DInput/QAxis> #include <Qt3DInput/QAxisInput> +#include <Qt3DInput/QButtonAxisInput> #include <Qt3DInput/QAction> #include <Qt3DInput/QActionInput> #include <Qt3DInput/QLogicalDevice> @@ -75,12 +76,12 @@ QOrbitControlPrivate::QOrbitControlPrivate() , m_shiftButtonInput(new Qt3DInput::QActionInput()) , m_mouseRxInput(new Qt3DInput::QAxisInput()) , m_mouseRyInput(new Qt3DInput::QAxisInput()) - , m_keyboardTxPosInput(new Qt3DInput::QAxisInput()) - , m_keyboardTyPosInput(new Qt3DInput::QAxisInput()) - , m_keyboardTzPosInput(new Qt3DInput::QAxisInput()) - , m_keyboardTxNegInput(new Qt3DInput::QAxisInput()) - , m_keyboardTyNegInput(new Qt3DInput::QAxisInput()) - , m_keyboardTzNegInput(new Qt3DInput::QAxisInput()) + , m_keyboardTxPosInput(new Qt3DInput::QButtonAxisInput()) + , m_keyboardTyPosInput(new Qt3DInput::QButtonAxisInput()) + , m_keyboardTzPosInput(new Qt3DInput::QButtonAxisInput()) + , m_keyboardTxNegInput(new Qt3DInput::QButtonAxisInput()) + , m_keyboardTyNegInput(new Qt3DInput::QButtonAxisInput()) + , m_keyboardTzNegInput(new Qt3DInput::QButtonAxisInput()) , m_keyboardDevice(new Qt3DInput::QKeyboardDevice()) , m_mouseDevice(new Qt3DInput::QMouseDevice()) , m_logicalDevice(new Qt3DInput::QLogicalDevice()) diff --git a/src/extras/defaults/qorbitcontrol_p.h b/src/extras/defaults/qorbitcontrol_p.h index e37ca50f6..900227152 100644 --- a/src/extras/defaults/qorbitcontrol_p.h +++ b/src/extras/defaults/qorbitcontrol_p.h @@ -71,6 +71,7 @@ class QAction; class QActionInput; class QAxis; class QAxisInput; +class QButtonAxisInput; class QAxisActionHandler; } @@ -104,12 +105,12 @@ public: Qt3DInput::QAxisInput *m_mouseRxInput; Qt3DInput::QAxisInput *m_mouseRyInput; - Qt3DInput::QAxisInput *m_keyboardTxPosInput; - Qt3DInput::QAxisInput *m_keyboardTyPosInput; - Qt3DInput::QAxisInput *m_keyboardTzPosInput; - Qt3DInput::QAxisInput *m_keyboardTxNegInput; - Qt3DInput::QAxisInput *m_keyboardTyNegInput; - Qt3DInput::QAxisInput *m_keyboardTzNegInput; + Qt3DInput::QButtonAxisInput *m_keyboardTxPosInput; + Qt3DInput::QButtonAxisInput *m_keyboardTyPosInput; + Qt3DInput::QButtonAxisInput *m_keyboardTzPosInput; + Qt3DInput::QButtonAxisInput *m_keyboardTxNegInput; + Qt3DInput::QButtonAxisInput *m_keyboardTyNegInput; + Qt3DInput::QButtonAxisInput *m_keyboardTzNegInput; Qt3DInput::QKeyboardDevice *m_keyboardDevice; Qt3DInput::QMouseDevice *m_mouseDevice; diff --git a/src/input/backend/axisinput.cpp b/src/input/backend/axisinput.cpp index 37abcb319..05b3a089a 100644 --- a/src/input/backend/axisinput.cpp +++ b/src/input/backend/axisinput.cpp @@ -65,7 +65,6 @@ QVector<int> listToIntArray(const QVariantList &l) AxisInput::AxisInput() : Qt3DCore::QBackendNode() , m_axis(0) - , m_scale(0.0f) { } @@ -76,8 +75,6 @@ void AxisInput::updateFromPeer(Qt3DCore::QNode *peer) { QAxisInput *input = static_cast<QAxisInput *>(peer); m_axis = input->axis(); - m_scale = input->scale(); - m_buttons = listToIntArray(input->buttons()); if (input->sourceDevice()) m_sourceDevice = input->sourceDevice()->id(); } @@ -87,17 +84,13 @@ void AxisInput::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &ch const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QAxisInputData>>(change); const auto &data = typedChange->data; m_sourceDevice = data.sourceDeviceId; - m_buttons = listToIntArray(data.buttons); m_axis = data.axis; - m_scale = data.scale; } void AxisInput::cleanup() { QBackendNode::setEnabled(false); m_axis = 0; - m_scale = 0.0f; - m_buttons.clear(); m_sourceDevice = Qt3DCore::QNodeId(); } @@ -107,12 +100,8 @@ void AxisInput::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Qt3DCore::QNodePropertyChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QNodePropertyChange>(e); if (propertyChange->propertyName() == QByteArrayLiteral("sourceDevice")) { m_sourceDevice = propertyChange->value().value<Qt3DCore::QNodeId>(); - } else if (propertyChange->propertyName() == QByteArrayLiteral("scale")) { - m_scale = propertyChange->value().toFloat(); } else if (propertyChange->propertyName() == QByteArrayLiteral("axis")) { m_axis = propertyChange->value().toInt(); - } else if (propertyChange->propertyName() == QByteArrayLiteral("buttons")) { - m_buttons = listToIntArray(propertyChange->value().toList()); } } QBackendNode::sceneChangeEvent(e); diff --git a/src/input/backend/axisinput_p.h b/src/input/backend/axisinput_p.h index 4683e7c4a..028bdc30a 100644 --- a/src/input/backend/axisinput_p.h +++ b/src/input/backend/axisinput_p.h @@ -65,21 +65,17 @@ class Q_AUTOTEST_EXPORT AxisInput : public Qt3DCore::QBackendNode public: AxisInput(); void updateFromPeer(Qt3DCore::QNode *peer) Q_DECL_OVERRIDE; - void cleanup(); + virtual void cleanup(); inline int axis() const { return m_axis; } - inline float scale() const { return m_scale; } - inline QVector<int> buttons() const { return m_buttons; } inline Qt3DCore::QNodeId sourceDevice() const { return m_sourceDevice; } void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE; -private: - void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; +protected: + void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_OVERRIDE; int m_axis; - QVector<int> m_buttons; Qt3DCore::QNodeId m_sourceDevice; - float m_scale; }; } // namespace Input diff --git a/src/input/backend/backend.pri b/src/input/backend/backend.pri index 647652009..834e9a58c 100644 --- a/src/input/backend/backend.pri +++ b/src/input/backend/backend.pri @@ -15,6 +15,7 @@ HEADERS += \ $$PWD/actioninput_p.h \ $$PWD/axis_p.h \ $$PWD/action_p.h \ + $$PWD/buttonaxisinput_p.h \ $$PWD/logicaldevice_p.h \ $$PWD/inputbackendnodefunctor_p.h \ $$PWD/qabstractphysicaldevicebackendnode.h \ @@ -44,6 +45,7 @@ SOURCES += \ $$PWD/actioninput.cpp \ $$PWD/axis.cpp \ $$PWD/action.cpp \ + $$PWD/buttonaxisinput.cpp \ $$PWD/logicaldevice.cpp \ $$PWD/qabstractphysicaldevicebackendnode.cpp \ $$PWD/movingaverage.cpp \ diff --git a/src/input/backend/buttonaxisinput.cpp b/src/input/backend/buttonaxisinput.cpp new file mode 100644 index 000000000..e6cac818c --- /dev/null +++ b/src/input/backend/buttonaxisinput.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "buttonaxisinput_p.h" +#include <Qt3DInput/qbuttonaxisinput.h> +#include <Qt3DInput/qabstractphysicaldevice.h> +#include <Qt3DInput/private/qbuttonaxisinput_p.h> +#include <Qt3DCore/qnodepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DInput { + +namespace Input { + +namespace { + +QVector<int> listToIntArray(const QVariantList &l) +{ + QVector<int> array; + array.reserve(l.size()); + for (const QVariant &v : l) + array.push_back(v.toInt()); + return array; +} + +} // anonymous + +ButtonAxisInput::ButtonAxisInput() + : AxisInput() + , m_scale(0.0f) +{ +} + +void ButtonAxisInput::updateFromPeer(Qt3DCore::QNode *peer) +{ + QButtonAxisInput *input = static_cast<QButtonAxisInput *>(peer); + m_scale = input->scale(); + m_buttons = listToIntArray(input->buttons()); + AxisInput::updateFromPeer(peer); +} + +void ButtonAxisInput::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) +{ + const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QButtonAxisInputData>>(change); + const auto &data = typedChange->data; + m_buttons = listToIntArray(data.buttons); + m_scale = data.scale; + AxisInput::initializeFromPeer(change); +} + +void ButtonAxisInput::cleanup() +{ + m_scale = 0.0f; + m_buttons.clear(); + AxisInput::cleanup(); +} + +void ButtonAxisInput::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) +{ + if (e->type() == Qt3DCore::NodeUpdated) { + Qt3DCore::QNodePropertyChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QNodePropertyChange>(e); + if (propertyChange->propertyName() == QByteArrayLiteral("scale")) { + m_scale = propertyChange->value().toFloat(); + } else if (propertyChange->propertyName() == QByteArrayLiteral("buttons")) { + m_buttons = listToIntArray(propertyChange->value().toList()); + } + } + AxisInput::sceneChangeEvent(e); +} + +} // Input + +} // Qt3DInput + +QT_END_NAMESPACE diff --git a/src/input/backend/buttonaxisinput_p.h b/src/input/backend/buttonaxisinput_p.h new file mode 100644 index 000000000..10b1bb2f7 --- /dev/null +++ b/src/input/backend/buttonaxisinput_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DINPUT_INPUT_BUTTONAXISINPUT_H +#define QT3DINPUT_INPUT_BUTTONAXISINPUT_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/private/axisinput_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DInput { + +namespace Input { + +class Q_AUTOTEST_EXPORT ButtonAxisInput : public AxisInput +{ +public: + ButtonAxisInput(); + void updateFromPeer(Qt3DCore::QNode *peer) Q_DECL_FINAL; + void cleanup() Q_DECL_FINAL; + + inline float scale() const { return m_scale; } + inline QVector<int> buttons() const { return m_buttons; } + void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_FINAL; + +private: + void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; + + QVector<int> m_buttons; + float m_scale; +}; + +} // namespace Input + +} // namespace Qt3DInput + +QT_END_NAMESPACE + +#endif // QT3DINPUT_INPUT_BUTTONAXISINPUT_H diff --git a/src/input/backend/inputhandler.cpp b/src/input/backend/inputhandler.cpp index dd4491506..6d4100af7 100644 --- a/src/input/backend/inputhandler.cpp +++ b/src/input/backend/inputhandler.cpp @@ -67,6 +67,7 @@ InputHandler::InputHandler() , m_axisInputManager(new AxisInputManager()) , m_axisSettingManager(new AxisSettingManager()) , m_actionInputManager(new ActionInputManager()) + , m_buttonAxisInputManager(new ButtonAxisInputManager()) , m_inputChordManager(new InputChordManager()) , m_inputSequenceManager(new InputSequenceManager()) , m_logicalDeviceManager(new LogicalDeviceManager()) @@ -93,6 +94,7 @@ InputHandler::~InputHandler() delete m_actionManager; delete m_axisSettingManager; delete m_axisInputManager; + delete m_buttonAxisInputManager; delete m_actionInputManager; delete m_inputChordManager; delete m_inputSequenceManager; diff --git a/src/input/backend/inputhandler_p.h b/src/input/backend/inputhandler_p.h index b39aeb681..d3812d35e 100644 --- a/src/input/backend/inputhandler_p.h +++ b/src/input/backend/inputhandler_p.h @@ -80,6 +80,7 @@ class ActionManager; class AxisInputManager; class AxisSettingManager; class ActionInputManager; +class ButtonAxisInputManager; class InputChordManager; class InputSequenceManager; class LogicalDeviceManager; @@ -103,6 +104,7 @@ public: inline AxisInputManager *axisInputManager() const { return m_axisInputManager; } inline AxisSettingManager *axisSettingManager() const { return m_axisSettingManager; } inline ActionInputManager *actionInputManager() const { return m_actionInputManager; } + inline ButtonAxisInputManager *buttonAxisInputManager() const { return m_buttonAxisInputManager; } inline InputChordManager *inputChordManager() const { return m_inputChordManager; } inline InputSequenceManager *inputSequenceManager() const { return m_inputSequenceManager; } inline LogicalDeviceManager *logicalDeviceManager() const { return m_logicalDeviceManager; } @@ -164,6 +166,7 @@ private: AxisInputManager *m_axisInputManager; AxisSettingManager *m_axisSettingManager; ActionInputManager *m_actionInputManager; + ButtonAxisInputManager *m_buttonAxisInputManager; InputChordManager *m_inputChordManager; InputSequenceManager *m_inputSequenceManager; LogicalDeviceManager *m_logicalDeviceManager; diff --git a/src/input/backend/inputmanagers_p.h b/src/input/backend/inputmanagers_p.h index 4967cd71d..a70a5d023 100644 --- a/src/input/backend/inputmanagers_p.h +++ b/src/input/backend/inputmanagers_p.h @@ -65,6 +65,7 @@ #include <Qt3DInput/private/action_p.h> #include <Qt3DInput/private/axis_p.h> #include <Qt3DInput/private/axissetting_p.h> +#include <Qt3DInput/private/buttonaxisinput_p.h> #include <Qt3DInput/private/logicaldevice_p.h> #include <Qt3DInput/private/genericdevicebackendnode_p.h> @@ -163,6 +164,16 @@ public: ActionInputManager() {} }; +class ButtonAxisInputManager : public Qt3DCore::QResourceManager< + ButtonAxisInput, + Qt3DCore::QNodeId, + 16, + Qt3DCore::ArrayAllocatingPolicy> +{ +public: + ButtonAxisInputManager() {} +}; + class InputChordManager : public Qt3DCore::QResourceManager< InputChord, Qt3DCore::QNodeId, diff --git a/src/input/backend/updateaxisactionjob.cpp b/src/input/backend/updateaxisactionjob.cpp index 97ad15842..cf35cbac6 100644 --- a/src/input/backend/updateaxisactionjob.cpp +++ b/src/input/backend/updateaxisactionjob.cpp @@ -170,6 +170,13 @@ void UpdateAxisActionJob::updateAxis(LogicalDevice *device) const auto axisInputIds = axis->inputs(); for (const Qt3DCore::QNodeId axisInputId : axisInputIds) { AxisInput *axisInput = m_handler->axisInputManager()->lookupResource(axisInputId); + ButtonAxisInput *buttonAxisInput = nullptr; + if (!axisInput) { + buttonAxisInput = m_handler->buttonAxisInputManager()->lookupResource(axisInputId); + axisInput = buttonAxisInput; + } + Q_ASSERT(axisInput); + QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = nullptr; const auto integrations = m_handler->inputDeviceIntegrations(); @@ -180,14 +187,14 @@ void UpdateAxisActionJob::updateAxis(LogicalDevice *device) if (physicalDeviceBackend != nullptr) { // Update the value - const QVector<int> buttons = axisInput->buttons(); + const QVector<int> buttons = buttonAxisInput ? buttonAxisInput->buttons() : QVector<int>(); // Axis was specified -> we take this as the base value if (axisInput->axis() != -1) axisValue += physicalDeviceBackend->processedAxisValue(axisInput->axis()); else if (!buttons.isEmpty()) { // TO DO: Linear Curver for the progression of the scale value if (anyOfRequiredButtonsPressed(buttons, physicalDeviceBackend)) - axisValue += axisInput->scale(); + axisValue += buttonAxisInput->scale(); } } } diff --git a/src/input/frontend/frontend.pri b/src/input/frontend/frontend.pri index ba237b420..8cf3d5fa9 100644 --- a/src/input/frontend/frontend.pri +++ b/src/input/frontend/frontend.pri @@ -16,6 +16,7 @@ HEADERS += \ $$PWD/qaction.h \ $$PWD/qaxisinput.h \ $$PWD/qaxis.h \ + $$PWD/qbuttonaxisinput.h \ $$PWD/qlogicaldevice.h \ $$PWD/qinputdeviceintegration.h \ $$PWD/qinputdeviceintegration_p.h \ @@ -33,6 +34,7 @@ HEADERS += \ $$PWD/qactioninput_p.h \ $$PWD/qaxis_p.h \ $$PWD/qaxisinput_p.h \ + $$PWD/qbuttonaxisinput_p.h \ $$PWD/qlogicaldevice_p.h \ $$PWD/qaxissetting_p.h \ $$PWD/qinputsequence_p.h \ @@ -54,6 +56,7 @@ SOURCES += \ $$PWD/qaction.cpp \ $$PWD/qaxisinput.cpp \ $$PWD/qaxis.cpp \ + $$PWD/qbuttonaxisinput.cpp \ $$PWD/qlogicaldevice.cpp \ $$PWD/qinputdeviceintegration.cpp \ $$PWD/qabstractphysicaldevice.cpp \ diff --git a/src/input/frontend/qaxisinput.cpp b/src/input/frontend/qaxisinput.cpp index e5cb0c054..9c2f30d43 100644 --- a/src/input/frontend/qaxisinput.cpp +++ b/src/input/frontend/qaxisinput.cpp @@ -67,6 +67,11 @@ QAxisInput::QAxisInput(Qt3DCore::QNode *parent) { } +QAxisInput::QAxisInput(QAxisInputPrivate &dd, Qt3DCore::QNode *parent) + : QNode(dd, parent) +{ +} + void QAxisInput::setSourceDevice(QAbstractPhysicalDevice *sourceDevice) { Q_D(QAxisInput); @@ -86,21 +91,6 @@ QAbstractPhysicalDevice *QAxisInput::sourceDevice() const return d->m_sourceDevice; } -void QAxisInput::setScale(float scale) -{ - Q_D(QAxisInput); - if (d->m_scale != scale) { - d->m_scale = scale; - emit scaleChanged(scale); - } -} - -float QAxisInput::scale() const -{ - Q_D(const QAxisInput); - return d->m_scale; -} - void QAxisInput::setAxis(int axis) { Q_D(QAxisInput); @@ -116,21 +106,6 @@ int QAxisInput::axis() const return d->m_axis; } -void QAxisInput::setButtons(const QVariantList &buttons) -{ - Q_D(QAxisInput); - if (buttons != d->m_buttons) { - d->m_buttons = buttons; - emit buttonsChanged(buttons); - } -} - -QVariantList QAxisInput::buttons() const -{ - Q_D(const QAxisInput); - return d->m_buttons; -} - Qt3DCore::QNodeCreatedChangeBasePtr QAxisInput::createNodeCreationChange() const { auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QAxisInputData>::create(this); @@ -139,8 +114,6 @@ Qt3DCore::QNodeCreatedChangeBasePtr QAxisInput::createNodeCreationChange() const Q_D(const QAxisInput); data.sourceDeviceId = qIdForNode(d->m_sourceDevice); data.axis = d->m_axis; - data.buttons = d->m_buttons; - data.scale = d->m_scale; return creationChange; } diff --git a/src/input/frontend/qaxisinput.h b/src/input/frontend/qaxisinput.h index 1156011e3..da840f25a 100644 --- a/src/input/frontend/qaxisinput.h +++ b/src/input/frontend/qaxisinput.h @@ -55,29 +55,24 @@ class QT3DINPUTSHARED_EXPORT QAxisInput : public Qt3DCore::QNode { Q_OBJECT Q_PROPERTY(Qt3DInput::QAbstractPhysicalDevice *sourceDevice READ sourceDevice WRITE setSourceDevice NOTIFY sourceDeviceChanged) - Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged) Q_PROPERTY(int axis READ axis WRITE setAxis NOTIFY axisChanged) - Q_PROPERTY(QVariantList buttons READ buttons WRITE setButtons NOTIFY buttonsChanged) public: explicit QAxisInput(Qt3DCore::QNode *parent = nullptr); QAbstractPhysicalDevice *sourceDevice() const; - float scale() const; int axis() const; - QVariantList buttons() const; public Q_SLOTS: void setSourceDevice(QAbstractPhysicalDevice *sourceDevice); - void setScale(float scale); void setAxis(int axis); - void setButtons(const QVariantList &buttons); Q_SIGNALS: void sourceDeviceChanged(QAbstractPhysicalDevice *sourceDevice); - void scaleChanged(float scale); void axisChanged(int axis); - void buttonsChanged(const QVariantList &buttons); + +protected: + QAxisInput(QAxisInputPrivate &dd, QNode *parent = nullptr); private: Q_DECLARE_PRIVATE(QAxisInput) diff --git a/src/input/frontend/qaxisinput_p.h b/src/input/frontend/qaxisinput_p.h index 36087564d..cb025ff50 100644 --- a/src/input/frontend/qaxisinput_p.h +++ b/src/input/frontend/qaxisinput_p.h @@ -67,22 +67,17 @@ public: QAxisInputPrivate() : Qt3DCore::QNodePrivate() , m_sourceDevice(nullptr) - , m_scale(0.0f) , m_axis(-1) {} - QVariantList m_buttons; QAbstractPhysicalDevice *m_sourceDevice; - float m_scale; int m_axis; }; struct QAxisInputData { Qt3DCore::QNodeId sourceDeviceId; - QVariantList buttons; // TODO: Replace with QVector<int> int axis; - float scale; }; } // Qt3DInput diff --git a/src/input/frontend/qbuttonaxisinput.cpp b/src/input/frontend/qbuttonaxisinput.cpp new file mode 100644 index 000000000..cd74cc8da --- /dev/null +++ b/src/input/frontend/qbuttonaxisinput.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbuttonaxisinput.h" +#include "qbuttonaxisinput_p.h" +#include <Qt3DInput/qabstractphysicaldevice.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DInput { + +/*! + * \qmltype ButtonAxisInput + * \instantiates Qt3DInput::QButtonAxisInput + * \inqmlmodule Qt3D.Input + * \since 5.7 + * \TODO + * + */ + +/*! + * \class Qt3DInput::QButtonAxisInput + * \inmodule Qt3DInput + * \since 5.7 + * \TODO + * + */ +QButtonAxisInput::QButtonAxisInput(Qt3DCore::QNode *parent) + : QAxisInput(*new QButtonAxisInputPrivate, parent) +{ +} + +void QButtonAxisInput::setScale(float scale) +{ + Q_D(QButtonAxisInput); + if (d->m_scale != scale) { + d->m_scale = scale; + emit scaleChanged(scale); + } +} + +float QButtonAxisInput::scale() const +{ + Q_D(const QButtonAxisInput); + return d->m_scale; +} + +void QButtonAxisInput::setButtons(const QVariantList &buttons) +{ + Q_D(QButtonAxisInput); + if (buttons != d->m_buttons) { + d->m_buttons = buttons; + emit buttonsChanged(buttons); + } +} + +QVariantList QButtonAxisInput::buttons() const +{ + Q_D(const QButtonAxisInput); + return d->m_buttons; +} + +Qt3DCore::QNodeCreatedChangeBasePtr QButtonAxisInput::createNodeCreationChange() const +{ + auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QButtonAxisInputData>::create(this); + auto &data = creationChange->data; + + Q_D(const QButtonAxisInput); + data.sourceDeviceId = qIdForNode(d->m_sourceDevice); + data.axis = d->m_axis; + data.buttons = d->m_buttons; + data.scale = d->m_scale; + + return creationChange; +} + +} // Qt3DInput + +QT_END_NAMESPACE diff --git a/src/input/frontend/qbuttonaxisinput.h b/src/input/frontend/qbuttonaxisinput.h new file mode 100644 index 000000000..9dda97a78 --- /dev/null +++ b/src/input/frontend/qbuttonaxisinput.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DINPUT_QBUTTONAXISINPUT_H +#define QT3DINPUT_QBUTTONAXISINPUT_H + +#include <Qt3DInput/qt3dinput_global.h> +#include <Qt3DInput/QAxisInput> + +QT_BEGIN_NAMESPACE + +namespace Qt3DInput { + +class QButtonAxisInputPrivate; + +class QT3DINPUTSHARED_EXPORT QButtonAxisInput : public QAxisInput +{ + Q_OBJECT + Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged) + Q_PROPERTY(QVariantList buttons READ buttons WRITE setButtons NOTIFY buttonsChanged) + +public: + explicit QButtonAxisInput(Qt3DCore::QNode *parent = nullptr); + + float scale() const; + QVariantList buttons() const; + +public Q_SLOTS: + void setScale(float scale); + void setButtons(const QVariantList &buttons); + +Q_SIGNALS: + void scaleChanged(float scale); + void buttonsChanged(const QVariantList &buttons); + +private: + Q_DECLARE_PRIVATE(QButtonAxisInput) + Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE; +}; + +} // Qt3DInput + +QT_END_NAMESPACE + +#endif // QT3DINPUT_QBUTTONAXISINPUT_H diff --git a/src/input/frontend/qbuttonaxisinput_p.h b/src/input/frontend/qbuttonaxisinput_p.h new file mode 100644 index 000000000..53f2df698 --- /dev/null +++ b/src/input/frontend/qbuttonaxisinput_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DINPUT_QBUTTONAXISINPUT_P_H +#define QT3DINPUT_QBUTTONAXISINPUT_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 <Qt3DInput/private/qaxisinput_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DInput { + +class QButtonAxisInputPrivate : public QAxisInputPrivate +{ +public: + QButtonAxisInputPrivate() + : QAxisInputPrivate() + , m_scale(0.0f) + {} + + QVariantList m_buttons; + float m_scale; +}; + +struct QButtonAxisInputData : public QAxisInputData +{ + QVariantList buttons; // TODO: Replace with QVector<int> + float scale; +}; + +} // Qt3DInput + +QT_END_NAMESPACE + +#endif // QT3DINPUT_QBUTTONAXISINPUT_P_H + diff --git a/src/input/frontend/qinputaspect.cpp b/src/input/frontend/qinputaspect.cpp index e78b65057..0169be233 100644 --- a/src/input/frontend/qinputaspect.cpp +++ b/src/input/frontend/qinputaspect.cpp @@ -40,6 +40,7 @@ #include "qinputaspect.h" #include "qinputaspect_p.h" #include "inputhandler_p.h" +#include "buttonaxisinput_p.h" #include "keyboarddevice_p.h" #include "keyboardhandler_p.h" #include "mousedevice_p.h" @@ -64,6 +65,7 @@ #include <Qt3DInput/qaxisinput.h> #include <Qt3DInput/qaxissetting.h> #include <Qt3DInput/qactioninput.h> +#include <Qt3DInput/qbuttonaxisinput.h> #include <Qt3DInput/qinputchord.h> #include <Qt3DInput/qinputsequence.h> #include <Qt3DInput/qlogicaldevice.h> @@ -117,6 +119,7 @@ QInputAspect::QInputAspect(QObject *parent) registerBackendType<QMouseHandler>(QBackendNodeMapperPtr(new Input::MouseHandlerFunctor(d_func()->m_inputHandler.data()))); registerBackendType<QAxis>(QBackendNodeMapperPtr(new Input::InputNodeFunctor<Input::Axis, Input::AxisManager>(d_func()->m_inputHandler->axisManager()))); registerBackendType<QAxisInput>(QBackendNodeMapperPtr(new Input::InputNodeFunctor<Input::AxisInput, Input::AxisInputManager>(d_func()->m_inputHandler->axisInputManager()))); + registerBackendType<QButtonAxisInput>(QBackendNodeMapperPtr(new Input::InputNodeFunctor<Input::ButtonAxisInput, Input::ButtonAxisInputManager>(d_func()->m_inputHandler->buttonAxisInputManager()))); registerBackendType<QAxisSetting>(QBackendNodeMapperPtr(new Input::InputNodeFunctor<Input::AxisSetting, Input::AxisSettingManager>(d_func()->m_inputHandler->axisSettingManager()))); registerBackendType<Qt3DInput::QAction>(QBackendNodeMapperPtr(new Input::InputNodeFunctor<Input::Action, Input::ActionManager>(d_func()->m_inputHandler->actionManager()))); registerBackendType<QActionInput>(QBackendNodeMapperPtr(new Input::InputNodeFunctor<Input::ActionInput, Input::ActionInputManager>(d_func()->m_inputHandler->actionInputManager()))); diff --git a/src/quick3d/imports/extras/defaults/qml/FirstPersonCameraController.qml b/src/quick3d/imports/extras/defaults/qml/FirstPersonCameraController.qml index e6950140d..f1c09c5d6 100644 --- a/src/quick3d/imports/extras/defaults/qml/FirstPersonCameraController.qml +++ b/src/quick3d/imports/extras/defaults/qml/FirstPersonCameraController.qml @@ -120,12 +120,12 @@ Entity { // Translation Axis { id: txAxis - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_Left] scale: -1.0 } - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_Right] scale: 1.0 @@ -133,12 +133,12 @@ Entity { }, Axis { id: tzAxis - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_Up] scale: 1.0 } - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_Down] scale: -1.0 @@ -146,12 +146,12 @@ Entity { }, Axis { id: tyAxis - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_PageUp] scale: 1.0 } - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_PageDown] scale: -1.0 diff --git a/src/quick3d/imports/extras/defaults/qml/OrbitController.qml b/src/quick3d/imports/extras/defaults/qml/OrbitController.qml index bba114730..3673a8d60 100644 --- a/src/quick3d/imports/extras/defaults/qml/OrbitController.qml +++ b/src/quick3d/imports/extras/defaults/qml/OrbitController.qml @@ -147,12 +147,12 @@ Entity { // Keyboard Axis { id: keyboardXAxis - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_Left] scale: -1.0 } - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_Right] scale: 1.0 @@ -160,12 +160,12 @@ Entity { }, Axis { id: keyboardZAxis - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_Up] scale: d.shiftPressed ? 1.0 : 0.0 } - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_Down] scale: d.shiftPressed ? -1.0 : 0.0 @@ -173,12 +173,12 @@ Entity { }, Axis { id: keyboardYAxis - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_Up] scale: d.shiftPressed ? 0.0 : 1.0 } - AxisInput { + ButtonAxisInput { sourceDevice: keyboardSourceDevice buttons: [Qt.Key_Down] scale: d.shiftPressed ? 0.0 : -1.0 diff --git a/src/quick3d/imports/input/qt3dquick3dinputplugin.cpp b/src/quick3d/imports/input/qt3dquick3dinputplugin.cpp index 108dabc83..25b4ae276 100644 --- a/src/quick3d/imports/input/qt3dquick3dinputplugin.cpp +++ b/src/quick3d/imports/input/qt3dquick3dinputplugin.cpp @@ -50,6 +50,7 @@ #include <Qt3DInput/qaxissetting.h> #include <Qt3DInput/qaction.h> #include <Qt3DInput/qactioninput.h> +#include <Qt3DInput/qbuttonaxisinput.h> #include <Qt3DInput/qinputsequence.h> #include <Qt3DInput/qinputchord.h> #include <Qt3DInput/qlogicaldevice.h> @@ -88,6 +89,7 @@ void Qt3DQuick3DInputPlugin::registerTypes(const char *uri) qmlRegisterType<Qt3DInput::QActionInput>(uri, 2, 0, "ActionInput"); qmlRegisterType<Qt3DInput::QAxisInput>(uri, 2, 0, "AxisInput"); qmlRegisterType<Qt3DInput::QAxisSetting>(uri, 2, 0, "AxisSetting"); + qmlRegisterType<Qt3DInput::QButtonAxisInput>(uri, 2, 0, "ButtonAxisInput"); qmlRegisterExtendedType<Qt3DInput::QAxis, Qt3DInput::Input::Quick::Quick3DAxis>(uri, 2, 0, "Axis"); qmlRegisterExtendedType<Qt3DInput::QAction, Qt3DInput::Input::Quick::Quick3DAction>(uri, 2, 0, "Action"); qmlRegisterExtendedType<Qt3DInput::QInputSequence, Qt3DInput::Input::Quick::Quick3DInputSequence>(uri, 2, 0, "InputSequence"); |