| 1 | // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | #include "qaxis.h" |
| 4 | #include "qaxis_p.h" |
| 5 | |
| 6 | #include <Qt3DInput/qabstractaxisinput.h> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | namespace Qt3DInput { |
| 11 | |
| 12 | /*! |
| 13 | Constructs a new QAxis instance with \a parent. |
| 14 | \class Qt3DInput::QAxis |
| 15 | \inmodule Qt3DInput |
| 16 | \inherits Qt3DCore::QNode |
| 17 | \brief QAxis stores QAbstractAxisInputs used to trigger an input event. |
| 18 | \since 5.7 |
| 19 | */ |
| 20 | |
| 21 | /*! |
| 22 | \qmltype Axis |
| 23 | \inqmlmodule Qt3D.Input |
| 24 | \nativetype Qt3DInput::QAxis |
| 25 | \brief QML frontend for the Qt3DInput::QAxis C++ class. |
| 26 | |
| 27 | Links a set of AbstractAxisInputs that trigger the same event. |
| 28 | \since 5.7 |
| 29 | */ |
| 30 | |
| 31 | /*! |
| 32 | \qmlproperty int QAxis::value |
| 33 | \readonly |
| 34 | |
| 35 | Holds the value of the axis. |
| 36 | |
| 37 | Note this property is not updated when the axis is disabled. |
| 38 | */ |
| 39 | |
| 40 | /*! |
| 41 | Constructs a new QAxis instance with parent \a parent. |
| 42 | */ |
| 43 | QAxis::QAxis(Qt3DCore::QNode *parent) |
| 44 | : Qt3DCore::QNode(*new QAxisPrivate(), parent) |
| 45 | { |
| 46 | Q_D(QAxis); |
| 47 | connect(sender: this, signal: &QAxis::enabledChanged, context: this, slot: [d]() { |
| 48 | d->setValue(0.); |
| 49 | }); |
| 50 | } |
| 51 | |
| 52 | /*! \internal */ |
| 53 | QAxis::~QAxis() |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | /*! |
| 58 | \qmlproperty list<AbstractAxisInput> Qt3D.Input::Axis::inputs |
| 59 | |
| 60 | the list of AbstractAxisInput that can trigger this Axis. |
| 61 | */ |
| 62 | |
| 63 | /*! |
| 64 | QAxis::addInput |
| 65 | Adds an \a input for the axis. |
| 66 | |
| 67 | \sa Qt3DInput::QAbstractAxisInput |
| 68 | */ |
| 69 | void QAxis::addInput(QAbstractAxisInput *input) |
| 70 | { |
| 71 | Q_D(QAxis); |
| 72 | if (!d->m_inputs.contains(t: input)) { |
| 73 | d->m_inputs.push_back(t: input); |
| 74 | |
| 75 | if (!input->parent()) |
| 76 | input->setParent(this); |
| 77 | |
| 78 | // Ensures proper bookkeeping |
| 79 | d->registerDestructionHelper(node: input, func: &QAxis::removeInput, d->m_inputs); |
| 80 | d->update(); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /*! |
| 85 | \qmlproperty list<var> Qt3D.Input::Axis::buttons |
| 86 | |
| 87 | The Buttons that can trigger this Action |
| 88 | */ |
| 89 | |
| 90 | /*! |
| 91 | QAxis::removeInput |
| 92 | |
| 93 | Removes an \a input from the axis. |
| 94 | |
| 95 | \sa Qt3DInput::QAbstractAxisInput |
| 96 | */ |
| 97 | void QAxis::removeInput(QAbstractAxisInput *input) |
| 98 | { |
| 99 | Q_D(QAxis); |
| 100 | if (d->m_inputs.contains(t: input)) { |
| 101 | |
| 102 | d->update(); |
| 103 | |
| 104 | d->m_inputs.removeOne(t: input); |
| 105 | |
| 106 | // Remove bookkeeping connection |
| 107 | d->unregisterDestructionHelper(node: input); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /*! |
| 112 | QAxis::inputs |
| 113 | |
| 114 | \return vector of all inputs added to the axis. |
| 115 | */ |
| 116 | QList<QAbstractAxisInput *> QAxis::inputs() const |
| 117 | { |
| 118 | Q_D(const QAxis); |
| 119 | return d->m_inputs; |
| 120 | } |
| 121 | |
| 122 | /*! |
| 123 | \property Qt3DInput::QAxis::value |
| 124 | |
| 125 | The value of the axis. |
| 126 | */ |
| 127 | float QAxis::value() const |
| 128 | { |
| 129 | Q_D(const QAxis); |
| 130 | return d->m_value; |
| 131 | } |
| 132 | |
| 133 | } // Qt3DInput |
| 134 | |
| 135 | QT_END_NAMESPACE |
| 136 | |
| 137 | #include "moc_qaxis.cpp" |
| 138 | |