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