File indexing completed on 2024-05-12 15:56:41

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