| 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 |
import QtQuick 2.0 |
| 52 |
import QtSystemInfo 5.5 |
| 53 |
|
| 54 |
Rectangle { |
| 55 |
width: 900 |
| 56 |
height: 480 |
| 57 |
|
| 58 |
ListView { |
| 59 |
anchors.fill: parent |
| 60 |
id: inputList |
| 61 |
model: deviceModel |
| 62 |
delegate: deviceDelegate |
| 63 |
anchors.margins: 6 |
| 64 |
} |
| 65 |
|
| 66 |
Component { |
| 67 |
id: deviceDelegate |
| 68 |
|
| 69 |
Rectangle { |
| 70 |
id: contentRect |
| 71 |
anchors { left: parent.left; right: parent.right } |
| 72 |
height: 20 |
| 73 |
Row { |
| 74 |
id: row |
| 75 |
spacing: 10 |
| 76 |
Text { text: name } |
| 77 |
Text { text: identifier } |
| 78 |
Text { text: typeToString(types) } |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
InputDeviceModel { |
| 83 |
id: deviceModel |
| 84 |
filter: InputInfo.Keyboard | InputInfo.Mouse | InputInfo.TouchScreen |
| 85 |
onCountChanged: { |
| 86 |
console.log("new count of filtered devices: " + devices) |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
InputInfo { |
| 91 |
id: systemInputs |
| 92 |
} |
| 93 |
|
| 94 |
InputDeviceManager { |
| 95 |
id: deviceManager |
| 96 |
filter: InputInfo.Mouse | InputInfo.Keyboard |
| 97 |
onReady: { |
| 98 |
console.log("number of mouse and keyboard devices: " + deviceManager.count) |
| 99 |
console.log("row count " + deviceModel.count) |
| 100 |
} |
| 101 |
onDeviceAdded: { |
| 102 |
console.log(inputDevice.properties.name+" " + inputDevice.properties.types +" "+InputInfo.Mouse) |
| 103 |
// does not seem to work |
| 104 |
if (inputDevice.properties.types & InputInfo.Mouse) { |
| 105 |
console.log("mouse added") |
| 106 |
} |
| 107 |
if (inputDevice.properties.types & InputInfo.Keyboard) { |
| 108 |
console.log("keyboard added") |
| 109 |
} |
| 110 |
} |
| 111 |
onDeviceRemoved: { |
| 112 |
console.log("device removed "+deviceId) |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
function typeToString(flags) { |
| 117 |
var typeString = "" |
| 118 |
if (flags & InputInfo.Button) |
| 119 |
typeString += "Button, " |
| 120 |
if (flags & InputInfo.Mouse) |
| 121 |
typeString += "Mouse, " |
| 122 |
if (flags & InputInfo.TouchPad) |
| 123 |
typeString += "TouchPad, " |
| 124 |
if (flags & InputInfo.TouchScreen) |
| 125 |
typeString += "TouchScreen, " |
| 126 |
if (flags & InputInfo.Keyboard) |
| 127 |
typeString += "Keyboard, " |
| 128 |
if (flags & InputInfo.Switch) |
| 129 |
typeString += "Switch " |
| 130 |
|
| 131 |
console.log(typeString) |
| 132 |
|
| 133 |
return typeString |
| 134 |
} |
| 135 |
} |