on bionic help sign in
unity8/plugins/Unity/InputInfo/qinputinfo.cpp
270 lines 6.9 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(UNITY_MOCKS)
45#include "qinputdeviceinfo_mock_p.h"
46#elif defined(Q_OS_LINUX)
47#include "linux/qinputdeviceinfo_linux_p.h"
48#endif
50Q_GLOBAL_STATIC(QInputDeviceManagerPrivate, inputDeviceManagerPrivate)
52QT_BEGIN_NAMESPACE
54QInputDeviceManagerPrivate * QInputDeviceManagerPrivate::instance()
56 QInputDeviceManagerPrivate *priv = inputDeviceManagerPrivate();
57 return priv;
60QInputDevicePrivate::QInputDevicePrivate(QObject *parent) :
61 QObject(parent),
62 type(QInputDevice::Unknown)
66QInputDevice::QInputDevice(QObject *parent) :
67 QObject(parent),
68 d_ptr(new QInputDevicePrivate(this))
72/*
73 * Returns the name of this input device.
74 */
75QString QInputDevice::name() const
77 return d_ptr->name;
80/*
81 * Sets the name of this input device to \b name.
82 */
83void QInputDevice::setName(const QString &name)
85 d_ptr->name = name;
88/*
89 * Returns the device path of this device.
90 */
91QString QInputDevice::devicePath() const
93 return d_ptr->devicePath;
96/*
97 * Sets the device ppath of this device to /b path.
98 */
99void QInputDevice::setDevicePath(const QString &path)
101 d_ptr->devicePath = path;
104/*
105 * Returns the number of buttons this device has.
106 */
107QList <int> QInputDevice::buttons() const
109 return d_ptr->buttons;
112/*
113 * Adds a button
114 */
115void QInputDevice::addButton(int buttonCode)
117 d_ptr->buttons.append(buttonCode);
120/*
121 * Returns the number of switch of this device.
122 */
123QList <int> QInputDevice::switches() const
125 return d_ptr->switches;
128/*
129 * Adds a switch
130 */
131void QInputDevice::addSwitch(int switchCode)
133 d_ptr->switches.append(switchCode);
136/*
137 * Returns a list of the relative axis of this device
138 */
139QList <int> QInputDevice::relativeAxis() const
141 return d_ptr->relativeAxis;
144/*
145 */
146void QInputDevice::addRelativeAxis(int axisCode)
148 d_ptr->relativeAxis.append(axisCode);
151/*
152 * Returns a list of the absolute axis of this device
153 */
154QList <int> QInputDevice::absoluteAxis() const
156 return d_ptr->absoluteAxis;
159/*
160 */
161void QInputDevice::addAbsoluteAxis(int axisCode)
163 d_ptr->absoluteAxis.append(axisCode);
166/*
167 * Returns a QInputDevice::InputTypeFlags of all the types of types.
168 */
169QInputDevice::InputTypeFlags QInputDevice::type() const
171 return d_ptr->type;
174/*
175 */
176void QInputDevice::setType(QInputDevice::InputTypeFlags type) //? setTypes?
178 d_ptr->type = type;
181QInputDeviceManager::QInputDeviceManager(QObject *parent) :
182 QObject(parent),
183 d_ptr(inputDeviceManagerPrivate)
185 connect(d_ptr, &QInputDeviceManagerPrivate::deviceAdded,this,&QInputDeviceManager::addedDevice);
186 connect(d_ptr, &QInputDeviceManagerPrivate::deviceRemoved,this,&QInputDeviceManager::deviceRemoved);
188 connect(d_ptr,SIGNAL(ready()),this,SIGNAL(ready()));
191/*
192 * Returns a QMap of known input devices.
193 */
194QMap <QString, QInputDevice *> QInputDeviceManager::deviceMap()
196 return d_ptr->deviceMap;
199/*
200 */
201void QInputDeviceManager::addedDevice(const QString & devicePath)
203 Q_EMIT deviceAdded(devicePath);
206/*
207 * Returns a QVector of InputDevices of type filter
208 * */
209QVector <QInputDevice *> QInputDeviceManager::deviceListOfType(QInputDevice::InputType filter)
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;
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
229 return deviceCount(static_cast< QInputDevice::InputType >(d_ptr->currentFilter));
232/*
233 * Returns the number of input devices of the type filter.
234 */
235int QInputDeviceManager::deviceCount(const QInputDevice::InputType filter) const
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);
244 if (i.value()->type().testFlag(filter)) {
245 dList++;
246 }
247 }
248 return dList;
251/*
252 * Returns the currently set device filter.
253 * */
254QInputDevice::InputType QInputDeviceManager::deviceFilter()
256 return d_ptr->currentFilter;
259/*
260 * Sets the current input device filter to filter.
261 * */
262void QInputDeviceManager::setDeviceFilter(QInputDevice::InputType filter)
264 if (filter != d_ptr->currentFilter) {
265 d_ptr->currentFilter = filter;
266 Q_EMIT deviceFilterChanged(filter);
267 }
270QT_END_NAMESPACE