1 | // Copyright (C) 2015 Paul Lemire paul.lemire350@gmail.com |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QT3DRENDER_RENDER_PICKBOUNDINGVOLUMEJOB_H |
5 | #define QT3DRENDER_RENDER_PICKBOUNDINGVOLUMEJOB_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of other Qt classes. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "abstractpickingjob_p.h" |
19 | #include <Qt3DCore/qaspectjob.h> |
20 | #include <Qt3DRender/private/qray3d_p.h> |
21 | #include <Qt3DRender/private/handle_types_p.h> |
22 | #include <Qt3DRender/private/qboundingvolumeprovider_p.h> |
23 | #include <Qt3DRender/private/qcollisionqueryresult_p.h> |
24 | #include <Qt3DRender/private/pickboundingvolumeutils_p.h> |
25 | #include <Qt3DRender/private/qt3drender_global_p.h> |
26 | #include <Qt3DRender/qpickevent.h> |
27 | #include <QMouseEvent> |
28 | #include <QKeyEvent> |
29 | #include <QSharedPointer> |
30 | |
31 | #include <vector> |
32 | #include <memory> |
33 | |
34 | QT_BEGIN_NAMESPACE |
35 | |
36 | namespace Qt3DRender { |
37 | |
38 | class QViewport; |
39 | |
40 | namespace Render { |
41 | class PickBoundingVolumeJobPrivate; |
42 | |
43 | namespace PickingUtils { |
44 | typedef std::vector<RayCasting::QCollisionQueryResult::Hit> HitList; |
45 | } |
46 | |
47 | class Q_3DRENDERSHARED_PRIVATE_EXPORT PickBoundingVolumeJob : public AbstractPickingJob |
48 | { |
49 | public: |
50 | PickBoundingVolumeJob(); |
51 | |
52 | void setRoot(Entity *root); |
53 | bool processMouseEvent(QObject* object, QMouseEvent *event); |
54 | void markPickersDirty(); |
55 | bool pickersDirty() const { return m_pickersDirty; } |
56 | |
57 | // For unit tests |
58 | inline HObjectPicker currentPicker() const { return m_currentPicker; } |
59 | inline QList<HObjectPicker> hoveredPickers() const { return m_hoveredPickers; } |
60 | bool runHelper() override; |
61 | |
62 | protected: |
63 | void processPickEvent(const PickingUtils::PickConfiguration &pickConfiguration, QObject *object, const QMouseEvent *event); |
64 | void dispatchPickEvents(const QMouseEvent *event, |
65 | const PickingUtils::HitList &sphereHits, |
66 | QPickEvent::Buttons eventButton, |
67 | int eventButtons, |
68 | int eventModifiers, |
69 | bool allHitsRequested, |
70 | Qt3DCore::QNodeId viewportNodeId); |
71 | |
72 | private: |
73 | Q_DECLARE_PRIVATE(PickBoundingVolumeJob) |
74 | |
75 | void clearPreviouslyHoveredPickers(); |
76 | |
77 | std::vector<std::pair<QObject*, std::unique_ptr<QMouseEvent>>> m_pendingMouseEvents; |
78 | bool m_pickersDirty; |
79 | bool m_oneHoverAtLeast; |
80 | HObjectPicker m_currentPicker; |
81 | Qt3DCore::QNodeId m_currentViewport; |
82 | QList<HObjectPicker> m_hoveredPickers; |
83 | QList<HObjectPicker> m_hoveredPickersToClear; |
84 | }; |
85 | |
86 | typedef QSharedPointer<PickBoundingVolumeJob> PickBoundingVolumeJobPtr; |
87 | |
88 | } // namespace Render |
89 | |
90 | } // namespace Qt3DRender |
91 | |
92 | QT_END_NAMESPACE |
93 | |
94 | #endif // QT3DRENDER_RENDER_PICKBOUNDINGVOLUMEJOB_H |
95 | |