on f751789 help sign in
unity8/plugins/Unity/InputInfo/qinputinfo.cpp
268 lines 6.8 kB history raw
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****************************************************************************/
42#include "qinputinfo.h"
44#if defined(Q_OS_LINUX)
45#include "linux/qinputdeviceinfo_linux_p.h"
46#endif
48Q_GLOBAL_STATIC(QInputDeviceManagerPrivate, inputDeviceManagerPrivate)
50QT_BEGIN_NAMESPACE
52QInputDeviceManagerPrivate * QInputDeviceManagerPrivate::instance()
54 QInputDeviceManagerPrivate *priv = inputDeviceManagerPrivate();
55 return priv;
58QInputDevicePrivate::QInputDevicePrivate(QObject *parent) :
59 QObject(parent),
60 type(QInputDevice::Unknown)
64QInputDevice::QInputDevice(QObject *parent) :
65 QObject(parent),
66 d_ptr(new QInputDevicePrivate(this))
70/*
71 * Returns the name of this input device.
72 */
73QString QInputDevice::name() const
75 return d_ptr->name;
78/*
79 * Sets the name of this input device to \b name.
80 */
81void QInputDevice::setName(const QString &name)
83 d_ptr->name = name;
86/*
87 * Returns the device path of this device.
88 */
89QString QInputDevice::devicePath() const
91 return d_ptr->devicePath;
94/*
95 * Sets the device ppath of this device to /b path.
96 */
97void QInputDevice::setDevicePath(const QString &path)
99 d_ptr->devicePath = path;
102/*
103 * Returns the number of buttons this device has.
104 */
105QList <int> QInputDevice::buttons() const
107 return d_ptr->buttons;
110/*
111 * Adds a button
112 */
113void QInputDevice::addButton(int buttonCode)
115 d_ptr->buttons.append(buttonCode);
118/*
119 * Returns the number of switch of this device.
120 */
121QList <int> QInputDevice::switches() const
123 return d_ptr->switches;
126/*
127 * Adds a switch
128 */
129void QInputDevice::addSwitch(int switchCode)
131 d_ptr->switches.append(switchCode);
134/*
135 * Returns a list of the relative axis of this device
136 */
137QList <int> QInputDevice::relativeAxis() const
139 return d_ptr->relativeAxis;
142/*
143 */
144void QInputDevice::addRelativeAxis(int axisCode)
146 d_ptr->relativeAxis.append(axisCode);
149/*
150 * Returns a list of the absolute axis of this device
151 */
152QList <int> QInputDevice::absoluteAxis() const
154 return d_ptr->absoluteAxis;
157/*
158 */
159void QInputDevice::addAbsoluteAxis(int axisCode)
161 d_ptr->absoluteAxis.append(axisCode);
164/*
165 * Returns a QInputDevice::InputTypeFlags of all the types of types.
166 */
167QInputDevice::InputTypeFlags QInputDevice::type() const
169 return d_ptr->type;
172/*
173 */
174void QInputDevice::setType(QInputDevice::InputTypeFlags type) //? setTypes?
176 d_ptr->type = type;
179QInputDeviceManager::QInputDeviceManager(QObject *parent) :
180 QObject(parent),
181 d_ptr(inputDeviceManagerPrivate)
183 connect(d_ptr, &QInputDeviceManagerPrivate::deviceAdded,this,&QInputDeviceManager::addedDevice);
184 connect(d_ptr, &QInputDeviceManagerPrivate::deviceRemoved,this,&QInputDeviceManager::deviceRemoved);
186 connect(d_ptr,SIGNAL(ready()),this,SIGNAL(ready()));
189/*
190 * Returns a QMap of known input devices.
191 */
192QMap <QString, QInputDevice *> QInputDeviceManager::deviceMap()
194 return d_ptr->deviceMap;
197/*
198 */
199void QInputDeviceManager::addedDevice(const QString & devicePath)
201 Q_EMIT deviceAdded(devicePath);
204/*
205 * Returns a QVector of InputDevices of type filter
206 * */
207QVector <QInputDevice *> QInputDeviceManager::deviceListOfType(QInputDevice::InputType filter)
209 QVector <QInputDevice *> dList;
210 QMapIterator<QString, QInputDevice *> i(d_ptr->deviceMap);
211 while (i.hasNext()) {
212 i.next();
213 if (i.value()->type().testFlag(filter) || filter == QInputDevice::Unknown) {
214 dList.append(i.value());
215 }
216 }
217 return dList;
220/*
221 * Returns the number of input devices with the currently set QInputDevice::InputType filter.
222 * If no device filter has been set, returns number of all available input devices.
223 * If filter has not been set, returns all available input devices
224 */
225int QInputDeviceManager::deviceCount() const
227 return deviceCount(static_cast< QInputDevice::InputType >(d_ptr->currentFilter));
230/*
231 * Returns the number of input devices of the type filter.
232 */
233int QInputDeviceManager::deviceCount(const QInputDevice::InputType filter) const
235 int dList = 0;
236 QMapIterator<QString, QInputDevice *> i(d_ptr->deviceMap);
237 while (i.hasNext()) {
238 i.next();
239// qDebug() << i.value()->name() << i.value()->devicePath();
240// qDebug() << i.value()->type() << i.value()->type().testFlag(filter);
242 if (i.value()->type().testFlag(filter)) {
243 dList++;
244 }
245 }
246 return dList;
249/*
250 * Returns the currently set device filter.
251 * */
252QInputDevice::InputType QInputDeviceManager::deviceFilter()
254 return d_ptr->currentFilter;
257/*
258 * Sets the current input device filter to filter.
259 * */
260void QInputDeviceManager::setDeviceFilter(QInputDevice::InputType filter)
262 if (filter != d_ptr->currentFilter) {
263 d_ptr->currentFilter = filter;
264 Q_EMIT deviceFilterChanged(filter);
265 }
268QT_END_NAMESPACE