Krita Source Code Documentation
Loading...
Searching...
No Matches
KoInputDevice.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006 Adrian Page <adrian@pagenet.plus.com>
3 * SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KO_INPUT_DEVICE_H_
9#define KO_INPUT_DEVICE_H_
10
11#include "kritaflake_export.h"
12
13#include <QTabletEvent>
14#include <QDebug>
15#include <QFlags>
16#include <boost/operators.hpp>
17
22class KRITAFLAKE_EXPORT KoInputDevice : public boost::equality_comparable<KoInputDevice>
23{
24public:
25
26 enum class Pointer {
27 Unknown = 0,
28 Generic = 0x0001, // mouse or similar
29 Finger = 0x0002, // touchscreen or pad
30 Pen = 0x0004, // stylus on a tablet
31 Eraser = 0x0008, // eraser end of a stylus
32 Cursor = 0x0010, // digitizer with crosshairs
33 AllPointerTypes = 0x7FFF
34 };
35
36 enum class InputDevice {
37 Unknown = 0x0000,
38 Mouse = 0x0001,
39 TouchScreen = 0x0002,
40 TouchPad = 0x0004,
41 Puck = 0x0008,
42 Stylus = 0x0010,
43 Airbrush = 0x0020,
44 Keyboard = 0x1000,
45 AllDevices = 0x7FFFFFFF
46 };
47
48 static Pointer convertPointerType(QTabletEvent *event)
49 {
50#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
51 switch (event->pointerType()) {
52 case QTabletEvent::UnknownPointer: {
53 return Pointer::Unknown;
54 }
55 break;
56 case QTabletEvent::Pen: {
57 return Pointer::Pen;
58 }
59 break;
60 case QTabletEvent::Cursor: {
61 return Pointer::Cursor;
62 }
63 break;
64 case QTabletEvent::Eraser: {
65 return Pointer::Eraser;
66 }
67 default:
68 return Pointer::Unknown;
69 }
70#else
71 QPointingDevice::PointerType pointer = event->pointerType();
72 switch (pointer) {
73 case (QPointingDevice::PointerType::Unknown): {
74 return Pointer::Unknown;
75 } break;
76 case QPointingDevice::PointerType::Generic:{
77 return Pointer::Generic;
78 } break;
79 case QPointingDevice::PointerType::Finger:{
80 return Pointer::Finger;
81 } break;
82 case QPointingDevice::PointerType::Pen:{
83 return Pointer::Pen;
84 } break;
85 case QPointingDevice::PointerType::Eraser:{
86 return Pointer::Eraser;
87 } break;
88
89 case QPointingDevice::PointerType::Cursor:{
90 return Pointer::Cursor;
91 } break;
92 case QPointingDevice::PointerType::AllPointerTypes:{
93 return Pointer::AllPointerTypes;
94 } break;
95 default:
96 return Pointer::Unknown;
97 }
98#endif
99 }
100
101 static InputDevice convertDeviceType(QTabletEvent *event)
102 {
103#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
104 switch (event->deviceType()) {
105 case QTabletEvent::NoDevice: {
106 return InputDevice::Unknown;
107 }
108 break;
109 case QTabletEvent::Puck: {
110 return InputDevice::Puck;
111 }
112 break;
113 case QTabletEvent::Stylus: {
114 return InputDevice::Stylus;
115 }
116 break;
117 case QTabletEvent::Airbrush: {
118 return InputDevice::Airbrush;
119 }
120 case QTabletEvent::RotationStylus: {
121 // Note: Qt6 no longer has the RotationStylus device type, so we will
122 // have to stop supporting it.
123 return InputDevice::Stylus;
124 }
125 default:
126 return InputDevice::Unknown;
127 }
128
129#else
130 QInputDevice::DeviceType deviceType = event->deviceType();
131 switch(deviceType) {
132 case QInputDevice::DeviceType::Unknown: {
133 return InputDevice::Unknown;
134 }
135 break;
136 case QInputDevice::DeviceType::Mouse:{
137 return InputDevice::Mouse;
138 }
139 break;
140 case QInputDevice::DeviceType::TouchScreen:
141 {
142 return InputDevice::TouchScreen;
143 }
144 break;
145 case QInputDevice::DeviceType::TouchPad:
146 {
147 return InputDevice::TouchPad;
148 }
149 break;
150 case QInputDevice::DeviceType::Puck:
151 {
152 return InputDevice::Puck;
153 }
154 break;
155 case QInputDevice::DeviceType::Stylus:
156 {
157 return InputDevice::Stylus;
158 }
159 break;
160 case QInputDevice::DeviceType::Airbrush:
161 {
162 return InputDevice::Airbrush;
163 }
164 break;
165 case QInputDevice::DeviceType::Keyboard:
166 {
167 return InputDevice::Keyboard;
168 }
169 break;
170 case QInputDevice::DeviceType::AllDevices:
171 {
172 return InputDevice::AllDevices;
173 }
174 default:
175 return InputDevice::Unknown;
176 }
177#endif
178 }
179
183 KoInputDevice(const KoInputDevice &other);
184
192 explicit KoInputDevice(InputDevice device, Pointer pointer, qint64 uniqueTabletId = -1);
193
198
200
205
210
217 qint64 uniqueTabletId() const;
218
222 bool isMouse() const;
223
225 bool operator==(const KoInputDevice&) const;
227 KoInputDevice & operator=(const KoInputDevice &);
228
229 static KoInputDevice invalid();
231 static KoInputDevice stylus();
232 static KoInputDevice eraser();
233
234
235private:
236 class Private;
237 Private * const d;
238};
239
241
242KRITAFLAKE_EXPORT QDebug operator<<(QDebug debug, const KoInputDevice &device);
243
244inline uint qHash(const KoInputDevice &key)
245{
246 return qHash(QString(":%1:%2:%3:%4")
247 .arg(int(key.device()))
248 .arg(int(key.pointer()))
249 .arg(int(key.uniqueTabletId()))
250 .arg(int(key.isMouse())));
251}
252
253#endif
254
bool operator==(const KisRegion &lhs, const KisRegion &rhs)
KRITAFLAKE_EXPORT QDebug operator<<(QDebug debug, const KoInputDevice &device)
uint qHash(const KoInputDevice &key)
unsigned int uint
KoInputDevice::InputDevice device
KoInputDevice::Pointer pointer
qint64 uniqueTabletId() const
bool isMouse() const
InputDevice device() const
static InputDevice convertDeviceType(QTabletEvent *event)
Pointer pointer() const
Private *const d
static Pointer convertPointerType(QTabletEvent *event)
static KoInputDevice mouse()
Standard mouse.
Q_DECLARE_METATYPE(KisPaintopLodLimitations)
@ Unknown
Definition psd.h:44