1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPOINTINGDEVICE_H
5#define QPOINTINGDEVICE_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qobject.h>
9#include <QtGui/qinputdevice.h>
10
11QT_BEGIN_NAMESPACE
12
13class QDebug;
14class QEventPoint;
15class QPointerEvent;
16class QPointingDevicePrivate;
17class QPointerEvent;
18class QScreen;
19
20class Q_GUI_EXPORT QPointingDeviceUniqueId
21{
22 Q_GADGET
23 Q_PROPERTY(qint64 numericId READ numericId CONSTANT)
24public:
25 Q_ALWAYS_INLINE
26 constexpr QPointingDeviceUniqueId() noexcept : m_numericId(-1) {}
27 // compiler-generated copy/move ctor/assignment operators are ok!
28 // compiler-generated dtor is ok!
29
30 static QPointingDeviceUniqueId fromNumericId(qint64 id);
31
32 Q_ALWAYS_INLINE constexpr bool isValid() const noexcept { return m_numericId != -1; }
33 qint64 numericId() const noexcept;
34
35private:
36 friend bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
37 { return lhs.numericId() == rhs.numericId(); }
38 friend bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
39 { return lhs.numericId() != rhs.numericId(); }
40
41 // TODO: for TUIO 2, or any other type of complex token ID, an internal
42 // array (or hash) can be added to hold additional properties.
43 // In this case, m_numericId will then turn into an index into that array (or hash).
44 qint64 m_numericId;
45};
46Q_DECLARE_TYPEINFO(QPointingDeviceUniqueId, Q_RELOCATABLE_TYPE);
47
48Q_GUI_EXPORT size_t qHash(QPointingDeviceUniqueId key, size_t seed = 0) noexcept;
49
50class Q_GUI_EXPORT QPointingDevice : public QInputDevice
51{
52 Q_OBJECT
53 Q_DECLARE_PRIVATE(QPointingDevice)
54 Q_PROPERTY(PointerType pointerType READ pointerType CONSTANT)
55 Q_PROPERTY(int maximumPoints READ maximumPoints CONSTANT)
56 Q_PROPERTY(int buttonCount READ buttonCount CONSTANT)
57 Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId CONSTANT)
58
59public:
60 enum class PointerType {
61 Unknown = 0,
62 Generic = 0x0001, // mouse or similar
63 Finger = 0x0002, // touchscreen or pad
64 Pen = 0x0004, // stylus on a tablet
65 Eraser = 0x0008, // eraser end of a stylus
66 Cursor = 0x0010, // digitizer with crosshairs
67 AllPointerTypes = 0x7FFF
68 };
69 Q_DECLARE_FLAGS(PointerTypes, PointerType)
70 Q_FLAG(PointerTypes)
71
72 enum GrabTransition {
73 GrabPassive = 0x01,
74 UngrabPassive = 0x02,
75 CancelGrabPassive = 0x03,
76 OverrideGrabPassive = 0x04,
77 GrabExclusive = 0x10,
78 UngrabExclusive = 0x20,
79 CancelGrabExclusive = 0x30,
80 };
81 Q_ENUM(GrabTransition)
82
83 QPointingDevice(QObject *parent = nullptr);
84 ~QPointingDevice();
85 QPointingDevice(const QString &name, qint64 systemId, QInputDevice::DeviceType devType,
86 PointerType pType, Capabilities caps, int maxPoints, int buttonCount,
87 const QString &seatName = QString(),
88 QPointingDeviceUniqueId uniqueId = QPointingDeviceUniqueId(),
89 QObject *parent = nullptr);
90
91#if QT_DEPRECATED_SINCE(6, 0)
92 QT_DEPRECATED_VERSION_X_6_0("Use the constructor")
93 void setType(DeviceType devType);
94 QT_DEPRECATED_VERSION_X_6_0("Use the constructor")
95 void setCapabilities(QInputDevice::Capabilities caps);
96 QT_DEPRECATED_VERSION_X_6_0("Use the constructor")
97 void setMaximumTouchPoints(int c);
98#endif
99
100 PointerType pointerType() const;
101 int maximumPoints() const;
102 int buttonCount() const;
103 QPointingDeviceUniqueId uniqueId() const;
104
105 static const QPointingDevice *primaryPointingDevice(const QString& seatName = QString());
106
107 bool operator==(const QPointingDevice &other) const;
108
109Q_SIGNALS:
110#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
111 void grabChanged(QObject *grabber, GrabTransition transition,
112 const QPointerEvent *event, const QEventPoint &point) const;
113#else
114 void grabChanged(QObject *grabber, QPointingDevice::GrabTransition transition,
115 const QPointerEvent *event, const QEventPoint &point);
116#endif
117
118protected:
119 QPointingDevice(QPointingDevicePrivate &d, QObject *parent);
120
121 Q_DISABLE_COPY_MOVE(QPointingDevice)
122};
123
124Q_DECLARE_OPERATORS_FOR_FLAGS(QPointingDevice::PointerTypes)
125
126#ifndef QT_NO_DEBUG_STREAM
127Q_GUI_EXPORT QDebug operator<<(QDebug, const QPointingDevice *);
128#endif
129
130//typedef QPointingDevice QTouchDevice; // Qt 5 source compatibility if we need it? or could be "using"
131
132QT_END_NAMESPACE
133
134#endif // QPOINTINGDEVICE_H
135

source code of qtbase/src/gui/kernel/qpointingdevice.h