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 "mousehandler_p.h" |
5 | |
6 | #include <Qt3DInput/qmousehandler.h> |
7 | #include <Qt3DInput/qmousedevice.h> |
8 | |
9 | #include <Qt3DInput/private/inputmanagers_p.h> |
10 | #include <Qt3DInput/private/inputhandler_p.h> |
11 | #include <Qt3DInput/private/mousedevice_p.h> |
12 | #include <Qt3DInput/private/qmousehandler_p.h> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | |
17 | namespace Qt3DInput { |
18 | namespace Input { |
19 | |
20 | using namespace Qt3DCore; |
21 | |
22 | MouseHandler::MouseHandler() |
23 | : BackendNode(ReadWrite) |
24 | , m_inputHandler(nullptr) |
25 | { |
26 | } |
27 | |
28 | MouseHandler::~MouseHandler() |
29 | { |
30 | } |
31 | |
32 | Qt3DCore::QNodeId MouseHandler::mouseDevice() const |
33 | { |
34 | return m_mouseDevice; |
35 | } |
36 | |
37 | void MouseHandler::setInputHandler(InputHandler *handler) |
38 | { |
39 | m_inputHandler = handler; |
40 | } |
41 | |
42 | void MouseHandler::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) |
43 | { |
44 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
45 | const Qt3DInput::QMouseHandler *node = qobject_cast<const Qt3DInput::QMouseHandler *>(object: frontEnd); |
46 | if (!node) |
47 | return; |
48 | |
49 | const auto newId = Qt3DCore::qIdForNode(node: node->sourceDevice()); |
50 | if (m_mouseDevice != newId) |
51 | setDevice(newId); |
52 | } |
53 | |
54 | void MouseHandler::setDevice(Qt3DCore::QNodeId device) |
55 | { |
56 | m_mouseDevice = device; |
57 | } |
58 | |
59 | MouseHandlerFunctor::MouseHandlerFunctor(InputHandler *handler) |
60 | : m_handler(handler) |
61 | { |
62 | } |
63 | |
64 | Qt3DCore::QBackendNode *MouseHandlerFunctor::create(Qt3DCore::QNodeId id) const |
65 | { |
66 | MouseHandler *input = m_handler->mouseInputManager()->getOrCreateResource(id); |
67 | input->setInputHandler(m_handler); |
68 | return input; |
69 | } |
70 | |
71 | Qt3DCore::QBackendNode *MouseHandlerFunctor::get(Qt3DCore::QNodeId id) const |
72 | { |
73 | return m_handler->mouseInputManager()->lookupResource(id); |
74 | } |
75 | |
76 | void MouseHandlerFunctor::destroy(Qt3DCore::QNodeId id) const |
77 | { |
78 | m_handler->mouseInputManager()->releaseResource(id); |
79 | } |
80 | |
81 | } // namespace Input |
82 | } // namespace Qt3DInput |
83 | |
84 | QT_END_NAMESPACE |
85 |