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 | |
4 | #include "qlogicaldevice.h" |
5 | #include "qlogicaldevice_p.h" |
6 | |
7 | #include <Qt3DInput/qaction.h> |
8 | #include <Qt3DInput/qaxis.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | namespace Qt3DInput { |
13 | |
14 | QLogicalDevicePrivate::QLogicalDevicePrivate() |
15 | : Qt3DCore::QComponentPrivate() |
16 | { |
17 | } |
18 | |
19 | QLogicalDevicePrivate::~QLogicalDevicePrivate() |
20 | { |
21 | } |
22 | |
23 | /*! |
24 | \class Qt3DInput::QLogicalDevice |
25 | \inmodule Qt3DInput |
26 | \inherits Qt3DCore::QNode |
27 | \brief QLogicalDevice allows the user to define a set of actions that they wish to use within an application. |
28 | |
29 | \since 5.6 |
30 | */ |
31 | |
32 | /*! |
33 | \qmltype LogicalDevice |
34 | \inqmlmodule Qt3D.Input |
35 | \instantiates Qt3DInput::QLogicalDevice |
36 | \brief QML frontend for the Qt3DInput::QLogicalDevice C++ class. |
37 | |
38 | Allows the user to define a set of actions that they wish to use within an application. |
39 | |
40 | \qml |
41 | LogicalDevice { |
42 | id: keyboardLogicalDevice |
43 | |
44 | actions: [ |
45 | Action { |
46 | name: "fire" |
47 | inputs: [ |
48 | ActionInput { |
49 | sourceDevice: keyboardSourceDevice |
50 | keys: [Qt.Key_Space] |
51 | }, |
52 | InputChord { |
53 | tolerance: 10 |
54 | inputs: [ |
55 | ActionInput { |
56 | sourceDevice: keyboardSourceDevice |
57 | keys: [Qt.Key_A] |
58 | }, |
59 | ActionInput { |
60 | sourceDevice: keyboardSourceDevice |
61 | keys: [Qt.Key_S] |
62 | } |
63 | ] |
64 | } |
65 | ] |
66 | }, |
67 | Action { |
68 | name: "reload" |
69 | inputs: [ |
70 | ActionInput { |
71 | sourceDevice: keyboardSourceDevice |
72 | keys: [Qt.Key_Alt] |
73 | } |
74 | ] |
75 | }, |
76 | Action { |
77 | name: "combo" |
78 | inputs: [ |
79 | InputSequence { |
80 | interval: 1000 |
81 | timeout: 10000 |
82 | inputs: [ |
83 | ActionInput { |
84 | sourceDevice: keyboardSourceDevice |
85 | keys: [Qt.Key_G] |
86 | }, |
87 | ActionInput { |
88 | sourceDevice: keyboardSourceDevice |
89 | keys: [Qt.Key_D] |
90 | }, |
91 | ActionInput { |
92 | sourceDevice: keyboardSourceDevice |
93 | keys: [Qt.Key_J] |
94 | } |
95 | ] |
96 | } |
97 | ] |
98 | } |
99 | ] |
100 | } |
101 | \endqml |
102 | |
103 | \since 5.6 |
104 | */ |
105 | |
106 | /*! |
107 | Constructs a new QLogicalDevice instance with parent \a parent. |
108 | */ |
109 | QLogicalDevice::QLogicalDevice(Qt3DCore::QNode *parent) |
110 | : Qt3DCore::QComponent(*new QLogicalDevicePrivate(), parent) |
111 | { |
112 | } |
113 | |
114 | QLogicalDevice::~QLogicalDevice() |
115 | { |
116 | } |
117 | |
118 | /*! |
119 | \qmlproperty list<Action> Qt3D.Input::LogicalDevice::actions |
120 | |
121 | The actions used by this Logical Device |
122 | */ |
123 | |
124 | /*! |
125 | Add an \a action to the list of actions. |
126 | */ |
127 | void QLogicalDevice::addAction(QAction *action) |
128 | { |
129 | Q_D(QLogicalDevice); |
130 | if (!d->m_actions.contains(t: action)) { |
131 | d->m_actions.push_back(t: action); |
132 | // Force creation in backend by setting parent |
133 | if (!action->parent()) |
134 | action->setParent(this); |
135 | |
136 | // Ensures proper bookkeeping |
137 | d->registerDestructionHelper(node: action, func: &QLogicalDevice::removeAction, d->m_actions); |
138 | |
139 | d->update(); |
140 | } |
141 | } |
142 | |
143 | /*! |
144 | Remove an \a action from the list of actions. |
145 | */ |
146 | void QLogicalDevice::removeAction(QAction *action) |
147 | { |
148 | Q_D(QLogicalDevice); |
149 | if (d->m_actions.contains(t: action)) { |
150 | d->update(); |
151 | |
152 | d->m_actions.removeOne(t: action); |
153 | |
154 | // Remove bookkeeping connection |
155 | d->unregisterDestructionHelper(node: action); |
156 | } |
157 | } |
158 | |
159 | /*! |
160 | Returns the list of actions. |
161 | */ |
162 | QList<QAction *> QLogicalDevice::actions() const |
163 | { |
164 | Q_D(const QLogicalDevice); |
165 | return d->m_actions; |
166 | } |
167 | |
168 | /*! |
169 | \qmlproperty list<Axis> Qt3D.Input::LogicalDevice::axis |
170 | |
171 | The axis used by this Logical Device |
172 | */ |
173 | |
174 | /*! |
175 | Add an \a axis to the list of axis. |
176 | */ |
177 | void QLogicalDevice::addAxis(QAxis *axis) |
178 | { |
179 | Q_D(QLogicalDevice); |
180 | if (!d->m_axes.contains(t: axis)) { |
181 | d->m_axes.push_back(t: axis); |
182 | |
183 | // Force creation in backend by setting parent |
184 | if (!axis->parent()) |
185 | axis->setParent(this); |
186 | |
187 | // Ensures proper bookkeeping |
188 | d->registerDestructionHelper(node: axis, func: &QLogicalDevice::removeAxis, d->m_axes); |
189 | |
190 | d->update(); |
191 | } |
192 | } |
193 | |
194 | /*! |
195 | Remove an \a axis drom the list of axis. |
196 | */ |
197 | void QLogicalDevice::removeAxis(QAxis *axis) |
198 | { |
199 | Q_D(QLogicalDevice); |
200 | if (d->m_axes.contains(t: axis)) { |
201 | d->update(); |
202 | |
203 | d->m_axes.removeOne(t: axis); |
204 | |
205 | // Remove bookkeeping connection |
206 | d->unregisterDestructionHelper(node: axis); |
207 | } |
208 | } |
209 | |
210 | /*! |
211 | Returns the list of axis. |
212 | */ |
213 | QList<QAxis *> QLogicalDevice::axes() const |
214 | { |
215 | Q_D(const QLogicalDevice); |
216 | return d->m_axes; |
217 | } |
218 | |
219 | } // Qt3DInput |
220 | |
221 | QT_END_NAMESPACE |
222 | |
223 | #include "moc_qlogicaldevice.cpp" |
224 | |