1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*
* Copyright (c) 2007 Thomas Zander <zander@kde.org>
*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "KoInputDevice.h"
class KoInputDevice::Private
{
public:
Private(QTabletEvent::TabletDevice d, QTabletEvent::PointerType p, qint64 id, bool m)
: device(d),
pointer(p),
uniqueTabletId(id),
mouse(m) {
}
QTabletEvent::TabletDevice device;
QTabletEvent::PointerType pointer;
qint64 uniqueTabletId;
bool mouse;
};
KoInputDevice::KoInputDevice(QTabletEvent::TabletDevice device, QTabletEvent::PointerType pointer, qint64 uniqueTabletId)
: d(new Private(device, pointer, uniqueTabletId, false))
{
}
KoInputDevice::KoInputDevice()
: d(new Private(QTabletEvent::NoDevice, QTabletEvent::UnknownPointer, -1, true))
{
}
KoInputDevice::KoInputDevice(const KoInputDevice &other)
: d(new Private(other.d->device, other.d->pointer, other.d->uniqueTabletId, other.d->mouse))
{
}
KoInputDevice::~KoInputDevice()
{
delete d;
}
QTabletEvent::TabletDevice KoInputDevice::device() const
{
return d->device;
}
QTabletEvent::PointerType KoInputDevice::pointer() const
{
return d->pointer;
}
qint64 KoInputDevice::uniqueTabletId() const
{
return d->uniqueTabletId;
}
bool KoInputDevice::isMouse() const
{
// sometimes, the system gives us tablet events with NoDevice or UnknownPointer. This is
// likely an XInput2 bug. However, assuming that if cannot identify the tablet device we've
// actually got a mouse is reasonable. See https://bugs.kde.org/show_bug.cgi?id=283130.
return d->mouse || d->device == QTabletEvent::NoDevice || d->pointer == QTabletEvent::UnknownPointer;
}
bool KoInputDevice::operator==(const KoInputDevice &other) const
{
return d->device == other.d->device && d->pointer == other.d->pointer &&
d->uniqueTabletId == other.d->uniqueTabletId && d->mouse == other.d->mouse;
}
bool KoInputDevice::operator!=(const KoInputDevice &other) const
{
return !(operator==(other));
}
KoInputDevice & KoInputDevice::operator=(const KoInputDevice & other)
{
d->device = other.d->device;
d->pointer = other.d->pointer;
d->uniqueTabletId = other.d->uniqueTabletId;
d->mouse = other.d->mouse;
return *this;
}
// static
KoInputDevice KoInputDevice::mouse()
{
KoInputDevice id;
return id;
}
// static
KoInputDevice KoInputDevice::stylus()
{
KoInputDevice id(QTabletEvent::Stylus, QTabletEvent::Pen);
return id;
}
// static
KoInputDevice KoInputDevice::eraser()
{
KoInputDevice id(QTabletEvent::Stylus, QTabletEvent::Eraser);
return id;
}
QDebug operator<<(QDebug dbg, const KoInputDevice &device)
{
#ifndef NDEBUG
if (device.isMouse())
dbg.nospace() << "mouse";
else {
switch (device.pointer()) {
case QTabletEvent::UnknownPointer:
dbg.nospace() << "unknown pointer";
break;
case QTabletEvent::Pen:
dbg.nospace() << "pen";
break;
case QTabletEvent::Cursor:
dbg.nospace() << "cursor";
break;
case QTabletEvent::Eraser:
dbg.nospace() << "eraser";
break;
}
switch(device.device()) {
case QTabletEvent::NoDevice:
dbg.space() << "no device";
break;
case QTabletEvent::Puck:
dbg.space() << "puck";
break;
case QTabletEvent::Stylus:
dbg.space() << "stylus";
break;
case QTabletEvent::Airbrush:
dbg.space() << "airbrush";
break;
case QTabletEvent::FourDMouse:
dbg.space() << "four2mouse";
break;
case QTabletEvent::RotationStylus:
dbg.space() << "rotationstylus";
break;
case QTabletEvent::XFreeEraser:
dbg.space() << "XFreeEraser";
break;
}
dbg.space() << "(id: " << device.uniqueTabletId() << ")";
}
#else
Q_UNUSED(device);
#endif
return dbg.space();
}
|