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 | #include "objectpicker_p.h" |
5 | #include "qpickevent.h" |
6 | #include <Qt3DRender/qobjectpicker.h> |
7 | #include <Qt3DRender/private/qobjectpicker_p.h> |
8 | #include <Qt3DRender/private/pickboundingvolumejob_p.h> |
9 | #include <Qt3DRender/private/qrenderaspect_p.h> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | namespace Qt3DRender { |
14 | |
15 | namespace Render { |
16 | |
17 | ObjectPicker::ObjectPicker() |
18 | : BackendNode(QBackendNode::ReadWrite) |
19 | , m_priority(0) |
20 | , m_isPressed(false) |
21 | , m_hoverEnabled(false) |
22 | , m_dragEnabled(false) |
23 | { |
24 | } |
25 | |
26 | ObjectPicker::~ObjectPicker() |
27 | { |
28 | notifyJob(); |
29 | } |
30 | |
31 | void ObjectPicker::cleanup() |
32 | { |
33 | BackendNode::setEnabled(false); |
34 | m_isPressed = false; |
35 | m_hoverEnabled = false; |
36 | m_dragEnabled = false; |
37 | m_priority = 0; |
38 | notifyJob(); |
39 | } |
40 | |
41 | void ObjectPicker::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) |
42 | { |
43 | const QObjectPicker *node = qobject_cast<const QObjectPicker *>(object: frontEnd); |
44 | if (!node) |
45 | return; |
46 | |
47 | if (firstTime) { |
48 | markDirty(changes: AbstractRenderer::AllDirty); |
49 | notifyJob(); |
50 | } |
51 | |
52 | if (isEnabled() != node->isEnabled()) { |
53 | markDirty(changes: AbstractRenderer::AllDirty); |
54 | // We let QBackendNode::syncFromFrontEnd change the enabled property |
55 | } |
56 | |
57 | if (node->isHoverEnabled() != m_hoverEnabled) { |
58 | m_hoverEnabled = node->isHoverEnabled(); |
59 | markDirty(changes: AbstractRenderer::AllDirty); |
60 | notifyJob(); |
61 | } |
62 | |
63 | if (node->isDragEnabled() != m_dragEnabled) { |
64 | m_dragEnabled = node->isDragEnabled(); |
65 | markDirty(changes: AbstractRenderer::AllDirty); |
66 | notifyJob(); |
67 | } |
68 | |
69 | if (node->priority() != m_priority) { |
70 | m_priority = node->priority(); |
71 | markDirty(changes: AbstractRenderer::AllDirty); |
72 | notifyJob(); |
73 | } |
74 | |
75 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
76 | } |
77 | |
78 | void ObjectPicker::notifyJob() |
79 | { |
80 | if (m_renderer && m_renderer->aspect()) |
81 | QRenderAspectPrivate::get(q: m_renderer->aspect())->m_pickBoundingVolumeJob->markPickersDirty(); |
82 | } |
83 | |
84 | bool ObjectPicker::isPressed() const |
85 | { |
86 | return m_isPressed; |
87 | } |
88 | |
89 | bool ObjectPicker::isHoverEnabled() const |
90 | { |
91 | return m_hoverEnabled; |
92 | } |
93 | |
94 | bool ObjectPicker::isDragEnabled() const |
95 | { |
96 | return m_dragEnabled; |
97 | } |
98 | |
99 | void ObjectPicker::setPressed(bool pressed) |
100 | { |
101 | m_isPressed = pressed; |
102 | } |
103 | |
104 | void ObjectPicker::setPriority(int priority) |
105 | { |
106 | m_priority = priority; |
107 | } |
108 | |
109 | int ObjectPicker::priority() const |
110 | { |
111 | return m_priority; |
112 | } |
113 | |
114 | } // Render |
115 | |
116 | } // Qt3DRender |
117 | |
118 | QT_END_NAMESPACE |
119 |