Lomiri
Loading...
Searching...
No Matches
qinputinfo.cpp
1/****************************************************************************
2**
3** Copyright (C) 2014 Canonical Ltd. and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtSystems 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 Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qinputinfo.h"
43
44#if defined(LOMIRI_MOCKS)
45#include "qinputdeviceinfo_mock_p.h"
46#elif defined(Q_OS_LINUX)
47#include "linux/qinputdeviceinfo_linux_p.h"
48#endif
49
50Q_GLOBAL_STATIC(QInputDeviceManagerPrivate, inputDeviceManagerPrivate)
51
52QT_BEGIN_NAMESPACE
53
54QInputDeviceManagerPrivate * QInputDeviceManagerPrivate::instance()
55{
56 QInputDeviceManagerPrivate *priv = inputDeviceManagerPrivate();
57 return priv;
58}
59
60QInputDevicePrivate::QInputDevicePrivate(QObject *parent) :
61 QObject(parent),
62 type(QInputDevice::Unknown)
63{
64}
65
66QInputDevice::QInputDevice(QObject *parent) :
67 QObject(parent),
68 d_ptr(new QInputDevicePrivate(this))
69{
70}
71
72/*
73 * Returns the name of this input device.
74 */
75QString QInputDevice::name() const
76{
77 return d_ptr->name;
78}
79
80/*
81 * Sets the name of this input device to \b name.
82 */
83void QInputDevice::setName(const QString &name)
84{
85 d_ptr->name = name;
86}
87
88/*
89 * Returns the device path of this device.
90 */
91QString QInputDevice::devicePath() const
92{
93 return d_ptr->devicePath;
94}
95
96/*
97 * Sets the device ppath of this device to /b path.
98 */
99void QInputDevice::setDevicePath(const QString &path)
100{
101 d_ptr->devicePath = path;
102}
103
104/*
105 * Returns the number of buttons this device has.
106 */
107QList <int> QInputDevice::buttons() const
108{
109 return d_ptr->buttons;
110}
111
112/*
113 * Adds a button
114 */
115void QInputDevice::addButton(int buttonCode)
116{
117 d_ptr->buttons.append(buttonCode);
118}
119
120/*
121 * Returns the number of switch of this device.
122 */
123QList <int> QInputDevice::switches() const
124{
125 return d_ptr->switches;
126}
127
128/*
129 * Adds a switch
130 */
131void QInputDevice::addSwitch(int switchCode)
132{
133 d_ptr->switches.append(switchCode);
134}
135
136/*
137 * Returns a list of the relative axis of this device
138 */
139QList <int> QInputDevice::relativeAxis() const
140{
141 return d_ptr->relativeAxis;
142}
143
144/*
145 */
146void QInputDevice::addRelativeAxis(int axisCode)
147{
148 d_ptr->relativeAxis.append(axisCode);
149}
150
151/*
152 * Returns a list of the absolute axis of this device
153 */
154QList <int> QInputDevice::absoluteAxis() const
155{
156 return d_ptr->absoluteAxis;
157}
158
159/*
160 */
161void QInputDevice::addAbsoluteAxis(int axisCode)
162{
163 d_ptr->absoluteAxis.append(axisCode);
164}
165
166/*
167 * Returns a QInputDevice::InputTypeFlags of all the types of types.
168 */
169QInputDevice::InputTypeFlags QInputDevice::type() const
170{
171 return d_ptr->type;
172}
173
174/*
175 */
176void QInputDevice::setType(QInputDevice::InputTypeFlags type) //? setTypes?
177{
178 d_ptr->type = type;
179}
180
181QInputDeviceManager::QInputDeviceManager(QObject *parent) :
182 QObject(parent),
183 d_ptr(inputDeviceManagerPrivate)
184{
185 connect(d_ptr, &QInputDeviceManagerPrivate::deviceAdded,this,&QInputDeviceManager::addedDevice);
186 connect(d_ptr, &QInputDeviceManagerPrivate::deviceRemoved,this,&QInputDeviceManager::deviceRemoved);
187
188 connect(d_ptr,SIGNAL(ready()),this,SIGNAL(ready()));
189}
190
191/*
192 * Returns a QMap of known input devices.
193 */
194QMap <QString, QInputDevice *> QInputDeviceManager::deviceMap()
195{
196 return d_ptr->deviceMap;
197}
198
199/*
200 */
201void QInputDeviceManager::addedDevice(const QString & devicePath)
202{
203 Q_EMIT deviceAdded(devicePath);
204}
205
206/*
207 * Returns a QVector of InputDevices of type filter
208 * */
209QVector <QInputDevice *> QInputDeviceManager::deviceListOfType(QInputDevice::InputType filter)
210{
211 QVector <QInputDevice *> dList;
212 QMapIterator<QString, QInputDevice *> i(d_ptr->deviceMap);
213 while (i.hasNext()) {
214 i.next();
215 if (i.value()->type().testFlag(filter) || filter == QInputDevice::Unknown) {
216 dList.append(i.value());
217 }
218 }
219 return dList;
220}
221
222/*
223 * Returns the number of input devices with the currently set QInputDevice::InputType filter.
224 * If no device filter has been set, returns number of all available input devices.
225 * If filter has not been set, returns all available input devices
226 */
227int QInputDeviceManager::deviceCount() const
228{
229 return deviceCount(static_cast< QInputDevice::InputType >(d_ptr->currentFilter));
230}
231
232/*
233 * Returns the number of input devices of the type filter.
234 */
235int QInputDeviceManager::deviceCount(const QInputDevice::InputType filter) const
236{
237 int dList = 0;
238 QMapIterator<QString, QInputDevice *> i(d_ptr->deviceMap);
239 while (i.hasNext()) {
240 i.next();
241// qDebug() << i.value()->name() << i.value()->devicePath();
242// qDebug() << i.value()->type() << i.value()->type().testFlag(filter);
243
244 if (i.value()->type().testFlag(filter)) {
245 dList++;
246 }
247 }
248 return dList;
249}
250
251/*
252 * Returns the currently set device filter.
253 * */
254QInputDevice::InputType QInputDeviceManager::deviceFilter()
255{
256 return d_ptr->currentFilter;
257}
258
259/*
260 * Sets the current input device filter to filter.
261 * */
262void QInputDeviceManager::setDeviceFilter(QInputDevice::InputType filter)
263{
264 if (filter != d_ptr->currentFilter) {
265 d_ptr->currentFilter = filter;
266 Q_EMIT deviceFilterChanged(filter);
267 }
268}
269
270QT_END_NAMESPACE