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 "qpickevent.h"
5#include "qpickevent_p.h"
6#include <private/qobject_p.h>
7
8QT_BEGIN_NAMESPACE
9
10namespace Qt3DRender {
11
12/*!
13 \class Qt3DRender::QPickEvent
14 \inmodule Qt3DRender
15
16 \brief The QPickEvent class holds information when an object is picked.
17
18 This is received as a parameter in most of the QObjectPicker component signals when picking
19 succeeds.
20
21 \sa QPickingSettings, QPickTriangleEvent, QObjectPicker
22
23 \since 5.7
24*/
25
26/*!
27 * \qmltype PickEvent
28 * \instantiates Qt3DRender::QPickEvent
29 * \inqmlmodule Qt3D.Render
30 * \sa ObjectPicker PickingSettings
31 * \brief PickEvent holds information when an object is picked.
32 * This is received as a parameter in most of the QObjectPicker component signals when picking
33 * succeeds.
34 */
35
36/*!
37 \fn Qt3DRender::QPickEvent::QPickEvent()
38 Constructs a new QPickEvent.
39 */
40QPickEvent::QPickEvent()
41 : QObject(*new QPickEventPrivate())
42{
43}
44
45QPickEventPrivate *QPickEventPrivate::get(QPickEvent *object)
46{
47 return object->d_func();
48}
49
50/*!
51 \fn Qt3DRender::QPickEvent::QPickEvent(const QPointF &position, const QVector3D &intersection, const QVector3D &localIntersection, float distance)
52 Constructs a new QPickEvent with the given parameters: \a position, \a intersection, \a localIntersection and \a distance
53 */
54// NOTE: remove in Qt6
55QPickEvent::QPickEvent(const QPointF &position, const QVector3D &worldIntersection, const QVector3D &localIntersection,
56 float distance)
57 : QObject(*new QPickEventPrivate())
58{
59 Q_D(QPickEvent);
60 d->m_position = position;
61 d->m_distance = distance;
62 d->m_worldIntersection = worldIntersection;
63 d->m_localIntersection = localIntersection;
64}
65
66/*!
67 Constructs a new QPickEvent with the given parameters: \a position, \a worldIntersection, \a localIntersection, \a distance, \a button, \a buttons and \a modifiers
68 */
69QPickEvent::QPickEvent(const QPointF &position, const QVector3D &worldIntersection, const QVector3D &localIntersection,
70 float distance, QPickEvent::Buttons button, int buttons, int modifiers)
71 : QObject(*new QPickEventPrivate())
72{
73 Q_D(QPickEvent);
74 d->m_position = position;
75 d->m_distance = distance;
76 d->m_worldIntersection = worldIntersection;
77 d->m_localIntersection = localIntersection;
78 d->m_button = button;
79 d->m_buttons = buttons;
80 d->m_modifiers = modifiers;
81}
82
83/*! \internal */
84QPickEvent::QPickEvent(QObjectPrivate &dd, QObject *parent)
85 : QObject(dd, parent)
86{
87
88}
89
90/*! \internal */
91QPickEvent::~QPickEvent()
92{
93}
94
95/*!
96 \qmlproperty bool Qt3D.Render::PickEvent::accepted
97 Specifies if event has been accepted
98*/
99/*!
100 \property Qt3DRender::QPickEvent::accepted
101 Specifies if event has been accepted
102 */
103/*!
104 * \brief QPickEvent::isAccepted
105 * \return true if the event has been accepted
106 */
107bool QPickEvent::isAccepted() const
108{
109 Q_D(const QPickEvent);
110 return d->m_accepted;
111}
112/*!
113 * \brief QPickEvent::setAccepted set if the event has been accepted to \a accepted
114 */
115void QPickEvent::setAccepted(bool accepted)
116{
117 Q_D(QPickEvent);
118 if (accepted != d->m_accepted) {
119 d->m_accepted = accepted;
120 emit acceptedChanged(accepted);
121 }
122}
123
124/*!
125 \qmlproperty Point2D Qt3D.Render::PickEvent::position
126 Specifies the mouse position with respect to the render area (window or quick item)
127*/
128/*!
129 \property Qt3DRender::QPickEvent::position
130 Specifies the mouse position with respect to the render area (window or quick item)
131 */
132/*!
133 * \brief QPickEvent::position
134 * \return mouse pointer coordinate of the pick query
135 */
136QPointF QPickEvent::position() const
137{
138 Q_D(const QPickEvent);
139 return d->m_position;
140}
141
142/*!
143 \qmlproperty real Qt3D.Render::PickEvent::distance
144 Specifies the distance of the hit to the camera
145*/
146/*!
147 \property Qt3DRender::QPickEvent::distance
148 Specifies the distance of the hit to the camera
149 */
150/*!
151 * \brief QPickEvent::distance
152 * \return distance from camera to pick point
153 */
154float QPickEvent::distance() const
155{
156 Q_D(const QPickEvent);
157 return d->m_distance;
158}
159
160/*!
161 \qmlproperty Vector3D Qt3D.Render::PickEvent::worldIntersection
162 Specifies the coordinates of the hit in world coordinate system
163*/
164/*!
165 \property Qt3DRender::QPickEvent::worldIntersection
166 Specifies the coordinates of the hit in world coordinate system
167 */
168/*!
169 * \brief QPickEvent::worldIntersection
170 * \return coordinates of the hit in world coordinate system
171 */
172QVector3D QPickEvent::worldIntersection() const
173{
174 Q_D(const QPickEvent);
175 return d->m_worldIntersection;
176}
177
178/*!
179 \qmlproperty Vector3D Qt3D.Render::PickEvent::localIntersection
180 Specifies the coordinates of the hit in the local coordinate system of the picked entity
181*/
182/*!
183 \property Qt3DRender::QPickEvent::localIntersection
184 Specifies the coordinates of the hit in the local coordinate system of the picked entity
185 */
186/*!
187 * \brief QPickEvent::localIntersection
188 * \return coordinates of the hit in the local coordinate system of the picked entity
189 */
190QVector3D QPickEvent::localIntersection() const
191{
192 Q_D(const QPickEvent);
193 return d->m_localIntersection;
194}
195
196/*!
197 * \enum Qt3DRender::QPickEvent::Buttons
198 *
199 * \value LeftButton
200 * \value RightButton
201 * \value MiddleButton
202 * \value BackButton
203 * \value NoButton
204 */
205
206/*!
207 \qmlproperty int Qt3D.Render::PickEvent::button
208 Specifies mouse button that caused the event
209*/
210/*!
211 \property Qt3DRender::QPickEvent::button
212 Specifies mouse button that caused the event
213 */
214/*!
215 * \brief QPickEvent::button
216 * \return mouse button that caused the event
217 */
218QPickEvent::Buttons QPickEvent::button() const
219{
220 Q_D(const QPickEvent);
221 return d->m_button;
222}
223
224/*!
225 \qmlproperty int Qt3D.Render::PickEvent::buttons
226 Specifies state of the mouse buttons for the event
227*/
228/*!
229 \property Qt3DRender::QPickEvent::buttons
230 Specifies state of the mouse buttons for the event
231 */
232/*!
233 * \brief QPickEvent::buttons
234 * \return bitfield to be used to check for mouse buttons that may be accompanying the pick event.
235 */
236int QPickEvent::buttons() const
237{
238 Q_D(const QPickEvent);
239 return d->m_buttons;
240}
241
242/*!
243 * \enum Qt3DRender::QPickEvent::Modifiers
244 *
245 * \value NoModifier
246 * \value ShiftModifier
247 * \value ControlModifier
248 * \value AltModifier
249 * \value MetaModifier
250 * \value KeypadModifier
251 */
252
253/*!
254 \qmlproperty int Qt3D.Render::PickEvent::modifiers
255 Specifies state of the mouse buttons for the event
256*/
257/*!
258 \property Qt3DRender::QPickEvent::modifiers
259 Specifies state of the mouse buttons for the event
260 */
261/*!
262 * \brief QPickEvent::modifiers
263 * \return bitfield to be used to check for keyboard modifiers that may be accompanying the pick event.
264 */
265int QPickEvent::modifiers() const
266{
267 Q_D(const QPickEvent);
268 return d->m_modifiers;
269}
270
271/*!
272 * \qmlproperty Viewport Qt3D.Render::PickEvent::viewport
273 * The viewport in which this event originated. A null value means the event originated from a frame graph branch without a Viewport.
274 * If a frame graph branch has a Viewport inside a Viewport the property will contain the leaf viewport.
275 *
276 * \since 5.14
277 */
278/*!
279 * \property Qt3DRender::QPickEvent::viewport
280 * The viewport in which this event originated. A null value means the event originated from a frame graph branch without a QViewport.
281 * If a frame graph branch has a Viewport inside a Viewport the property will contain the leaf viewport.
282 *
283 * \since 5.14
284 */
285QViewport *QPickEvent::viewport() const
286{
287 Q_D(const QPickEvent);
288 return d->m_viewport;
289}
290
291
292/*!
293 * \qmlproperty Entity Qt3D.Render::PickEvent::entity
294 * The entity that the picked geometry belongs to.
295 *
296 * If the object picker is not attached to a leaf node in the scene graph,
297 * this is useful to find which child entity was actually picked.
298 *
299 * \since 5.14
300 */
301/*!
302 * \property Qt3DRender::QPickEvent::entity
303 * The entity that the picked geometry belongs to.
304 *
305 * If the object picker is not attached to a leaf node in the scene graph,
306 * this is useful to find which child entity was actually picked.
307 *
308 * \since 5.14
309 */
310Qt3DCore::QEntity *QPickEvent::entity() const
311{
312 Q_D(const QPickEvent);
313 return d->m_entityPtr;
314}
315
316} // Qt3DRender
317
318QT_END_NAMESPACE
319
320#include "moc_qpickevent.cpp"
321
322

source code of qt3d/src/render/picking/qpickevent.cpp