1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2020 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QPOINTINGDEVICE_H |
41 | #define QPOINTINGDEVICE_H |
42 | |
43 | #include <QtGui/qtguiglobal.h> |
44 | #include <QtCore/qobject.h> |
45 | #include <QtGui/qinputdevice.h> |
46 | |
47 | QT_BEGIN_NAMESPACE |
48 | |
49 | class QDebug; |
50 | class QEventPoint; |
51 | class QPointerEvent; |
52 | class QPointingDevicePrivate; |
53 | class QPointerEvent; |
54 | class QScreen; |
55 | |
56 | class Q_GUI_EXPORT QPointingDeviceUniqueId |
57 | { |
58 | Q_GADGET |
59 | Q_PROPERTY(qint64 numericId READ numericId CONSTANT) |
60 | public: |
61 | Q_ALWAYS_INLINE |
62 | constexpr QPointingDeviceUniqueId() noexcept : m_numericId(-1) {} |
63 | // compiler-generated copy/move ctor/assignment operators are ok! |
64 | // compiler-generated dtor is ok! |
65 | |
66 | static QPointingDeviceUniqueId fromNumericId(qint64 id); |
67 | |
68 | Q_ALWAYS_INLINE constexpr bool isValid() const noexcept { return m_numericId != -1; } |
69 | qint64 numericId() const noexcept; |
70 | |
71 | private: |
72 | // TODO: for TUIO 2, or any other type of complex token ID, an internal |
73 | // array (or hash) can be added to hold additional properties. |
74 | // In this case, m_numericId will then turn into an index into that array (or hash). |
75 | qint64 m_numericId; |
76 | }; |
77 | Q_DECLARE_TYPEINFO(QPointingDeviceUniqueId, Q_MOVABLE_TYPE); |
78 | |
79 | Q_GUI_EXPORT bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept; |
80 | inline bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept |
81 | { return !operator==(lhs, rhs); } |
82 | Q_GUI_EXPORT size_t qHash(QPointingDeviceUniqueId key, size_t seed = 0) noexcept; |
83 | |
84 | class Q_GUI_EXPORT QPointingDevice : public QInputDevice |
85 | { |
86 | Q_OBJECT |
87 | Q_DECLARE_PRIVATE(QPointingDevice) |
88 | Q_PROPERTY(PointerType pointerType READ pointerType) |
89 | Q_PROPERTY(int maximumPoints READ maximumPoints) |
90 | Q_PROPERTY(int buttonCount READ buttonCount) |
91 | Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId) |
92 | |
93 | public: |
94 | enum class PointerType : qint16 { |
95 | Unknown = 0, |
96 | Generic = 0x0001, // mouse or similar |
97 | Finger = 0x0002, // touchscreen or pad |
98 | Pen = 0x0004, // stylus on a tablet |
99 | Eraser = 0x0008, // eraser end of a stylus |
100 | Cursor = 0x0010, // digitizer with crosshairs |
101 | AllPointerTypes = 0x7FFF |
102 | }; |
103 | Q_DECLARE_FLAGS(PointerTypes, PointerType) |
104 | Q_FLAG(PointerTypes) |
105 | |
106 | enum GrabTransition : quint8 { |
107 | GrabPassive = 0x01, |
108 | UngrabPassive = 0x02, |
109 | CancelGrabPassive = 0x03, |
110 | OverrideGrabPassive = 0x04, |
111 | GrabExclusive = 0x10, |
112 | UngrabExclusive = 0x20, |
113 | CancelGrabExclusive = 0x30, |
114 | }; |
115 | Q_ENUM(GrabTransition) |
116 | |
117 | QPointingDevice(); |
118 | ~QPointingDevice(); |
119 | QPointingDevice(const QString &name, qint64 systemId, QInputDevice::DeviceType devType, |
120 | PointerType pType, Capabilities caps, int maxPoints, int buttonCount, |
121 | const QString &seatName = QString(), |
122 | QPointingDeviceUniqueId uniqueId = QPointingDeviceUniqueId(), |
123 | QObject *parent = nullptr); |
124 | |
125 | #if QT_DEPRECATED_SINCE(6, 0) |
126 | QT_DEPRECATED_VERSION_X_6_0("Use the constructor" ) |
127 | void setType(DeviceType devType); |
128 | QT_DEPRECATED_VERSION_X_6_0("Use the constructor" ) |
129 | void setCapabilities(QInputDevice::Capabilities caps); |
130 | QT_DEPRECATED_VERSION_X_6_0("Use the constructor" ) |
131 | void setMaximumTouchPoints(int c); |
132 | #endif |
133 | |
134 | PointerType pointerType() const; |
135 | int maximumPoints() const; |
136 | int buttonCount() const; |
137 | QPointingDeviceUniqueId uniqueId() const; |
138 | |
139 | static const QPointingDevice *primaryPointingDevice(const QString& seatName = QString()); |
140 | |
141 | bool operator==(const QPointingDevice &other) const; |
142 | |
143 | Q_SIGNALS: |
144 | void grabChanged(QObject *grabber, GrabTransition transition, const QPointerEvent *event, const QEventPoint &point) const; |
145 | |
146 | protected: |
147 | QPointingDevice(QPointingDevicePrivate &d, QObject *parent = nullptr); |
148 | |
149 | Q_DISABLE_COPY_MOVE(QPointingDevice) |
150 | }; |
151 | |
152 | Q_DECLARE_OPERATORS_FOR_FLAGS(QPointingDevice::PointerTypes) |
153 | |
154 | #ifndef QT_NO_DEBUG_STREAM |
155 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPointingDevice *); |
156 | #endif |
157 | |
158 | //typedef QPointingDevice QTouchDevice; // Qt 5 source compatibility if we need it? or could be "using" |
159 | |
160 | QT_END_NAMESPACE |
161 | |
162 | #endif // QPOINTINGDEVICE_H |
163 | |