1// Copyright (C) 2016 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 "qinputsettings.h"
5#include "qinputsettings_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DInput {
10
11/*!
12 \class Qt3DInput::QInputSettings
13 \inmodule Qt3DInput
14 \inherits Qt3DCore::QComponent
15 \brief QInputSettings class holds the pointer to an input event source object.
16 \since 5.7
17
18 The QInputSettings component must be set as a component of the scene root entity.
19 It stores a pointer to the object that acts as the source of input events to be handled
20 by various input classes. For example, a QWindow instance can be an event source.
21
22 \sa QMouseDevice, QKeyboardDevice
23*/
24
25/*!
26 \qmltype InputSettings
27 \inqmlmodule Qt3D.Input
28 \inherits Component3D
29 \instantiates Qt3DInput::QInputSettings
30 \brief InputSettings holds the pointer to an input event source object.
31 \since 5.7
32
33 The InputSettings component must be set as a component of the scene root entity.
34 It stores a pointer to the object that acts as the source of input events to be handled
35 by various input classes. For example, a Window instance can be an event source.
36
37 \sa MouseDevice, KeyboardDevice
38*/
39
40QInputSettingsPrivate::QInputSettingsPrivate()
41 : Qt3DCore::QComponentPrivate()
42 , m_eventSource(nullptr)
43{
44}
45
46QInputSettings::QInputSettings(Qt3DCore::QNode *parent)
47 : Qt3DCore::QComponent(*new QInputSettingsPrivate(), parent)
48{
49}
50
51QInputSettings::~QInputSettings()
52{
53}
54
55/*!
56 \property QInputSettings::eventSource
57
58 Holds the current event source. An event source is an object that is capable
59 of receiving various input events, such as mouse or keyboard events.
60 Typically it is a QWindow instance.
61 */
62
63/*!
64 \qmlproperty QtObject InputSettings::eventSource
65
66 Holds the current event source. An event source is an object that is capable
67 of receiving various input events, such as mouse or keyboard events.
68 Typically it is a Window instance.
69*/
70QObject *QInputSettings::eventSource() const
71{
72 Q_D(const QInputSettings);
73 return d->m_eventSource;
74}
75
76void QInputSettings::setEventSource(QObject *eventSource)
77{
78 Q_D(QInputSettings);
79 if (d->m_eventSource != eventSource) {
80 if (d->m_eventSource)
81 QObject::disconnect(d->m_connection);
82 d->m_eventSource = eventSource;
83 emit eventSourceChanged(eventSource);
84 d->m_connection = QObject::connect(sender: eventSource, signal: &QObject::destroyed,
85 context: this, slot: &QInputSettings::eventSourceDestroyed);
86 }
87}
88
89void QInputSettings::eventSourceDestroyed()
90{
91 Q_D(QInputSettings);
92 QObject::disconnect(d->m_connection);
93 d->m_eventSource = nullptr;
94 emit eventSourceChanged(nullptr);
95}
96
97} // Qt3DInput
98
99
100QT_END_NAMESPACE
101
102#include "moc_qinputsettings.cpp"
103

source code of qt3d/src/input/frontend/qinputsettings.cpp