| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2015 Paul Lemire paul.lemire350@gmail.com | 
| 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 "objectpicker_p.h" | 
| 41 | #include "qpickevent.h" | 
| 42 | #include <Qt3DRender/qobjectpicker.h> | 
| 43 | #include <Qt3DRender/private/qobjectpicker_p.h> | 
| 44 | #include <Qt3DRender/qattribute.h> | 
| 45 | #include <Qt3DRender/private/pickboundingvolumejob_p.h> | 
| 46 | #include <Qt3DRender/private/qrenderaspect_p.h> | 
| 47 |  | 
| 48 | QT_BEGIN_NAMESPACE | 
| 49 |  | 
| 50 | namespace Qt3DRender { | 
| 51 |  | 
| 52 | namespace Render { | 
| 53 |  | 
| 54 | ObjectPicker::ObjectPicker() | 
| 55 |     : BackendNode(QBackendNode::ReadWrite) | 
| 56 |     , m_priority(0) | 
| 57 |     , m_isPressed(false) | 
| 58 |     , m_hoverEnabled(false) | 
| 59 |     , m_dragEnabled(false) | 
| 60 | { | 
| 61 | } | 
| 62 |  | 
| 63 | ObjectPicker::~ObjectPicker() | 
| 64 | { | 
| 65 |     notifyJob(); | 
| 66 | } | 
| 67 |  | 
| 68 | void ObjectPicker::cleanup() | 
| 69 | { | 
| 70 |     BackendNode::setEnabled(false); | 
| 71 |     m_isPressed = false; | 
| 72 |     m_hoverEnabled = false; | 
| 73 |     m_dragEnabled = false; | 
| 74 |     m_priority = 0; | 
| 75 |     notifyJob(); | 
| 76 | } | 
| 77 |  | 
| 78 | void ObjectPicker::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) | 
| 79 | { | 
| 80 |     const QObjectPicker *node = qobject_cast<const QObjectPicker *>(object: frontEnd); | 
| 81 |     if (!node) | 
| 82 |         return; | 
| 83 |  | 
| 84 |     if (firstTime) { | 
| 85 |         markDirty(changes: AbstractRenderer::AllDirty); | 
| 86 |         notifyJob(); | 
| 87 |     } | 
| 88 |  | 
| 89 |     if (isEnabled() != node->isEnabled()) { | 
| 90 |         markDirty(changes: AbstractRenderer::AllDirty); | 
| 91 |         // We let QBackendNode::syncFromFrontEnd change the enabled property | 
| 92 |     } | 
| 93 |  | 
| 94 |     if (node->isHoverEnabled() != m_hoverEnabled) { | 
| 95 |         m_hoverEnabled = node->isHoverEnabled(); | 
| 96 |         markDirty(changes: AbstractRenderer::AllDirty); | 
| 97 |         notifyJob(); | 
| 98 |     } | 
| 99 |  | 
| 100 |     if (node->isDragEnabled() != m_dragEnabled) { | 
| 101 |         m_dragEnabled = node->isDragEnabled(); | 
| 102 |         markDirty(changes: AbstractRenderer::AllDirty); | 
| 103 |         notifyJob(); | 
| 104 |     } | 
| 105 |  | 
| 106 |     if (node->priority() != m_priority) { | 
| 107 |         m_priority = node->priority(); | 
| 108 |         markDirty(changes: AbstractRenderer::AllDirty); | 
| 109 |         notifyJob(); | 
| 110 |     } | 
| 111 |  | 
| 112 |     BackendNode::syncFromFrontEnd(frontEnd, firstTime); | 
| 113 | } | 
| 114 |  | 
| 115 | void ObjectPicker::notifyJob() | 
| 116 | { | 
| 117 |     if (m_renderer && m_renderer->aspect()) | 
| 118 |         QRenderAspectPrivate::get(q: m_renderer->aspect())->m_pickBoundingVolumeJob->markPickersDirty(); | 
| 119 | } | 
| 120 |  | 
| 121 | bool ObjectPicker::isPressed() const | 
| 122 | { | 
| 123 |     return m_isPressed; | 
| 124 | } | 
| 125 |  | 
| 126 | bool ObjectPicker::isHoverEnabled() const | 
| 127 | { | 
| 128 |     return m_hoverEnabled; | 
| 129 | } | 
| 130 |  | 
| 131 | bool ObjectPicker::isDragEnabled() const | 
| 132 | { | 
| 133 |     return m_dragEnabled; | 
| 134 | } | 
| 135 |  | 
| 136 | void ObjectPicker::setPressed(bool pressed) | 
| 137 | { | 
| 138 |     m_isPressed = pressed; | 
| 139 | } | 
| 140 |  | 
| 141 | void ObjectPicker::setPriority(int priority) | 
| 142 | { | 
| 143 |     m_priority = priority; | 
| 144 | } | 
| 145 |  | 
| 146 | int ObjectPicker::priority() const | 
| 147 | { | 
| 148 |     return m_priority; | 
| 149 | } | 
| 150 |  | 
| 151 | } // Render | 
| 152 |  | 
| 153 | } // Qt3DRender | 
| 154 |  | 
| 155 | QT_END_NAMESPACE | 
| 156 |  |