mirror of https://github.com/qt/qt3d.git
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>
This commit is contained in:
parent
617e4c7686
commit
f63397953d
|
|
@ -142,12 +142,12 @@ Entity {
|
|||
Axis {
|
||||
name: "TX"
|
||||
inputs: [
|
||||
AxisInput {
|
||||
ButtonAxisInput {
|
||||
sourceDevice: keyboardSourceDevice
|
||||
buttons: [Qt.Key_Left]
|
||||
scale: -1.0
|
||||
},
|
||||
AxisInput {
|
||||
ButtonAxisInput {
|
||||
sourceDevice: keyboardSourceDevice
|
||||
buttons: [Qt.Key_Right]
|
||||
scale: 1.0
|
||||
|
|
@ -157,12 +157,12 @@ Entity {
|
|||
Axis {
|
||||
name: "TZ"
|
||||
inputs: [
|
||||
AxisInput {
|
||||
ButtonAxisInput {
|
||||
sourceDevice: keyboardSourceDevice
|
||||
buttons: [Qt.Key_Up]
|
||||
scale: 1.0
|
||||
},
|
||||
AxisInput {
|
||||
ButtonAxisInput {
|
||||
sourceDevice: keyboardSourceDevice
|
||||
buttons: [Qt.Key_Down]
|
||||
scale: -1.0
|
||||
|
|
@ -172,12 +172,12 @@ Entity {
|
|||
Axis {
|
||||
name: "TY"
|
||||
inputs: [
|
||||
AxisInput {
|
||||
ButtonAxisInput {
|
||||
sourceDevice: keyboardSourceDevice
|
||||
buttons: [Qt.Key_PageUp]
|
||||
scale: 1.0
|
||||
},
|
||||
AxisInput {
|
||||
ButtonAxisInput {
|
||||
sourceDevice: keyboardSourceDevice
|
||||
buttons: [Qt.Key_PageDown]
|
||||
scale: -1.0
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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())));
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -36,18 +36,6 @@
|
|||
#include <Qt3DCore/qnodepropertychange.h>
|
||||
#include "testdevice.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void compareKeys(const QVector<int> &backendKeys, const QVariantList &frontendKeys)
|
||||
{
|
||||
QCOMPARE(backendKeys.size(), frontendKeys.size());
|
||||
for (int i = 0, m = backendKeys.size(); i < m; ++i) {
|
||||
QCOMPARE(backendKeys.at(i), frontendKeys.at(i).toInt());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class tst_AxisInput : public Qt3DCore::QBackendNodeTester
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -61,9 +49,7 @@ private Q_SLOTS:
|
|||
Qt3DInput::QAxisInput axisInput;
|
||||
TestDevice sourceDevice;
|
||||
|
||||
axisInput.setButtons(QVariantList() << QVariant(1 << 8));
|
||||
axisInput.setAxis(327);
|
||||
axisInput.setScale(0.5f);
|
||||
axisInput.setSourceDevice(&sourceDevice);
|
||||
|
||||
// WHEN
|
||||
|
|
@ -72,9 +58,7 @@ private Q_SLOTS:
|
|||
// THEN
|
||||
QCOMPARE(backendAxisInput.peerId(), axisInput.id());
|
||||
QCOMPARE(backendAxisInput.isEnabled(), axisInput.isEnabled());
|
||||
compareKeys(backendAxisInput.buttons(), axisInput.buttons());
|
||||
QCOMPARE(backendAxisInput.axis(), axisInput.axis());
|
||||
QCOMPARE(backendAxisInput.scale(), axisInput.scale());
|
||||
QCOMPARE(backendAxisInput.sourceDevice(), sourceDevice.id());
|
||||
}
|
||||
|
||||
|
|
@ -85,8 +69,6 @@ private Q_SLOTS:
|
|||
|
||||
// THEN
|
||||
QVERIFY(backendAxisInput.peerId().isNull());
|
||||
QCOMPARE(backendAxisInput.scale(), 0.0f);
|
||||
QVERIFY(backendAxisInput.buttons().isEmpty());
|
||||
QCOMPARE(backendAxisInput.axis(), 0);
|
||||
QCOMPARE(backendAxisInput.isEnabled(), false);
|
||||
QCOMPARE(backendAxisInput.sourceDevice(), Qt3DCore::QNodeId());
|
||||
|
|
@ -95,9 +77,7 @@ private Q_SLOTS:
|
|||
Qt3DInput::QAxisInput axisInput;
|
||||
TestDevice sourceDevice;
|
||||
|
||||
axisInput.setButtons(QVariantList() << QVariant(1 << 8));
|
||||
axisInput.setAxis(327);
|
||||
axisInput.setScale(0.5f);
|
||||
axisInput.setSourceDevice(&sourceDevice);
|
||||
|
||||
// WHEN
|
||||
|
|
@ -106,8 +86,6 @@ private Q_SLOTS:
|
|||
|
||||
// THEN
|
||||
QVERIFY(backendAxisInput.peerId().isNull());
|
||||
QCOMPARE(backendAxisInput.scale(), 0.0f);
|
||||
QVERIFY(backendAxisInput.buttons().isEmpty());
|
||||
QCOMPARE(backendAxisInput.axis(), 0);
|
||||
QCOMPARE(backendAxisInput.isEnabled(), false);
|
||||
QCOMPARE(backendAxisInput.sourceDevice(), Qt3DCore::QNodeId());
|
||||
|
|
@ -127,24 +105,6 @@ private Q_SLOTS:
|
|||
// THEN
|
||||
QCOMPARE(backendAxisInput.axis(), 32);
|
||||
|
||||
// WHEN
|
||||
updateChange.reset(new Qt3DCore::QNodePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId()));
|
||||
updateChange->setValue(QVariantList() << QVariant(64));
|
||||
updateChange->setPropertyName("buttons");
|
||||
backendAxisInput.sceneChangeEvent(updateChange);
|
||||
|
||||
// THEN
|
||||
compareKeys(backendAxisInput.buttons(), QVariantList() << QVariant(64));
|
||||
|
||||
// WHEN
|
||||
updateChange.reset(new Qt3DCore::QNodePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId()));
|
||||
updateChange->setValue(0.5f);
|
||||
updateChange->setPropertyName("scale");
|
||||
backendAxisInput.sceneChangeEvent(updateChange);
|
||||
|
||||
// THEN
|
||||
QCOMPARE(backendAxisInput.scale(), 0.5f);
|
||||
|
||||
// WHEN
|
||||
updateChange.reset(new Qt3DCore::QNodePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId()));
|
||||
updateChange->setPropertyName("enabled");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
TEMPLATE = app
|
||||
|
||||
TARGET = tst_buttonaxisinput
|
||||
|
||||
QT += core-private 3dcore 3dcore-private 3dinput 3dinput-private testlib
|
||||
|
||||
CONFIG += testcase
|
||||
|
||||
SOURCES += tst_buttonaxisinput.cpp
|
||||
|
||||
include(../../core/common/common.pri)
|
||||
include(../commons/commons.pri)
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** 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:GPL-EXCEPT$
|
||||
** 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 General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** 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-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtTest/QTest>
|
||||
#include <qbackendnodetester.h>
|
||||
#include <Qt3DCore/private/qnode_p.h>
|
||||
#include <Qt3DCore/private/qscene_p.h>
|
||||
#include <Qt3DCore/qnodepropertychange.h>
|
||||
#include <Qt3DInput/private/buttonaxisinput_p.h>
|
||||
#include <Qt3DInput/QButtonAxisInput>
|
||||
#include <Qt3DCore/qnodepropertychange.h>
|
||||
#include "testdevice.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void compareKeys(const QVector<int> &backendKeys, const QVariantList &frontendKeys)
|
||||
{
|
||||
QCOMPARE(backendKeys.size(), frontendKeys.size());
|
||||
for (int i = 0, m = backendKeys.size(); i < m; ++i) {
|
||||
QCOMPARE(backendKeys.at(i), frontendKeys.at(i).toInt());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class tst_ButtonAxisInput: public Qt3DCore::QBackendNodeTester
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
void checkPeerPropertyMirroring()
|
||||
{
|
||||
// GIVEN
|
||||
Qt3DInput::Input::ButtonAxisInput backendAxisInput;
|
||||
Qt3DInput::QButtonAxisInput axisInput;
|
||||
TestDevice sourceDevice;
|
||||
|
||||
axisInput.setButtons(QVariantList() << QVariant(1 << 8));
|
||||
axisInput.setAxis(327);
|
||||
axisInput.setScale(0.5f);
|
||||
axisInput.setSourceDevice(&sourceDevice);
|
||||
|
||||
// WHEN
|
||||
simulateInitialization(&axisInput, &backendAxisInput);
|
||||
|
||||
// THEN
|
||||
QCOMPARE(backendAxisInput.peerId(), axisInput.id());
|
||||
QCOMPARE(backendAxisInput.isEnabled(), axisInput.isEnabled());
|
||||
compareKeys(backendAxisInput.buttons(), axisInput.buttons());
|
||||
QCOMPARE(backendAxisInput.axis(), axisInput.axis());
|
||||
QCOMPARE(backendAxisInput.scale(), axisInput.scale());
|
||||
QCOMPARE(backendAxisInput.sourceDevice(), sourceDevice.id());
|
||||
}
|
||||
|
||||
void checkInitialAndCleanedUpState()
|
||||
{
|
||||
// GIVEN
|
||||
Qt3DInput::Input::ButtonAxisInput backendAxisInput;
|
||||
|
||||
// THEN
|
||||
QVERIFY(backendAxisInput.peerId().isNull());
|
||||
QCOMPARE(backendAxisInput.scale(), 0.0f);
|
||||
QVERIFY(backendAxisInput.buttons().isEmpty());
|
||||
QCOMPARE(backendAxisInput.axis(), 0);
|
||||
QCOMPARE(backendAxisInput.isEnabled(), false);
|
||||
QCOMPARE(backendAxisInput.sourceDevice(), Qt3DCore::QNodeId());
|
||||
|
||||
// GIVEN
|
||||
Qt3DInput::QButtonAxisInput axisInput;
|
||||
TestDevice sourceDevice;
|
||||
|
||||
axisInput.setButtons(QVariantList() << QVariant(1 << 8));
|
||||
axisInput.setAxis(327);
|
||||
axisInput.setScale(0.5f);
|
||||
axisInput.setSourceDevice(&sourceDevice);
|
||||
|
||||
// WHEN
|
||||
backendAxisInput.updateFromPeer(&axisInput);
|
||||
backendAxisInput.cleanup();
|
||||
|
||||
// THEN
|
||||
QVERIFY(backendAxisInput.peerId().isNull());
|
||||
QCOMPARE(backendAxisInput.scale(), 0.0f);
|
||||
QVERIFY(backendAxisInput.buttons().isEmpty());
|
||||
QCOMPARE(backendAxisInput.axis(), 0);
|
||||
QCOMPARE(backendAxisInput.isEnabled(), false);
|
||||
QCOMPARE(backendAxisInput.sourceDevice(), Qt3DCore::QNodeId());
|
||||
}
|
||||
|
||||
void checkPropertyChanges()
|
||||
{
|
||||
// GIVEN
|
||||
Qt3DInput::Input::ButtonAxisInput backendAxisInput;
|
||||
|
||||
|
||||
// WHEN
|
||||
Qt3DCore::QNodePropertyChangePtr updateChange(new Qt3DCore::QNodePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId()));
|
||||
updateChange->setValue(32);
|
||||
updateChange->setPropertyName("axis");
|
||||
backendAxisInput.sceneChangeEvent(updateChange);
|
||||
|
||||
// THEN
|
||||
QCOMPARE(backendAxisInput.axis(), 32);
|
||||
|
||||
// WHEN
|
||||
updateChange.reset(new Qt3DCore::QNodePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId()));
|
||||
updateChange->setValue(QVariantList() << QVariant(64));
|
||||
updateChange->setPropertyName("buttons");
|
||||
backendAxisInput.sceneChangeEvent(updateChange);
|
||||
|
||||
// THEN
|
||||
compareKeys(backendAxisInput.buttons(), QVariantList() << QVariant(64));
|
||||
|
||||
// WHEN
|
||||
updateChange.reset(new Qt3DCore::QNodePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId()));
|
||||
updateChange->setValue(0.5f);
|
||||
updateChange->setPropertyName("scale");
|
||||
backendAxisInput.sceneChangeEvent(updateChange);
|
||||
|
||||
// THEN
|
||||
QCOMPARE(backendAxisInput.scale(), 0.5f);
|
||||
|
||||
// WHEN
|
||||
updateChange.reset(new Qt3DCore::QNodePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId()));
|
||||
updateChange->setPropertyName("enabled");
|
||||
updateChange->setValue(true);
|
||||
backendAxisInput.sceneChangeEvent(updateChange);
|
||||
|
||||
// THEN
|
||||
QCOMPARE(backendAxisInput.isEnabled(), true);
|
||||
|
||||
// WHEN
|
||||
TestDevice device;
|
||||
updateChange.reset(new Qt3DCore::QNodePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId()));
|
||||
updateChange->setPropertyName("sourceDevice");
|
||||
updateChange->setValue(QVariant::fromValue(device.id()));
|
||||
backendAxisInput.sceneChangeEvent(updateChange);
|
||||
|
||||
// THEN
|
||||
QCOMPARE(backendAxisInput.sourceDevice(), device.id());
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_ButtonAxisInput)
|
||||
|
||||
#include "tst_buttonaxisinput.moc"
|
||||
|
|
@ -4,10 +4,12 @@ contains(QT_CONFIG, private_tests) {
|
|||
SUBDIRS += \
|
||||
qaxis \
|
||||
qaction \
|
||||
qaxisinput \
|
||||
qactioninput \
|
||||
qaxisinput \
|
||||
qbuttonaxisinput \
|
||||
qlogicaldevice \
|
||||
axis \
|
||||
action \
|
||||
axisinput
|
||||
axisinput \
|
||||
buttonaxisinput
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,19 +55,15 @@ private Q_SLOTS:
|
|||
Qt3DInput::QAxisInput *defaultConstructed = new Qt3DInput::QAxisInput();
|
||||
QTest::newRow("defaultConstructed") << defaultConstructed;
|
||||
|
||||
Qt3DInput::QAxisInput *axisInputWithKeysAndAxis = new Qt3DInput::QAxisInput();
|
||||
axisInputWithKeysAndAxis->setButtons(QVariantList() << QVariant((1 << 1) | (1 << 5)));
|
||||
axisInputWithKeysAndAxis->setAxis(383);
|
||||
axisInputWithKeysAndAxis->setScale(327.0f);
|
||||
QTest::newRow("axisInputWithKeys") << axisInputWithKeysAndAxis;
|
||||
Qt3DInput::QAxisInput *axisInputWithAxis = new Qt3DInput::QAxisInput();
|
||||
axisInputWithAxis->setAxis(383);
|
||||
QTest::newRow("axisInputWithAxis") << axisInputWithAxis;
|
||||
|
||||
Qt3DInput::QAxisInput *axisInputWithKeysAndSourceDevice = new Qt3DInput::QAxisInput();
|
||||
Qt3DInput::QAxisInput *axisInputWithAxisAndSourceDevice = new Qt3DInput::QAxisInput();
|
||||
TestDevice *device = new TestDevice();
|
||||
axisInputWithKeysAndSourceDevice->setButtons(QVariantList() << QVariant((1 << 1) | (1 << 5)));
|
||||
axisInputWithKeysAndSourceDevice->setSourceDevice(device);
|
||||
axisInputWithKeysAndSourceDevice->setAxis(427);
|
||||
axisInputWithKeysAndAxis->setScale(355.0f);
|
||||
QTest::newRow("axisInputWithKeysAndSourceDevice") << axisInputWithKeysAndSourceDevice;
|
||||
axisInputWithAxisAndSourceDevice->setSourceDevice(device);
|
||||
axisInputWithAxisAndSourceDevice->setAxis(427);
|
||||
QTest::newRow("axisInputWithAxisAndSourceDevice") << axisInputWithAxisAndSourceDevice;
|
||||
}
|
||||
|
||||
void checkCloning()
|
||||
|
|
@ -90,9 +86,7 @@ private Q_SLOTS:
|
|||
QCOMPARE(axisInput->id(), creationChangeData->subjectId());
|
||||
QCOMPARE(axisInput->isEnabled(), creationChangeData->isNodeEnabled());
|
||||
QCOMPARE(axisInput->metaObject(), creationChangeData->metaObject());
|
||||
QCOMPARE(axisInput->buttons(), cloneData.buttons);
|
||||
QCOMPARE(axisInput->axis(), cloneData.axis);
|
||||
QCOMPARE(axisInput->scale(), cloneData.scale);
|
||||
QCOMPARE(axisInput->sourceDevice() ? axisInput->sourceDevice()->id() : Qt3DCore::QNodeId(), cloneData.sourceDeviceId);
|
||||
}
|
||||
|
||||
|
|
@ -102,40 +96,13 @@ private Q_SLOTS:
|
|||
QScopedPointer<Qt3DInput::QAxisInput> axisInput(new Qt3DInput::QAxisInput());
|
||||
TestArbiter arbiter(axisInput.data());
|
||||
|
||||
// WHEN
|
||||
QVariantList buttons = QVariantList() << QVariant(555);
|
||||
axisInput->setButtons(buttons);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
// THEN
|
||||
QCOMPARE(arbiter.events.size(), 1);
|
||||
Qt3DCore::QNodePropertyChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QNodePropertyChange>();
|
||||
QCOMPARE(change->propertyName(), "buttons");
|
||||
QCOMPARE(change->value().toList(), buttons);
|
||||
QCOMPARE(change->type(), Qt3DCore::NodeUpdated);
|
||||
|
||||
arbiter.events.clear();
|
||||
|
||||
// WHEN
|
||||
axisInput->setScale(1340.0f);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
// THEN
|
||||
QCOMPARE(arbiter.events.size(), 1);
|
||||
change = arbiter.events.first().staticCast<Qt3DCore::QNodePropertyChange>();
|
||||
QCOMPARE(change->propertyName(), "scale");
|
||||
QCOMPARE(change->value().toFloat(), 1340.0f);
|
||||
QCOMPARE(change->type(), Qt3DCore::NodeUpdated);
|
||||
|
||||
arbiter.events.clear();
|
||||
|
||||
// WHEN
|
||||
axisInput->setAxis(350);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
// THEN
|
||||
QCOMPARE(arbiter.events.size(), 1);
|
||||
change = arbiter.events.first().staticCast<Qt3DCore::QNodePropertyChange>();
|
||||
Qt3DCore::QNodePropertyChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QNodePropertyChange>();
|
||||
QCOMPARE(change->propertyName(), "axis");
|
||||
QCOMPARE(change->value().toInt(), 350);
|
||||
QCOMPARE(change->type(), Qt3DCore::NodeUpdated);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
TEMPLATE = app
|
||||
|
||||
TARGET = tst_qbuttonaxisinput
|
||||
|
||||
QT += core-private 3dcore 3dcore-private 3dinput 3dinput-private testlib
|
||||
|
||||
CONFIG += testcase
|
||||
|
||||
SOURCES += tst_qbuttonaxisinput.cpp
|
||||
|
||||
include(../../render/commons/commons.pri)
|
||||
include(../commons/commons.pri)
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 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:GPL-EXCEPT$
|
||||
** 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 General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** 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-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtTest/QTest>
|
||||
#include <Qt3DCore/private/qnode_p.h>
|
||||
#include <Qt3DCore/private/qscene_p.h>
|
||||
#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
|
||||
|
||||
#include <Qt3DInput/QAbstractPhysicalDevice>
|
||||
#include <Qt3DInput/QButtonAxisInput>
|
||||
#include <Qt3DInput/private/qbuttonaxisinput_p.h>
|
||||
|
||||
#include "testpostmanarbiter.h"
|
||||
#include "testdevice.h"
|
||||
|
||||
class tst_QButtonAxisInput: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
tst_QButtonAxisInput()
|
||||
{
|
||||
qRegisterMetaType<Qt3DInput::QAbstractPhysicalDevice*>("Qt3DInput::QAbstractPhysicalDevice*");
|
||||
}
|
||||
|
||||
private Q_SLOTS:
|
||||
void checkCloning_data()
|
||||
{
|
||||
QTest::addColumn<Qt3DInput::QButtonAxisInput *>("axisInput");
|
||||
|
||||
Qt3DInput::QButtonAxisInput *defaultConstructed = new Qt3DInput::QButtonAxisInput();
|
||||
QTest::newRow("defaultConstructed") << defaultConstructed;
|
||||
|
||||
Qt3DInput::QButtonAxisInput *axisInputWithKeysAndAxis = new Qt3DInput::QButtonAxisInput();
|
||||
axisInputWithKeysAndAxis->setButtons(QVariantList() << QVariant((1 << 1) | (1 << 5)));
|
||||
axisInputWithKeysAndAxis->setAxis(383);
|
||||
axisInputWithKeysAndAxis->setScale(327.0f);
|
||||
QTest::newRow("axisInputWithKeys") << axisInputWithKeysAndAxis;
|
||||
|
||||
Qt3DInput::QButtonAxisInput *axisInputWithKeysAndSourceDevice = new Qt3DInput::QButtonAxisInput();
|
||||
TestDevice *device = new TestDevice();
|
||||
axisInputWithKeysAndSourceDevice->setButtons(QVariantList() << QVariant((1 << 1) | (1 << 5)));
|
||||
axisInputWithKeysAndSourceDevice->setSourceDevice(device);
|
||||
axisInputWithKeysAndSourceDevice->setAxis(427);
|
||||
axisInputWithKeysAndSourceDevice->setScale(355.0f);
|
||||
QTest::newRow("axisInputWithKeysAndSourceDevice") << axisInputWithKeysAndSourceDevice;
|
||||
}
|
||||
|
||||
void checkCloning()
|
||||
{
|
||||
// GIVEN
|
||||
QFETCH(Qt3DInput::QButtonAxisInput *, axisInput);
|
||||
|
||||
// WHEN
|
||||
Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(axisInput);
|
||||
QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges = creationChangeGenerator.creationChanges();
|
||||
|
||||
// THEN
|
||||
QCOMPARE(creationChanges.size(), 1 + (axisInput->sourceDevice() ? 1 : 0));
|
||||
|
||||
const Qt3DCore::QNodeCreatedChangePtr<Qt3DInput::QButtonAxisInputData> creationChangeData =
|
||||
qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DInput::QButtonAxisInputData>>(creationChanges.first());
|
||||
const Qt3DInput::QButtonAxisInputData &cloneData = creationChangeData->data;
|
||||
QCOMPARE(axisInput->id(), creationChangeData->subjectId());
|
||||
QCOMPARE(axisInput->isEnabled(), creationChangeData->isNodeEnabled());
|
||||
QCOMPARE(axisInput->metaObject(), creationChangeData->metaObject());
|
||||
QCOMPARE(axisInput->buttons(), cloneData.buttons);
|
||||
QCOMPARE(axisInput->axis(), cloneData.axis);
|
||||
QCOMPARE(axisInput->scale(), cloneData.scale);
|
||||
QCOMPARE(axisInput->sourceDevice() ? axisInput->sourceDevice()->id() : Qt3DCore::QNodeId(), cloneData.sourceDeviceId);
|
||||
}
|
||||
|
||||
void checkPropertyUpdates()
|
||||
{
|
||||
// GIVEN
|
||||
QScopedPointer<Qt3DInput::QButtonAxisInput> axisInput(new Qt3DInput::QButtonAxisInput());
|
||||
TestArbiter arbiter(axisInput.data());
|
||||
|
||||
// WHEN
|
||||
QVariantList buttons = QVariantList() << QVariant(555);
|
||||
axisInput->setButtons(buttons);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
// THEN
|
||||
QCOMPARE(arbiter.events.size(), 1);
|
||||
Qt3DCore::QNodePropertyChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QNodePropertyChange>();
|
||||
QCOMPARE(change->propertyName(), "buttons");
|
||||
QCOMPARE(change->value().toList(), buttons);
|
||||
QCOMPARE(change->type(), Qt3DCore::NodeUpdated);
|
||||
|
||||
arbiter.events.clear();
|
||||
|
||||
// WHEN
|
||||
axisInput->setScale(1340.0f);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
// THEN
|
||||
QCOMPARE(arbiter.events.size(), 1);
|
||||
change = arbiter.events.first().staticCast<Qt3DCore::QNodePropertyChange>();
|
||||
QCOMPARE(change->propertyName(), "scale");
|
||||
QCOMPARE(change->value().toFloat(), 1340.0f);
|
||||
QCOMPARE(change->type(), Qt3DCore::NodeUpdated);
|
||||
|
||||
arbiter.events.clear();
|
||||
|
||||
// WHEN
|
||||
axisInput->setAxis(350);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
// THEN
|
||||
QCOMPARE(arbiter.events.size(), 1);
|
||||
change = arbiter.events.first().staticCast<Qt3DCore::QNodePropertyChange>();
|
||||
QCOMPARE(change->propertyName(), "axis");
|
||||
QCOMPARE(change->value().toInt(), 350);
|
||||
QCOMPARE(change->type(), Qt3DCore::NodeUpdated);
|
||||
|
||||
arbiter.events.clear();
|
||||
|
||||
// WHEN
|
||||
TestDevice *device = new TestDevice(axisInput.data());
|
||||
QCoreApplication::processEvents();
|
||||
arbiter.events.clear();
|
||||
|
||||
axisInput->setSourceDevice(device);
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
// THEN
|
||||
QCOMPARE(arbiter.events.size(), 1);
|
||||
change = arbiter.events.first().staticCast<Qt3DCore::QNodePropertyChange>();
|
||||
QCOMPARE(change->propertyName(), "sourceDevice");
|
||||
QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), device->id());
|
||||
QCOMPARE(change->type(), Qt3DCore::NodeUpdated);
|
||||
|
||||
arbiter.events.clear();
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(tst_QButtonAxisInput)
|
||||
|
||||
#include "tst_qbuttonaxisinput.moc"
|
||||
Loading…
Reference in New Issue