Warning, file /office/calligra/libs/flake/KoInputDevice.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  Copyright (c) 2007 Thomas Zander <zander@kde.org>
0003  *
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include "KoInputDevice.h"
0021 
0022 class Q_DECL_HIDDEN KoInputDevice::Private
0023 {
0024 public:
0025     Private(QTabletEvent::TabletDevice d, QTabletEvent::PointerType p, qint64 id, bool m)
0026             : device(d),
0027             pointer(p),
0028             uniqueTabletId(id),
0029             mouse(m) {
0030     }
0031     QTabletEvent::TabletDevice device;
0032     QTabletEvent::PointerType pointer;
0033     qint64 uniqueTabletId;
0034     bool mouse;
0035 };
0036 
0037 KoInputDevice::KoInputDevice(QTabletEvent::TabletDevice device, QTabletEvent::PointerType pointer, qint64 uniqueTabletId)
0038         : d(new Private(device, pointer, uniqueTabletId, false))
0039 {
0040 }
0041 
0042 KoInputDevice::KoInputDevice()
0043         : d(new Private(QTabletEvent::NoDevice, QTabletEvent::UnknownPointer, -1, true))
0044 {
0045 }
0046 
0047 KoInputDevice::KoInputDevice(const KoInputDevice &other)
0048         : d(new Private(other.d->device, other.d->pointer, other.d->uniqueTabletId, other.d->mouse))
0049 {
0050 }
0051 
0052 
0053 KoInputDevice::~KoInputDevice()
0054 {
0055     delete d;
0056 }
0057 
0058 QTabletEvent::TabletDevice KoInputDevice::device() const
0059 {
0060     return d->device;
0061 }
0062 
0063 QTabletEvent::PointerType KoInputDevice::pointer() const
0064 {
0065     return d->pointer;
0066 }
0067 
0068 qint64 KoInputDevice::uniqueTabletId() const
0069 {
0070     return d->uniqueTabletId;
0071 }
0072 
0073 bool KoInputDevice::isMouse() const
0074 {
0075     // sometimes, the system gives us tablet events with NoDevice or UnknownPointer. This is
0076     // likely an XInput2 bug. However, assuming that if cannot identify the tablet device we've
0077     // actually got a mouse is reasonable. See https://bugs.kde.org/show_bug.cgi?id=283130.
0078     return d->mouse || d->device == QTabletEvent::NoDevice || d->pointer == QTabletEvent::UnknownPointer;
0079 }
0080 
0081 
0082 bool KoInputDevice::operator==(const KoInputDevice &other) const
0083 {
0084     return d->device == other.d->device && d->pointer == other.d->pointer &&
0085            d->uniqueTabletId == other.d->uniqueTabletId && d->mouse == other.d->mouse;
0086 }
0087 
0088 bool KoInputDevice::operator!=(const KoInputDevice &other) const
0089 {
0090     return !(operator==(other));
0091 }
0092 
0093 KoInputDevice & KoInputDevice::operator=(const KoInputDevice & other)
0094 {
0095     d->device = other.d->device;
0096     d->pointer = other.d->pointer;
0097     d->uniqueTabletId = other.d->uniqueTabletId;
0098     d->mouse = other.d->mouse;
0099     return *this;
0100 }
0101 
0102 // static
0103 KoInputDevice KoInputDevice::invalid()
0104 {
0105     KoInputDevice id(QTabletEvent::NoDevice, QTabletEvent::UnknownPointer);
0106     return id;
0107 }
0108 
0109 
0110 
0111 KoInputDevice KoInputDevice::mouse()
0112 {
0113     KoInputDevice id;
0114     return id;
0115 }
0116 
0117 // static
0118 KoInputDevice KoInputDevice::stylus()
0119 {
0120     KoInputDevice id(QTabletEvent::Stylus, QTabletEvent::Pen);
0121     return id;
0122 }
0123 
0124 // static
0125 KoInputDevice KoInputDevice::eraser()
0126 {
0127     KoInputDevice id(QTabletEvent::Stylus, QTabletEvent::Eraser);
0128     return id;
0129 }
0130 
0131 QDebug operator<<(QDebug dbg, const KoInputDevice &device)
0132 {
0133 #ifndef NDEBUG
0134     if (device.isMouse())
0135         dbg.nospace() << "mouse";
0136     else {
0137         switch (device.pointer()) {
0138         case QTabletEvent::UnknownPointer:
0139             dbg.nospace() << "unknown pointer";
0140             break;
0141         case QTabletEvent::Pen:
0142             dbg.nospace() << "pen";
0143             break;
0144         case QTabletEvent::Cursor:
0145             dbg.nospace() << "cursor";
0146             break;
0147         case QTabletEvent::Eraser:
0148             dbg.nospace() << "eraser";
0149             break;
0150         }
0151         switch(device.device()) {
0152         case QTabletEvent::NoDevice:
0153             dbg.space() << "no device";
0154             break;
0155         case QTabletEvent::Puck:
0156             dbg.space() << "puck";
0157             break;
0158         case QTabletEvent::Stylus:
0159             dbg.space() << "stylus";
0160             break;
0161         case QTabletEvent::Airbrush:
0162             dbg.space() << "airbrush";
0163             break;
0164         case QTabletEvent::FourDMouse:
0165             dbg.space() << "four2mouse";
0166             break;
0167         case QTabletEvent::RotationStylus:
0168             dbg.space() << "rotationstylus";
0169             break;
0170         case QTabletEvent::XFreeEraser:
0171             dbg.space() << "XFreeEraser";
0172             break;
0173         }
0174         dbg.space() << "(id: " << device.uniqueTabletId() << ")";
0175     }
0176 #else
0177     Q_UNUSED(device);
0178 #endif
0179     return dbg.space();
0180 }