1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ****************************************************************************/ |
38 | |
39 | #include "qaxis.h" |
40 | #include "qaxis_p.h" |
41 | |
42 | #include <Qt3DInput/qabstractaxisinput.h> |
43 | #include <Qt3DCore/qnodecreatedchange.h> |
44 | |
45 | QT_BEGIN_NAMESPACE |
46 | |
47 | namespace Qt3DInput { |
48 | |
49 | /*! |
50 | Constructs a new QAxis instance with \a parent. |
51 | \class Qt3DInput::QAxis |
52 | \inmodule Qt3DInput |
53 | \inherits Qt3DCore::QNode |
54 | \brief QAxis stores QAbstractAxisInputs used to trigger an input event. |
55 | \since 5.7 |
56 | */ |
57 | |
58 | /*! |
59 | \qmltype Axis |
60 | \inqmlmodule Qt3D.Input |
61 | \instantiates Qt3DInput::QAxis |
62 | \brief QML frontend for the Qt3DInput::QAxis C++ class. |
63 | |
64 | Links a set of AbstractAxisInputs that trigger the same event. |
65 | \since 5.7 |
66 | */ |
67 | |
68 | /*! |
69 | \qmlproperty int QAxis::value |
70 | \readonly |
71 | |
72 | Holds the value of the axis. |
73 | |
74 | Note this property is not updated when the axis is disabled. |
75 | */ |
76 | |
77 | /*! |
78 | Constructs a new QAxis instance with parent \a parent. |
79 | */ |
80 | QAxis::QAxis(Qt3DCore::QNode *parent) |
81 | : Qt3DCore::QNode(*new QAxisPrivate(), parent) |
82 | { |
83 | Q_D(QAxis); |
84 | connect(sender: this, signal: &QAxis::enabledChanged, slot: [d]() { |
85 | d->setValue(0.); |
86 | }); |
87 | } |
88 | |
89 | /*! \internal */ |
90 | QAxis::~QAxis() |
91 | { |
92 | } |
93 | |
94 | /*! |
95 | \qmlproperty list<AbstractAxisInput> Qt3D.Input::Axis::inputs |
96 | |
97 | the list of AbstractAxisInput that can trigger this Axis. |
98 | */ |
99 | |
100 | /*! |
101 | QAxis::addInput |
102 | Adds an \a input for the axis. |
103 | |
104 | \sa Qt3DInput::QAbstractAxisInput |
105 | */ |
106 | void QAxis::addInput(QAbstractAxisInput *input) |
107 | { |
108 | Q_D(QAxis); |
109 | if (!d->m_inputs.contains(t: input)) { |
110 | d->m_inputs.push_back(t: input); |
111 | |
112 | if (!input->parent()) |
113 | input->setParent(this); |
114 | |
115 | // Ensures proper bookkeeping |
116 | d->registerDestructionHelper(node: input, func: &QAxis::removeInput, d->m_inputs); |
117 | d->updateNode(node: input, property: "input" , change: Qt3DCore::PropertyValueAdded); |
118 | } |
119 | } |
120 | |
121 | /*! |
122 | \qmlproperty QVariantList Qt3D.Input::Axis::buttons |
123 | |
124 | The Buttons that can trigger this Action |
125 | */ |
126 | |
127 | /*! |
128 | QAxis::removeInput |
129 | |
130 | Removes an \a input from the axis. |
131 | |
132 | \sa Qt3DInput::QAbstractAxisInput |
133 | */ |
134 | void QAxis::removeInput(QAbstractAxisInput *input) |
135 | { |
136 | Q_D(QAxis); |
137 | if (d->m_inputs.contains(t: input)) { |
138 | |
139 | d->updateNode(node: input, property: "input" , change: Qt3DCore::PropertyValueRemoved); |
140 | |
141 | d->m_inputs.removeOne(t: input); |
142 | |
143 | // Remove bookkeeping connection |
144 | d->unregisterDestructionHelper(node: input); |
145 | } |
146 | } |
147 | |
148 | /*! |
149 | QAxis::inputs |
150 | |
151 | \return vector of all inputs added to the axis. |
152 | */ |
153 | QVector<QAbstractAxisInput *> QAxis::inputs() const |
154 | { |
155 | Q_D(const QAxis); |
156 | return d->m_inputs; |
157 | } |
158 | |
159 | /*! |
160 | \property QAxis::value |
161 | |
162 | The value of the axis. |
163 | */ |
164 | float QAxis::value() const |
165 | { |
166 | Q_D(const QAxis); |
167 | return d->m_value; |
168 | } |
169 | |
170 | // TODO Unused remove in Qt6 |
171 | void QAxis::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &) |
172 | { |
173 | } |
174 | |
175 | Qt3DCore::QNodeCreatedChangeBasePtr QAxis::createNodeCreationChange() const |
176 | { |
177 | auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QAxisData>::create(arguments: this); |
178 | auto &data = creationChange->data; |
179 | data.inputIds = qIdsForNodes(nodes: inputs()); |
180 | return creationChange; |
181 | } |
182 | |
183 | } // Qt3DInput |
184 | |
185 | QT_END_NAMESPACE |
186 | |