1/****************************************************************************
2**
3** Copyright (C) 2016 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
40#include "qbuttonaxisinput.h"
41#include "qbuttonaxisinput_p.h"
42
43#include <Qt3DInput/qabstractphysicaldevice.h>
44
45QT_BEGIN_NAMESPACE
46
47namespace Qt3DInput {
48
49/*!
50 * \qmltype ButtonAxisInput
51 * \instantiates Qt3DInput::QButtonAxisInput
52 * \inqmlmodule Qt3D.Input
53 * \brief QML frontend for QButtonAxisInput C++ class.
54 * \since 5.7
55 * The axis value is controlled by buttons rather than a traditional analog input such as a joystick.
56 *
57 */
58
59/*!
60 * \class Qt3DInput::QButtonAxisInput
61 * \inheaderfile Qt3DInput/QButtonAxisInput
62 * \inmodule Qt3DInput
63 * \brief An axis input controlled by buttons
64 * \since 5.7
65 * The axis value is controlled by buttons rather than a traditional analog input such as a joystick.
66 *
67 */
68/*!
69 \qmlproperty real ButtonAxisInput::scale
70 Specifies how the axis output value is scaled. No scaling is applied by default
71 so it defaults to 1.
72*/
73
74/*!
75 \qmlproperty list<var> ButtonAxisInput::buttons
76 Specifies the buttons which control the axis
77*/
78
79/*!
80 \qmlproperty real ButtonAxisInput::acceleration
81 Specifies the rate at which the axis value changes when a button is held
82*/
83
84/*!
85 \qmlproperty list<var> ButtonAxisInput::deceleration
86 Specifies the rate at which the axis value returns to normal when a button is released
87*/
88
89/*!
90 Constructs a new QButtonAxisInput instance with \a parent.
91 */
92QButtonAxisInput::QButtonAxisInput(Qt3DCore::QNode *parent)
93 : QAbstractAxisInput(*new QButtonAxisInputPrivate, parent)
94{
95}
96
97/*! \internal */
98QButtonAxisInput::~QButtonAxisInput()
99{
100}
101
102/*!
103 \property QButtonAxisInput::scale
104 Specifies how the axis output value is scaled. No scaling is applied by default
105 so it defaults to 1.
106 */
107void QButtonAxisInput::setScale(float scale)
108{
109 Q_D(QButtonAxisInput);
110 if (d->m_scale != scale) {
111 d->m_scale = scale;
112 emit scaleChanged(scale);
113 }
114}
115
116float QButtonAxisInput::scale() const
117{
118 Q_D(const QButtonAxisInput);
119 return d->m_scale;
120}
121
122/*!
123 \property QButtonAxisInput::buttons
124 Specifies the buttons which control the axis
125 */
126void QButtonAxisInput::setButtons(const QVector<int> &buttons)
127{
128 Q_D(QButtonAxisInput);
129 if (buttons != d->m_buttons) {
130 d->m_buttons = buttons;
131 emit buttonsChanged(buttons);
132 }
133}
134
135QVector<int> QButtonAxisInput::buttons() const
136{
137 Q_D(const QButtonAxisInput);
138 return d->m_buttons;
139}
140
141/*!
142 \property QButtonAxisInput::acceleration
143 Specifies the rate at which the axis value changes when a button is held
144 */
145float QButtonAxisInput::acceleration() const
146{
147 Q_D(const QButtonAxisInput);
148 return d->m_acceleration;
149}
150
151void QButtonAxisInput::setAcceleration(float acceleration)
152{
153 Q_D(QButtonAxisInput);
154 if (d->m_acceleration != acceleration) {
155 d->m_acceleration = acceleration;
156 emit accelerationChanged(acceleration);
157 }
158}
159
160/*!
161 \property QButtonAxisInput::deceleration
162 Specifies the rate at which the axis value returns to normal when a button is released
163 */
164float QButtonAxisInput::deceleration() const
165{
166 Q_D(const QButtonAxisInput);
167 return d->m_deceleration;
168}
169
170void QButtonAxisInput::setDeceleration(float deceleration)
171{
172 Q_D(QButtonAxisInput);
173 if (d->m_deceleration != deceleration) {
174 d->m_deceleration = deceleration;
175 emit decelerationChanged(deceleration);
176 }
177}
178
179Qt3DCore::QNodeCreatedChangeBasePtr QButtonAxisInput::createNodeCreationChange() const
180{
181 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QButtonAxisInputData>::create(arguments: this);
182 auto &data = creationChange->data;
183
184 Q_D(const QButtonAxisInput);
185 data.sourceDeviceId = qIdForNode(node: d->m_sourceDevice);
186 data.buttons = d->m_buttons;
187 data.scale = d->m_scale;
188 data.acceleration = d->m_acceleration;
189 data.deceleration = d->m_deceleration;
190
191 return creationChange;
192}
193
194} // Qt3DInput
195
196QT_END_NAMESPACE
197

source code of qt3d/src/input/frontend/qbuttonaxisinput.cpp