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#include "qinputsequence.h"
40#include "qinputsequence_p.h"
41
42#include <Qt3DInput/qabstractactioninput.h>
43#include <Qt3DInput/qabstractphysicaldevice.h>
44#include <Qt3DCore/qnodecreatedchange.h>
45
46#include <Qt3DCore/private/qnode_p.h>
47
48QT_BEGIN_NAMESPACE
49
50namespace Qt3DInput {
51
52QInputSequencePrivate::QInputSequencePrivate()
53 : QAbstractActionInputPrivate(),
54 m_timeout(0),
55 m_buttonInterval(0)
56{
57}
58
59/*!
60 \class Qt3DInput::QInputSequence
61 \inmodule Qt3DInput
62 \inherits QAbstractAggregateActionInput
63 \brief QInputSequence represents a set of QAbstractActionInput's that must be triggerd one after the other.
64 \since 5.7
65*/
66
67/*!
68 \qmltype InputSequence
69 \inqmlmodule Qt3D.Input
70 \inherits QAbstractAggregateActionInput
71 \instantiates Qt3DInput::QInputSequence
72 \brief QML frontend for the Qt3DInput::QInputSequence C++ class.
73
74 Represents a set of QAbstractActionInput's that must be triggerd one after the other.
75
76 The following example shows a chord that will be triggered by pressing the A and S keys together with a tolerance of 10 miliseconds between presses.
77 \qml
78 InputChord {
79 tolerance: 10
80 inputs: [
81 ActionInput {
82 sourceDevice: keyboardSourceDevice
83 keys: [Qt.Key_A]
84 },
85 ActionInput {
86 sourceDevice: keyboardSourceDevice
87 keys: [Qt.Key_S]
88 }
89 ]
90 }
91 \endqml
92
93 \since 5.7
94*/
95
96/*!
97 Constructs a new QInputSequence with parent \a parent.
98 */
99QInputSequence::QInputSequence(Qt3DCore::QNode *parent)
100 : Qt3DInput::QAbstractActionInput(*new QInputSequencePrivate(), parent)
101{
102
103}
104
105/*! \internal */
106QInputSequence::~QInputSequence()
107{
108}
109
110/*!
111 \qmlproperty list<AbstractActionInput> Qt3D.Input::InputSequence::sequences
112*/
113
114
115/*!
116 \qmlproperty int Qt3D.Input::InputSequence::timeout
117
118 The time in milliseconds in which all QAbstractActionInput's in the input sequence must triggered within.
119*/
120
121/*!
122 \qmlsignal Qt3D.Input::InputSequence::timeoutChanged()
123
124 This signal is emitted when the timeout of the input sequence is changed.
125
126 The corresponding handler is \c onTimeoutChanged
127*/
128
129/*!
130 Returns the time in which all QAbstractActionInput's in the input sequence must triggered within.
131 The time is in milliseconds
132 */
133int QInputSequence::timeout() const
134{
135 Q_D(const QInputSequence);
136 return d->m_timeout;
137}
138
139/*!
140 \qmlproperty int Qt3D.Input::InputSequence::buttonInterval
141
142 The maximum time in milliseconds in between consecutive QAbstractActionInput's in the input sequence.
143*/
144
145/*!
146 \qmlsignal Qt3D.Input::InputSequence::buttonIntervalChanged()
147
148 This signal is emitted when the buttonInterval of the input sequence is changed.
149
150 The corresponding handler is \c onButtonIntervalChanged
151*/
152
153/*!
154 Returns the maximum time in between consecutive QAbstractActionInput's in the input sequence.
155 The time is in milliseconds
156 */
157int QInputSequence::buttonInterval() const
158{
159 Q_D(const QInputSequence);
160 return d->m_buttonInterval;
161}
162
163/*!
164 \property QInputSequence::timeout
165
166 The time in which all QAbstractActionInput's in the input sequence must triggered within.
167 The time is in milliseconds.
168 */
169void QInputSequence::setTimeout(int timeout)
170{
171 Q_D(QInputSequence);
172 if (d->m_timeout != timeout) {
173 d->m_timeout = timeout;
174 emit timeoutChanged(timeout);
175 }
176}
177
178/*!
179 \property QInputSequence::buttonInterval
180
181 The maximum time in between consecutive QAbstractActionInput's in the input sequence.
182 The time is in milliseconds.
183 */
184void QInputSequence::setButtonInterval(int buttonInterval)
185{
186 Q_D(QInputSequence);
187 if (d->m_buttonInterval != buttonInterval) {
188 d->m_buttonInterval = buttonInterval;
189 emit buttonIntervalChanged(buttonInterval);
190 }
191}
192
193/*!
194 Append the QAbstractActionInput \a input to the end of this QInputSequence's sequence vector.
195
196 \sa removeSequence
197 */
198void QInputSequence::addSequence(QAbstractActionInput *input)
199{
200 Q_D(QInputSequence);
201 if (!d->m_sequences.contains(t: input)) {
202 d->m_sequences.push_back(t: input);
203
204 // Ensures proper bookkeeping
205 d->registerDestructionHelper(node: input, func: &QInputSequence::removeSequence, d->m_sequences);
206
207 if (!input->parent())
208 input->setParent(this);
209
210 d->updateNode(node: input, property: "input", change: Qt3DCore::PropertyValueAdded);
211 }
212}
213
214/*!
215 Remove the QAbstractActionInput \a input from this QInputSequence's sequence vector.
216
217 \sa addSequence
218 */
219void QInputSequence::removeSequence(QAbstractActionInput *input)
220{
221 Q_D(QInputSequence);
222 if (d->m_sequences.contains(t: input)) {
223 d->updateNode(node: input, property: "input", change: Qt3DCore::PropertyValueRemoved);
224
225 d->m_sequences.removeOne(t: input);
226
227 // Remove bookkeeping connection
228 d->unregisterDestructionHelper(node: input);
229 }
230}
231
232/*!
233 Returns the QInputSequence's sequence vector.
234 */
235QVector<QAbstractActionInput *> QInputSequence::sequences() const
236{
237 Q_D(const QInputSequence);
238 return d->m_sequences;
239}
240
241Qt3DCore::QNodeCreatedChangeBasePtr QInputSequence::createNodeCreationChange() const
242{
243 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QInputSequenceData>::create(arguments: this);
244 QInputSequenceData &data = creationChange->data;
245
246 Q_D(const QInputSequence);
247 data.sequenceIds = qIdsForNodes(nodes: sequences());
248 data.timeout = d->m_timeout;
249 data.buttonInterval = d->m_buttonInterval;
250
251 return creationChange;
252}
253
254} // Qt3DInput
255
256QT_END_NAMESPACE
257

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