File indexing completed on 2024-05-19 04:24:50

0001 /*
0002  *  SPDX-FileCopyrightText: 2006 Adrian Page <adrian@pagenet.plus.com>
0003  *  SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
0004 
0005    SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KO_INPUT_DEVICE_H_
0009 #define KO_INPUT_DEVICE_H_
0010 
0011 #include "kritaflake_export.h"
0012 
0013 #include <QHash>
0014 #include <QTabletEvent>
0015 #include <QDebug>
0016 #include <boost/operators.hpp>
0017 
0018 /**
0019  * This class represents an input device.
0020  * A user can manipulate flake-shapes using a large variety of input devices. This ranges from
0021  * a mouse to a paintbrush-like tool connected to a tablet. */
0022 class KRITAFLAKE_EXPORT KoInputDevice : public boost::equality_comparable<KoInputDevice>
0023 {
0024 public:
0025     /**
0026      * Copy constructor.
0027      */
0028     KoInputDevice(const KoInputDevice &other);
0029 
0030     /**
0031      * Constructor for a tablet.
0032      * Create a new input device with one of the many types that the tablet can have.
0033      * @param device the device as found on a QTabletEvent
0034      * @param pointer the pointer as found on a QTabletEvent
0035      * @param uniqueTabletId the uniqueId as found on a QTabletEvent
0036      */
0037     explicit KoInputDevice(QTabletEvent::TabletDevice device, QTabletEvent::PointerType pointer, qint64 uniqueTabletId = -1);
0038 
0039     /**
0040      * Constructor for the mouse as input device.
0041      */
0042     KoInputDevice();
0043 
0044     ~KoInputDevice();
0045 
0046     /**
0047      * Return the tablet device used
0048      */
0049     QTabletEvent::TabletDevice device() const;
0050 
0051     /**
0052      * Return the pointer used
0053      */
0054     QTabletEvent::PointerType pointer() const;
0055 
0056     /**
0057      * Return the unique tablet id as registered by QTabletEvents. Note that this
0058      * id can change randomly, so it's not dependable.
0059      *
0060      * See https://bugs.kde.org/show_bug.cgi?id=407659
0061      */
0062     qint64 uniqueTabletId() const;
0063 
0064     /**
0065      * Return if this is a mouse device.
0066      */
0067     bool isMouse() const;
0068 
0069     /// equal
0070     bool operator==(const KoInputDevice&) const;
0071     /// assignment
0072     KoInputDevice & operator=(const KoInputDevice &);
0073 
0074     static KoInputDevice invalid();   ///< invalid input device
0075     static KoInputDevice mouse();     ///< Standard mouse
0076     static KoInputDevice stylus();    ///< Wacom style/pen
0077     static KoInputDevice eraser();    ///< Wacom eraser
0078 
0079 
0080 private:
0081     class Private;
0082     Private * const d;
0083 };
0084 
0085 Q_DECLARE_METATYPE(KoInputDevice)
0086 
0087 KRITAFLAKE_EXPORT QDebug operator<<(QDebug debug, const KoInputDevice &device);
0088 
0089 inline uint qHash(const KoInputDevice &key)
0090 {
0091     return qHash(QString(":%1:%2:%3:%4")
0092                  .arg(key.device())
0093                  .arg(key.pointer())
0094                  .arg(key.uniqueTabletId())
0095                  .arg(key.isMouse()));
0096 }
0097 
0098 #endif
0099