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

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