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