1// Copyright (C) 2014 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 "qkeyevent.h"
5
6QT_BEGIN_NAMESPACE
7
8namespace Qt3DInput {
9
10//Qt6: Move this into a QtQmlGui module and merge it with QQuickKeyEvent
11
12/*!
13 \class Qt3DInput::QKeyEvent
14 \inmodule Qt3DInput
15 \brief QKeyEvent event type send by KeyBoardHandler.
16 \since 5.5
17 \brief Contains parameters that describe a key event
18*/
19
20/*!
21 \qmltype KeyEvent
22 \inqmlmodule Qt3D.Input
23 \instantiates Qt3DInput::QKeyEvent
24 \brief QML frontend for QKeyEvent C++ class.
25 \since 5.5
26 \brief Contains parameters that describe a key event
27
28 The KeyEvent QML type cannot be directly created. Objects of this type
29 are used as signal parameters in KeyboardHandler.
30*/
31
32/*!
33 * \typedef Qt3DInput::QKeyEventPtr
34 * \relates Qt3DInput::QKeyEvent
35 *
36 * A shared pointer for QKeyEvent.
37 */
38
39QKeyEvent::QKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text, bool autorep, ushort count)
40 : QObject()
41 , m_event(new QT_PREPEND_NAMESPACE(QKeyEvent){type, key, modifiers, text, autorep, count})
42{
43 m_event->setAccepted(false);
44}
45
46QKeyEvent::QKeyEvent(const QT_PREPEND_NAMESPACE(QKeyEvent) &ke)
47 : QObject()
48 , m_event(static_cast<QT_PREPEND_NAMESPACE(QKeyEvent) *>(ke.clone()))
49{
50 m_event->setAccepted(false);
51}
52
53/*! \internal */
54QKeyEvent::~QKeyEvent()
55{
56}
57
58/*!
59 \qmlproperty int Qt3D.Input::KeyEvent::key
60 \readonly
61
62 This property holds the code of the key that was pressed or released.
63
64 See \l [CPP] {Qt::Key}{Qt.Key} for the list of keyboard codes.
65
66 \sa {QtQuick::KeyEvent::key}{KeyEvent.key}
67*/
68
69/*!
70 \qmlproperty string Qt3D.Input::KeyEvent::text
71 \readonly
72
73 This property holds the Unicode text that the key generated. The text
74 returned can be an empty string in cases where modifier keys, such as
75 Shift, Control, Alt, and Meta, are being pressed or released. In such
76 cases \l key will contain a valid value.
77*/
78
79/*!
80 \qmlproperty int Qt3D.Input::KeyEvent::modifiers
81 \readonly
82
83 This property holds the keyboard modifier flags that existed immediately
84 before the event occurred.
85
86 \sa {QtQuick::KeyEvent::modifiers}{KeyEvent.modifiers}
87*/
88
89/*!
90 \qmlproperty bool Qt3D.Input::KeyEvent::isAutoRepeat
91 \readonly
92
93 Holds whether this event comes from an auto-repeating key.
94*/
95
96/*!
97 \qmlproperty int Qt3D.Input::KeyEvent::count
98 \readonly
99
100 Holds the number of keys involved in this event. If \l text is not empty,
101 this is simply the length of the string.
102*/
103
104/*!
105 \qmlproperty quint32 Qt3D.Input::KeyEvent::nativeScanCode
106 \readonly
107
108 This property contains the native scan code of the key that was pressed.
109 It is passed through from QKeyEvent unchanged.
110
111 \sa QKeyEvent::nativeScanCode()
112*/
113
114/*!
115 \qmlproperty bool Qt3D.Input::KeyEvent::accepted
116
117 Setting \e accepted to \c true prevents the key event from being propagated
118 to the item's parent.
119
120 Generally, if the item acts on the key event then it should be accepted so
121 that ancestor items do not also respond to the same event.
122*/
123
124/*!
125 \qmlmethod bool Qt3D.Input::KeyEvent::matches(StandardKey key)
126
127 Returns \c true if the key event matches the given standard \a key; otherwise
128 returns \c false.
129
130 \sa QKeySequence::StandardKey
131*/
132
133/*!
134 \property Qt3DInput::QKeyEvent::key
135 \readonly
136
137 This property holds the code of the key that was pressed or released.
138
139 See \l [CPP] {Qt::Key}{Qt.Key} for the list of keyboard codes.
140
141 \b {See also} \l [QtGui] {QKeyEvent::key()}.
142*/
143
144/*!
145 \property Qt3DInput::QKeyEvent::text
146 \readonly
147
148 This property holds the Unicode text that the key generated. The text
149 returned can be an empty string in cases where modifier keys, such as
150 Shift, Control, Alt, and Meta, are being pressed or released. In such
151 cases \l key will contain a valid value.
152*/
153
154/*!
155 \property Qt3DInput::QKeyEvent::modifiers
156 \readonly
157
158 This property holds the keyboard modifier flags that existed immediately
159 before the event occurred.
160
161 \b {See also} \l [QtGui] {QKeyEvent::modifiers()}.
162*/
163
164/*!
165 \property Qt3DInput::QKeyEvent::isAutoRepeat
166 \readonly
167
168 Holds whether this event comes from an auto-repeating key.
169*/
170
171/*!
172 \property Qt3DInput::QKeyEvent::count
173 \readonly
174
175 Holds the number of keys involved in this event. If \l text is not empty,
176 this is simply the length of the string.
177*/
178
179/*!
180 \property Qt3DInput::QKeyEvent::nativeScanCode
181 \readonly
182
183 This property contains the native scan code of the key that was pressed.
184 It is passed through from QKeyEvent unchanged.
185
186*/
187
188/*!
189 \property Qt3DInput::QKeyEvent::accepted
190
191 Setting \e accepted to \c true prevents the key event from being propagated
192 to the item's parent.
193
194 Generally, if the item acts on the key event then it should be accepted so
195 that ancestor items do not also respond to the same event.
196*/
197
198/*!
199 \fn bool Qt3DInput::QKeyEvent::matches(QKeySequence::StandardKey key_) const
200
201 Returns \c true if the key event matches the given standard key \a key_; otherwise
202 returns \c false.
203
204 \sa QKeySequence::StandardKey
205*/
206
207/*!
208 \fn QEvent::Type Qt3DInput::QKeyEvent::type() const
209 Returns the type of the event.
210
211*/
212
213} // namespace Qt3DInput
214
215QT_END_NAMESPACE
216
217#include "moc_qkeyevent.cpp"
218

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