Debian Codegraph @

examples/systeminfo/inputinfo/inputtest.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 Canonical, Ltd. and/or its subsidiary(-ies).
4 ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/legal
6 **
7 ** This file is part of the QtSystems module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** BSD License Usage
19 ** Alternatively, you may use this file under the terms of the BSD license
20 ** as follows:
21 **
22 ** "Redistribution and use in source and binary forms, with or without
23 ** modification, are permitted provided that the following conditions are
24 ** met:
25 ** * Redistributions of source code must retain the above copyright
26 ** notice, this list of conditions and the following disclaimer.
27 ** * Redistributions in binary form must reproduce the above copyright
28 ** notice, this list of conditions and the following disclaimer in
29 ** the documentation and/or other materials provided with the
30 ** distribution.
31 ** * Neither the name of The Qt Company Ltd nor the names of its
32 ** contributors may be used to endorse or promote products derived
33 ** from this software without specific prior written permission.
34 **
35 **
36 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
47 **
48 ** $QT_END_LICENSE$
49 **
50 ****************************************************************************/
51
52 #include "inputtest.h"
53 #include <qinputinfo.h>
54 #include <QDebug>
55
56 Inputtest::Inputtest(QObject *parent) :
57 QObject(parent)
58 {
59 inputDeviceManager = new QInputInfoManager(this);
60 connect(inputDeviceManager, &QInputInfoManager::deviceAdded,this,&Inputtest::deviceAdded);
61 connect(inputDeviceManager, &QInputInfoManager::deviceRemoved,this,&Inputtest::deviceRemoved);
62 connect(inputDeviceManager, &QInputInfoManager::ready,this,&Inputtest::ready);
63 connect(inputDeviceManager, &QInputInfoManager::filterChanged,this,&Inputtest::filterChanged);
64 connect(inputDeviceManager, &QInputInfoManager::countChanged,this,&Inputtest::countChanged);
65
66 QMap <QString, QInputDevice *> map = inputDeviceManager->deviceMap();
67 qDebug() << map.count();
68 }
69
70 void Inputtest::deviceAdded(const QInputDevice *devicePath)
71 {
72 qDebug() << Q_FUNC_INFO << devicePath;
73
74 // QInputDevice *device = inputDeviceInfo->deviceMap().value(devicePath);
75
76 // qDebug() << inputDeviceInfo->deviceMap().count();
77 // qDebug() << device->name() << device->devicePath();
78 // qDebug() << "buttons count"<< device->buttons().count();
79 // qDebug() << "switch count"<< device->switches().count();
80 // qDebug() << "relativeAxes count"<< device->relativeAxes().count();
81 // qDebug() << "absoluteAxes count"<< device->absoluteAxes().count();
82 // qDebug() << "type" << device->type();
83 // qDebug();
84
85 // QMapIterator<QString, QInputDevice*> i(inputDeviceInfo->deviceMap());
86 // while (i.hasNext()) {
87 // i.next();
88 // // qDebug() << i.value()->name();
89 // }
90 }
91
92 void Inputtest::deviceRemoved(const QString &devicePath)
93 {
94 qDebug() << Q_FUNC_INFO << devicePath;
95 // QMapIterator<QString, QInputDevice*> i(inputDeviceInfo->deviceMap());
96 // while (i.hasNext()) {
97 // i.next();
98 /// qDebug() << i.value()->name();
99 // }
100 }
101
102 void Inputtest::ready()
103 {
104 qDebug() << "ready <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" ;
105 QMap <QString, QInputDevice *> map = inputDeviceManager->deviceMap();
106 qDebug() << map.count();
107
108 inputDeviceManager->setFilter(QInputDevice::Mouse | QInputDevice::Keyboard | QInputDevice::TouchScreen);
109 }
110
111 QString Inputtest::typeToString(QInputDevice::InputTypeFlags type)
112 {
113 qDebug() << type;
114 QStringList typeString;
115 if (type.testFlag(QInputDevice::Button))
116 typeString << QStringLiteral("Button");
117 if (type.testFlag(QInputDevice::Mouse))
118 typeString << QStringLiteral("Mouse");
119 if (type.testFlag(QInputDevice::TouchPad))
120 typeString << QStringLiteral("TouchPad");
121 if (type.testFlag(QInputDevice::TouchScreen))
122 typeString << QStringLiteral("TouchScreen");
123 if (type.testFlag(QInputDevice::Keyboard))
124 typeString << QStringLiteral("Keyboard");
125 if (type.testFlag(QInputDevice::Switch))
126 typeString << QStringLiteral("Switch");
127
128 if (typeString.isEmpty())
129 typeString << QStringLiteral("Unknown");
130 return typeString.join((", "));
131 }
132
133 void Inputtest::filterChanged(QInputDevice::InputTypeFlags filterFlags)
134 {
135 qDebug() << Q_FUNC_INFO << filterFlags;
136
137 qDebug() <<"Found"<< inputDeviceManager->deviceMap().count() << "input devices";
138 QMapIterator<QString, QInputDevice*> i(inputDeviceManager->deviceMap());
139 while (i.hasNext()) {
140 i.next();
141 qDebug() << i.value()->name() << i.value()->identifier();
142 qDebug() << "buttons count"<< i.value()->buttons().count();
143 qDebug() << "switch count"<< i.value()->switches().count();
144 qDebug() << "relativeAxes count"<< i.value()->relativeAxes().count();
145 qDebug() << "absoluteAxes count"<< i.value()->absoluteAxes().count();
146 qDebug() << "type" << typeToString(i.value()->types());
147
148 qDebug();
149 // qDebug() << i.value()->name();
150 }
151 qDebug() << "Number of keyboards:" << inputDeviceManager->count(QInputDevice::Keyboard);
152 qDebug() << "Number of mice:" << inputDeviceManager->count(QInputDevice::Mouse);
153 qDebug() << "Number of touchscreens:" << inputDeviceManager->count(QInputDevice::TouchScreen);
154 }
155
156 void Inputtest::countChanged(int newCount)
157 {
158 qWarning() << Q_FUNC_INFO << newCount;
159 }
160