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