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 "qactioninput.h"
4#include "qactioninput_p.h"
5
6#include <Qt3DInput/qabstractphysicaldevice.h>
7#include <Qt3DInput/qabstractactioninput.h>
8
9QT_BEGIN_NAMESPACE
10
11namespace Qt3DInput {
12
13QActionInputPrivate::QActionInputPrivate()
14 : QAbstractActionInputPrivate(),
15 m_sourceDevice(nullptr)
16{
17}
18
19/*!
20 \class Qt3DInput::QActionInput
21 \inmodule Qt3DInput
22 \inherits Qt3DInput::QAbstractActionInput
23 \brief QActionInput stores Device and Buttons used to trigger an input event.
24
25 \since 5.7
26*/
27
28/*!
29 \qmltype ActionInput
30 \inqmlmodule Qt3D.Input
31 \inherits QAbstractActionInput
32 \instantiates Qt3DInput::QActionInput
33 \brief QML frontend for the Qt3DInput::QActionInput C++ class.
34
35 Links a physical device and selected buttons on it which can trigger this action.
36
37 Each Action input can be triggered by one or many buttons on a source device
38 \qml
39 ActionInput {
40 sourceDevice: keyboardSourceDevice
41 buttons: [Qt.Key_A]
42 }
43 \endqml
44 \qml
45 ActionInput {
46 sourceDevice: keyboardSourceDevice
47 buttons: [Qt.Key_A,Qt.Key_B]
48 }
49 \endqml
50 \since 5.7
51*/
52
53/*!
54 Constructs a new QActionInput instance with \a parent.
55 */
56QActionInput::QActionInput(Qt3DCore::QNode *parent)
57 : Qt3DInput::QAbstractActionInput(*new QActionInputPrivate(), parent)
58{
59
60}
61
62/*! \internal */
63QActionInput::~QActionInput()
64{
65}
66
67/*!
68 \property Qt3DInput::QActionInput::buttons
69
70 Holds the buttons that can trigger this Action.
71 */
72QList<int> QActionInput::buttons() const
73{
74 Q_D(const QActionInput);
75 return d->m_buttons;
76}
77
78/*!
79 \property Qt3DInput::QActionInput::sourceDevice
80
81 The current source device of the QActionInput.
82*/
83/*!
84 \fn Qt3DInput::QActionInput::sourceDeviceChanged(QAbstractPhysicalDevice *sourceDevice)
85
86 This signal is emitted when the source device associated with the action input is changed to \a sourceDevice.
87*/
88
89/*!
90 \qmlproperty AbstractPhysicalDevice Qt3D.Input::ActionInput::sourceDevice
91
92 The current source device of the ActionInput
93*/
94
95/*!
96 \qmlsignal Qt3D.Input::ActionInput::sourceDeviceChanged()
97
98 This signal is emitted when the source device associated with the action input is changed.
99
100 The corresponding handler is \c onSourceDeviceChanged
101*/
102void QActionInput::setSourceDevice(QAbstractPhysicalDevice *sourceDevice)
103{
104 Q_D(QActionInput);
105 if (d->m_sourceDevice != sourceDevice) {
106
107 if (d->m_sourceDevice)
108 d->unregisterDestructionHelper(node: d->m_sourceDevice);
109
110 // Check and set parent if needed
111 // to force creation in the backend
112 if (sourceDevice && !sourceDevice->parent())
113 sourceDevice->setParent(this);
114
115 d->m_sourceDevice = sourceDevice;
116
117 // Ensures proper bookkeeping
118 if (d->m_sourceDevice)
119 d->registerDestructionHelper(node: sourceDevice, func: &QActionInput::setSourceDevice, d->m_sourceDevice);
120
121 emit sourceDeviceChanged(sourceDevice);
122 }
123}
124
125QAbstractPhysicalDevice *QActionInput::sourceDevice() const
126{
127 Q_D(const QActionInput);
128 return d->m_sourceDevice;
129}
130
131/*!
132 \fn Qt3DInput::QActionInput::buttonsChanged(const QList<int> &buttons)
133
134 This signal is emitted when the buttons associated with the action input is changed.
135 The buttons changed are \a buttons
136*/
137
138/*!
139 \qmlproperty list<int> Qt3D.Input::ActionInput::buttons
140
141 The Buttons that can trigger this Action.
142*/
143
144/*!
145 \qmlsignal Qt3D.Input::ActionInput::buttonsChanged(const QList<int> &buttons)
146
147 This signal is emitted when the \a buttons associated with the action input is changed.
148
149 The corresponding handler is \c onbuttonsChanged
150*/
151
152/*!
153 Set the buttons to trigger the QActionInput instance to \a buttons.
154 */
155void QActionInput::setButtons(const QList<int> &buttons)
156{
157 Q_D(QActionInput);
158 if (buttons != d->m_buttons) {
159 d->m_buttons = buttons;
160 emit buttonsChanged(buttons);
161 }
162}
163
164} // Qt3DInput
165
166QT_END_NAMESPACE
167
168#include "moc_qactioninput.cpp"
169

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