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
14QT_BEGIN_NAMESPACE
15
16
17namespace Qt3DInput {
18namespace Input {
19
20using namespace Qt3DCore;
21
22MouseHandler::MouseHandler()
23 : BackendNode(ReadWrite)
24 , m_inputHandler(nullptr)
25{
26}
27
28MouseHandler::~MouseHandler()
29{
30}
31
32Qt3DCore::QNodeId MouseHandler::mouseDevice() const
33{
34 return m_mouseDevice;
35}
36
37void MouseHandler::setInputHandler(InputHandler *handler)
38{
39 m_inputHandler = handler;
40}
41
42void 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
54void MouseHandler::setDevice(Qt3DCore::QNodeId device)
55{
56 m_mouseDevice = device;
57}
58
59MouseHandlerFunctor::MouseHandlerFunctor(InputHandler *handler)
60 : m_handler(handler)
61{
62}
63
64Qt3DCore::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
71Qt3DCore::QBackendNode *MouseHandlerFunctor::get(Qt3DCore::QNodeId id) const
72{
73 return m_handler->mouseInputManager()->lookupResource(id);
74}
75
76void MouseHandlerFunctor::destroy(Qt3DCore::QNodeId id) const
77{
78 m_handler->mouseInputManager()->releaseResource(id);
79}
80
81} // namespace Input
82} // namespace Qt3DInput
83
84QT_END_NAMESPACE
85

source code of qt3d/src/input/backend/mousehandler.cpp