1// Copyright (C) 2016 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 "qinputsequence.h"
4#include "qinputsequence_p.h"
5
6#include <Qt3DInput/qabstractactioninput.h>
7#include <Qt3DInput/qabstractphysicaldevice.h>
8
9#include <Qt3DCore/private/qnode_p.h>
10
11QT_BEGIN_NAMESPACE
12
13namespace Qt3DInput {
14
15QInputSequencePrivate::QInputSequencePrivate()
16 : QAbstractActionInputPrivate(),
17 m_timeout(0),
18 m_buttonInterval(0)
19{
20}
21
22/*!
23 \class Qt3DInput::QInputSequence
24 \inmodule Qt3DInput
25 \inherits QAbstractAggregateActionInput
26 \brief QInputSequence represents a set of QAbstractActionInput's that must be triggerd one after the other.
27 \since 5.7
28*/
29
30/*!
31 \qmltype InputSequence
32 \inqmlmodule Qt3D.Input
33 \inherits QAbstractAggregateActionInput
34 \instantiates Qt3DInput::QInputSequence
35 \brief QML frontend for the Qt3DInput::QInputSequence C++ class.
36
37 Represents a set of QAbstractActionInput's that must be triggerd one after the other.
38
39 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.
40 \qml
41 InputChord {
42 tolerance: 10
43 inputs: [
44 ActionInput {
45 sourceDevice: keyboardSourceDevice
46 keys: [Qt.Key_A]
47 },
48 ActionInput {
49 sourceDevice: keyboardSourceDevice
50 keys: [Qt.Key_S]
51 }
52 ]
53 }
54 \endqml
55
56 \since 5.7
57*/
58
59/*!
60 Constructs a new QInputSequence with parent \a parent.
61 */
62QInputSequence::QInputSequence(Qt3DCore::QNode *parent)
63 : Qt3DInput::QAbstractActionInput(*new QInputSequencePrivate(), parent)
64{
65
66}
67
68/*! \internal */
69QInputSequence::~QInputSequence()
70{
71}
72
73/*!
74 \qmlproperty list<AbstractActionInput> Qt3D.Input::InputSequence::sequences
75*/
76
77
78/*!
79 \qmlproperty int Qt3D.Input::InputSequence::timeout
80
81 The time in milliseconds in which all QAbstractActionInput's in the input sequence must triggered within.
82*/
83
84/*!
85 \qmlsignal Qt3D.Input::InputSequence::timeoutChanged()
86
87 This signal is emitted when the timeout of the input sequence is changed.
88
89 The corresponding handler is \c onTimeoutChanged
90*/
91
92/*!
93 Returns the time in which all QAbstractActionInput's in the input sequence must triggered within.
94 The time is in milliseconds
95 */
96int QInputSequence::timeout() const
97{
98 Q_D(const QInputSequence);
99 return d->m_timeout;
100}
101
102/*!
103 \qmlproperty int Qt3D.Input::InputSequence::buttonInterval
104
105 The maximum time in milliseconds in between consecutive QAbstractActionInput's in the input sequence.
106*/
107
108/*!
109 \qmlsignal Qt3D.Input::InputSequence::buttonIntervalChanged()
110
111 This signal is emitted when the buttonInterval of the input sequence is changed.
112
113 The corresponding handler is \c onButtonIntervalChanged
114*/
115
116/*!
117 Returns the maximum time in between consecutive QAbstractActionInput's in the input sequence.
118 The time is in milliseconds
119 */
120int QInputSequence::buttonInterval() const
121{
122 Q_D(const QInputSequence);
123 return d->m_buttonInterval;
124}
125
126/*!
127 \property QInputSequence::timeout
128
129 The time in which all QAbstractActionInput's in the input sequence must triggered within.
130 The time is in milliseconds.
131 */
132void QInputSequence::setTimeout(int timeout)
133{
134 Q_D(QInputSequence);
135 if (d->m_timeout != timeout) {
136 d->m_timeout = timeout;
137 emit timeoutChanged(timeout);
138 }
139}
140
141/*!
142 \property QInputSequence::buttonInterval
143
144 The maximum time in between consecutive QAbstractActionInput's in the input sequence.
145 The time is in milliseconds.
146 */
147void QInputSequence::setButtonInterval(int buttonInterval)
148{
149 Q_D(QInputSequence);
150 if (d->m_buttonInterval != buttonInterval) {
151 d->m_buttonInterval = buttonInterval;
152 emit buttonIntervalChanged(buttonInterval);
153 }
154}
155
156/*!
157 Append the QAbstractActionInput \a input to the end of this QInputSequence's sequence vector.
158
159 \sa removeSequence
160 */
161void QInputSequence::addSequence(QAbstractActionInput *input)
162{
163 Q_D(QInputSequence);
164 if (!d->m_sequences.contains(t: input)) {
165 d->m_sequences.push_back(t: input);
166
167 // Ensures proper bookkeeping
168 d->registerDestructionHelper(node: input, func: &QInputSequence::removeSequence, d->m_sequences);
169
170 if (!input->parent())
171 input->setParent(this);
172
173 d->update();
174 }
175}
176
177/*!
178 Remove the QAbstractActionInput \a input from this QInputSequence's sequence vector.
179
180 \sa addSequence
181 */
182void QInputSequence::removeSequence(QAbstractActionInput *input)
183{
184 Q_D(QInputSequence);
185 if (d->m_sequences.contains(t: input)) {
186 d->update();
187
188 d->m_sequences.removeOne(t: input);
189
190 // Remove bookkeeping connection
191 d->unregisterDestructionHelper(node: input);
192 }
193}
194
195/*!
196 Returns the QInputSequence's sequence vector.
197 */
198QList<QAbstractActionInput *> QInputSequence::sequences() const
199{
200 Q_D(const QInputSequence);
201 return d->m_sequences;
202}
203
204} // Qt3DInput
205
206QT_END_NAMESPACE
207
208#include "moc_qinputsequence.cpp"
209

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