Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • util
pointerevent.cpp
1#include "pointerevent.h"
2
3PointerEvent::PointerEvent(QMouseEvent* event, const QPointF& canvasPos)
4{
5 mMouseEvent = event;
6 mCanvasPos = canvasPos;
7}
8
9PointerEvent::PointerEvent(QTabletEvent* event, const QPointF& canvasPos)
10{
11 mTabletEvent = event;
12 mCanvasPos = canvasPos;
13}
14
15PointerEvent::~PointerEvent()
16{
17}
18
19QPointF PointerEvent::canvasPos() const
20{
21 return mCanvasPos;
22}
23
24QPointF PointerEvent::viewportPos() const
25{
26 if (mMouseEvent)
27 {
28 return mMouseEvent->localPos();
29 }
30 else if (mTabletEvent)
31 {
32 return mTabletEvent->posF();
33 }
34 Q_ASSERT(false);
35 return QPointF();
36}
37
38Qt::MouseButton PointerEvent::button() const
39{
40 if (mMouseEvent)
41 {
42 return mMouseEvent->button();
43 }
44 else if (mTabletEvent)
45 {
46 return mTabletEvent->button();
47 }
48 // if we land here... the incoming input was
49 // neither tablet nor mouse
50 Q_ASSERT(false);
51 return Qt::NoButton;
52}
53
54Qt::MouseButtons PointerEvent::buttons() const
55{
56 if (mMouseEvent)
57 {
58 return mMouseEvent->buttons();
59 }
60 else if (mTabletEvent)
61 {
62 return mTabletEvent->buttons();
63 }
64 // if we land here... the incoming input was
65 // neither tablet nor mouse
66 Q_ASSERT(false);
67 return Qt::NoButton;
68}
69
70qreal PointerEvent::pressure() const
71{
72 if (mTabletEvent)
73 {
74 return mTabletEvent->pressure();
75 }
76 return 1.0;
77}
78
79qreal PointerEvent::rotation() const
80{
81 if (mTabletEvent)
82 {
83 return mTabletEvent->rotation();
84 }
85 return 0.0;
86}
87
88qreal PointerEvent::tangentialPressure() const
89{
90 if (mTabletEvent)
91 {
92 return mTabletEvent->tangentialPressure();
93 }
94 return 0.0;
95}
96
97int PointerEvent::x() const
98{
99 if (mMouseEvent)
100 {
101 return mMouseEvent->x();
102 }
103 else if (mTabletEvent)
104 {
105 return mTabletEvent->x();
106 }
107 else
108 {
109 Q_ASSERT(false);
110 return 0;
111 }
112
113}
114
115int PointerEvent::y() const
116{
117 if (mMouseEvent)
118 {
119 return mMouseEvent->y();
120 }
121 else if (mTabletEvent)
122 {
123 return mTabletEvent->y();
124 }
125 else
126 {
127 Q_ASSERT(false);
128 return 0;
129 }
130}
131
132bool PointerEvent::isTabletEvent() const
133{
134 if (mTabletEvent)
135 {
136 return true;
137 }
138 else
139 {
140 return false;
141 }
142}
143
144Qt::KeyboardModifiers PointerEvent::modifiers() const
145{
146 if (mMouseEvent)
147 {
148 return mMouseEvent->modifiers();
149 }
150 else if (mTabletEvent)
151 {
152 return mTabletEvent->modifiers();
153 }
154
155 Q_ASSERT(false);
156 return Qt::NoModifier;
157}
158
159void PointerEvent::accept()
160{
161 if (mMouseEvent)
162 {
163 mMouseEvent->accept();
164 }
165 else if (mTabletEvent)
166 {
167 mTabletEvent->accept();
168 }
169 else
170 {
171 Q_ASSERT(false);
172 }
173}
174
175void PointerEvent::ignore()
176{
177 if (mMouseEvent)
178 {
179 mMouseEvent->ignore();
180 }
181 else if (mTabletEvent)
182 {
183 mTabletEvent->ignore();
184 }
185 else
186 {
187 Q_ASSERT(false);
188 }
189}
190
191bool PointerEvent::isAccepted()
192{
193 if (mMouseEvent)
194 {
195 return mMouseEvent->isAccepted();
196 }
197 else if (mTabletEvent)
198 {
199 return mTabletEvent->isAccepted();
200 }
201 Q_ASSERT(false);
202 return false;
203}
204
205PointerEvent::Type PointerEvent::eventType() const
206{
207 if (mMouseEvent)
208 {
209 switch (mMouseEvent->type())
210 {
211 case QEvent::MouseButtonPress:
212 return Type::Press;
213 case QEvent::MouseMove:
214 return Type::Move;
215 case QEvent::MouseButtonRelease:
216 return Type::Release;
217 default:
218 return Type::Unmapped;
219 }
220 }
221 else if (mTabletEvent)
222 {
223 switch (mTabletEvent->type())
224 {
225 case QEvent::TabletPress:
226 return Type::Press;
227 case QEvent::TabletMove:
228 return Type::Move;
229 case QEvent::TabletRelease:
230 return Type::Release;
231 default:
232 return Type::Unmapped;
233 }
234 }
235 return Type::Unmapped;
236}
237
238PointerEvent::InputType PointerEvent::inputType() const
239{
240 if (mMouseEvent) {
241 return InputType::Mouse;
242 }
243 else if (mTabletEvent)
244 {
245 return InputType::Tablet;
246 }
247 return InputType::Unknown;
248}
249
250#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
251
252QInputDevice::DeviceType PointerEvent::device() const
253{
254 if (mTabletEvent)
255 {
256 return mTabletEvent->deviceType();
257 }
258 return QInputDevice::DeviceType::Unknown;
259}
260
261QPointingDevice::PointerType PointerEvent::pointerType() const
262{
263 if (mTabletEvent)
264 {
265 return mTabletEvent->pointerType();
266 }
267 return QPointingDevice::PointerType::Unknown;
268}
269
270#else // QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
271
272QTabletEvent::TabletDevice PointerEvent::device() const
273{
274 if (mTabletEvent)
275 {
276 return mTabletEvent->device();
277 }
278 return QTabletEvent::TabletDevice::NoDevice;
279}
280
281QTabletEvent::PointerType PointerEvent::pointerType() const
282{
283 if (mTabletEvent)
284 {
285 return mTabletEvent->pointerType();
286 }
287 return QTabletEvent::PointerType::UnknownPointer;
288}
289
290#endif // QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
PointerEvent::tangentialPressure
qreal tangentialPressure() const
Returns the tangential pressure of a tablet's that support it This is typically given by a finger whe...
Definition: pointerevent.cpp:88
PointerEvent::viewportPos
QPointF viewportPos() const
Returns the QPointF of the device, in viewport coordinates Returns pos() if used on mouse event.
Definition: pointerevent.cpp:24
PointerEvent::x
int x() const
Returns the x position of the input device in the widget.
Definition: pointerevent.cpp:97
PointerEvent::button
Qt::MouseButton button() const
Returns Qt::MouseButton()
Definition: pointerevent.cpp:38
PointerEvent::isTabletEvent
bool isTabletEvent() const
Returns true if the device was tablet, otherwise false.
Definition: pointerevent.cpp:132
PointerEvent::y
int y() const
Returns the y position of the input device in the widget.
Definition: pointerevent.cpp:115
PointerEvent::rotation
qreal rotation() const
Returns rotation value if any, otherwise 0.
Definition: pointerevent.cpp:79
PointerEvent::canvasPos
QPointF canvasPos() const
Returns the QPointF of the device, in canvas coordinates.
Definition: pointerevent.cpp:19
PointerEvent::modifiers
Qt::KeyboardModifiers modifiers() const
Returns the modifier created by keyboard while a device was in use.
Definition: pointerevent.cpp:144
PointerEvent::buttons
Qt::MouseButtons buttons() const
Returns Qt::MouseButtons()
Definition: pointerevent.cpp:54
PointerEvent::pressure
qreal pressure() const
Returns a value between 0 and 1 for tablet events, otherwise 1.0.
Definition: pointerevent.cpp:70
QEvent::MouseButtonPress
MouseButtonPress
QEvent::accept
void accept()
QEvent::isAccepted
bool isAccepted() const const
QEvent::ignore
void ignore()
QEvent::type
QEvent::Type type() const const
QInputEvent::modifiers
Qt::KeyboardModifiers modifiers() const const
QMouseEvent
QMouseEvent::button
Qt::MouseButton button() const const
QMouseEvent::buttons
Qt::MouseButtons buttons() const const
QMouseEvent::localPos
const QPointF & localPos() const const
QMouseEvent::x
int x() const const
QMouseEvent::y
int y() const const
QPointF
Qt::KeyboardModifiers
typedef KeyboardModifiers
Qt::MouseButton
MouseButton
QTabletEvent::device
QTabletEvent::TabletDevice device() const const
QTabletEvent
QTabletEvent::PointerType
PointerType
QTabletEvent::TabletDevice
TabletDevice
QTabletEvent::button
Qt::MouseButton button() const const
QTabletEvent::buttons
Qt::MouseButtons buttons() const const
QTabletEvent::deviceType
QTabletEvent::TabletDevice deviceType() const const
QTabletEvent::pointerType
QTabletEvent::PointerType pointerType() const const
QTabletEvent::posF
const QPointF & posF() const const
QTabletEvent::pressure
qreal pressure() const const
QTabletEvent::rotation
qreal rotation() const const
QTabletEvent::tangentialPressure
qreal tangentialPressure() const const
QTabletEvent::x
int x() const const
QTabletEvent::y
int y() const const
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39