1/****************************************************************************
2**
3** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qinputsettings.h"
41#include "qinputsettings_p.h"
42
43#include <Qt3DCore/qnodecreatedchange.h>
44
45QT_BEGIN_NAMESPACE
46
47namespace Qt3DInput {
48
49/*!
50 \class Qt3DInput::QInputSettings
51 \inmodule Qt3DInput
52 \inherits Qt3DCore::QComponent
53 \brief QInputSettings class holds the pointer to an input event source object.
54 \since 5.7
55
56 The QInputSettings component must be set as a component of the scene root entity.
57 It stores a pointer to the object that acts as the source of input events to be handled
58 by various input classes. For example, a QWindow instance can be an event source.
59
60 \sa QMouseDevice, QKeyboardDevice
61*/
62
63/*!
64 \qmltype InputSettings
65 \inqmlmodule Qt3D.Input
66 \inherits Component3D
67 \instantiates Qt3DInput::QInputSettings
68 \brief InputSettings holds the pointer to an input event source object.
69 \since 5.7
70
71 The InputSettings component must be set as a component of the scene root entity.
72 It stores a pointer to the object that acts as the source of input events to be handled
73 by various input classes. For example, a Window instance can be an event source.
74
75 \sa MouseDevice, KeyboardDevice
76*/
77
78QInputSettingsPrivate::QInputSettingsPrivate()
79 : Qt3DCore::QComponentPrivate()
80 , m_eventSource(nullptr)
81{
82}
83
84QInputSettings::QInputSettings(Qt3DCore::QNode *parent)
85 : Qt3DCore::QComponent(*new QInputSettingsPrivate(), parent)
86{
87}
88
89QInputSettings::~QInputSettings()
90{
91}
92
93/*!
94 \property QInputSettings::eventSource
95
96 Holds the current event source. An event source is an object that is capable
97 of receiving various input events, such as mouse or keyboard events.
98 Typically it is a QWindow instance.
99 */
100
101/*!
102 \qmlproperty Object InputSettings::eventSource
103
104 Holds the current event source. An event source is an object that is capable
105 of receiving various input events, such as mouse or keyboard events.
106 Typically it is a Window instance.
107*/
108QObject *QInputSettings::eventSource() const
109{
110 Q_D(const QInputSettings);
111 return d->m_eventSource;
112}
113
114void QInputSettings::setEventSource(QObject *eventSource)
115{
116 Q_D(QInputSettings);
117 if (d->m_eventSource != eventSource) {
118 if (d->m_eventSource)
119 QObject::disconnect(d->m_connection);
120 d->m_eventSource = eventSource;
121 emit eventSourceChanged(eventSource);
122 d->m_connection = QObject::connect(sender: eventSource, signal: &QObject::destroyed,
123 receiver: this, slot: &QInputSettings::eventSourceDestroyed);
124 }
125}
126
127void QInputSettings::eventSourceDestroyed()
128{
129 Q_D(QInputSettings);
130 QObject::disconnect(d->m_connection);
131 d->m_eventSource = nullptr;
132 emit eventSourceChanged(nullptr);
133}
134
135Qt3DCore::QNodeCreatedChangeBasePtr QInputSettings::createNodeCreationChange() const
136{
137 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QInputSettingsData>::create(arguments: this);
138 auto &data = creationChange->data;
139
140 Q_D(const QInputSettings);
141 data.eventSource = d->m_eventSource;
142
143 return creationChange;
144}
145
146} // Qt3DInput
147
148
149QT_END_NAMESPACE
150

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