1 #include "pointerevent.h"
2 
PointerEvent(QMouseEvent * event)3 PointerEvent::PointerEvent(QMouseEvent* event)
4 {
5     mMouseEvent = event;
6 }
7 
PointerEvent(QTabletEvent * event)8 PointerEvent::PointerEvent(QTabletEvent* event)
9 {
10     mTabletEvent = event;
11 }
12 
~PointerEvent()13 PointerEvent::~PointerEvent()
14 {
15 }
16 
pos() const17 QPoint PointerEvent::pos() const
18 {
19     if (mMouseEvent)
20     {
21         return mMouseEvent->pos();
22     }
23     else if (mTabletEvent)
24     {
25         return mTabletEvent->pos();
26     }
27     Q_ASSERT(false);
28     return QPoint();
29 }
30 
posF() const31 QPointF PointerEvent::posF() const
32 {
33     if (mMouseEvent)
34     {
35         return mMouseEvent->localPos();
36     }
37     else if (mTabletEvent)
38     {
39         return mTabletEvent->posF();
40     }
41     Q_ASSERT(false);
42     return QPointF();
43 }
44 
button() const45 Qt::MouseButton PointerEvent::button() const
46 {
47     if (mMouseEvent)
48     {
49         return mMouseEvent->button();
50     }
51     else if (mTabletEvent)
52     {
53         return mTabletEvent->button();
54     }
55     // if we land here... the incoming input was
56     // neither tablet nor mouse
57     Q_ASSERT(false);
58     return Qt::NoButton;
59 }
60 
buttons() const61 Qt::MouseButtons PointerEvent::buttons() const
62 {
63     if (mMouseEvent)
64     {
65         return mMouseEvent->buttons();
66     }
67     else if (mTabletEvent)
68     {
69         return mTabletEvent->buttons();
70     }
71     // if we land here... the incoming input was
72     // neither tablet nor mouse
73     Q_ASSERT(false);
74     return Qt::NoButton;
75 }
76 
pressure() const77 qreal PointerEvent::pressure() const
78 {
79     if (mTabletEvent)
80     {
81         return mTabletEvent->pressure();
82     }
83     return 1.0;
84 }
85 
rotation() const86 qreal PointerEvent::rotation() const
87 {
88     if (mTabletEvent)
89     {
90         return mTabletEvent->rotation();
91     }
92     return 0.0;
93 }
94 
tangentialPressure() const95 qreal PointerEvent::tangentialPressure() const
96 {
97     if (mTabletEvent)
98     {
99         return mTabletEvent->tangentialPressure();
100     }
101     return 0.0;
102 }
103 
x() const104 int PointerEvent::x() const
105 {
106     if (mMouseEvent)
107     {
108         return mMouseEvent->x();
109     }
110     else if (mTabletEvent)
111     {
112         return mTabletEvent->x();
113     }
114     else
115     {
116         Q_ASSERT(false);
117         return 0;
118     }
119 
120 }
121 
y() const122 int PointerEvent::y() const
123 {
124     if (mMouseEvent)
125     {
126         return mMouseEvent->y();
127     }
128     else if (mTabletEvent)
129     {
130         return mTabletEvent->y();
131     }
132     else
133     {
134         Q_ASSERT(false);
135         return 0;
136     }
137 }
138 
isTabletEvent() const139 bool PointerEvent::isTabletEvent() const
140 {
141     if (mTabletEvent)
142     {
143         return true;
144     }
145     else
146     {
147         return false;
148     }
149 }
150 
modifiers() const151 Qt::KeyboardModifiers PointerEvent::modifiers() const
152 {
153     if (mMouseEvent)
154     {
155         return mMouseEvent->modifiers();
156     }
157     else if (mTabletEvent)
158     {
159         return mTabletEvent->modifiers();
160     }
161 
162     Q_ASSERT(false);
163     return Qt::NoModifier;
164 }
165 
accept()166 void PointerEvent::accept()
167 {
168     if (mMouseEvent)
169     {
170         mMouseEvent->accept();
171     }
172     else if (mTabletEvent)
173     {
174         mTabletEvent->accept();
175     }
176     else
177     {
178         Q_ASSERT(false);
179     }
180 }
181 
ignore()182 void PointerEvent::ignore()
183 {
184     if (mMouseEvent)
185     {
186         mMouseEvent->ignore();
187     }
188     else if (mTabletEvent)
189     {
190         mTabletEvent->ignore();
191     }
192     else
193     {
194         Q_ASSERT(false);
195     }
196 }
197 
isAccepted()198 bool PointerEvent::isAccepted()
199 {
200     if (mMouseEvent)
201     {
202         return mMouseEvent->isAccepted();
203     }
204     else if (mTabletEvent)
205     {
206         return mTabletEvent->isAccepted();
207     }
208     Q_ASSERT(false);
209     return false;
210 }
211 
eventType() const212 QEvent::Type PointerEvent::eventType() const
213 {
214     if (mMouseEvent)
215     {
216         return mMouseEvent->type();
217     }
218     else if (mTabletEvent)
219     {
220         return mTabletEvent->type();
221     }
222     return QEvent::None;
223 }
224 
inputType() const225 PointerEvent::InputType PointerEvent::inputType() const
226 {
227     if (mMouseEvent) {
228         return InputType::Mouse;
229     }
230     else if (mTabletEvent)
231     {
232         return InputType::Tablet;
233     }
234     return InputType::Unknown;
235 }
236 
device() const237 QTabletEvent::TabletDevice PointerEvent::device() const
238 {
239     if (mTabletEvent)
240     {
241         return mTabletEvent->device();
242     }
243     return QTabletEvent::TabletDevice::NoDevice;
244 }
245 
pointerType() const246 QTabletEvent::PointerType PointerEvent::pointerType() const
247 {
248     if (mTabletEvent)
249     {
250         return mTabletEvent->pointerType();
251     }
252     return QTabletEvent::PointerType::UnknownPointer;
253 }
254 
255 //QEvent::device
256