All Classes Namespaces Functions Variables Enumerations Properties Pages
pointerevent.cpp
1 #include "pointerevent.h"
2 
3 PointerEvent::PointerEvent(QMouseEvent* event)
4 {
5  mMouseEvent = event;
6 }
7 
8 PointerEvent::PointerEvent(QTabletEvent* event)
9 {
10  mTabletEvent = event;
11 }
12 
13 PointerEvent::~PointerEvent()
14 {
15 }
16 
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 
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 
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 
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 
78 {
79  if (mTabletEvent)
80  {
81  return mTabletEvent->pressure();
82  }
83  return 1.0;
84 }
85 
87 {
88  if (mTabletEvent)
89  {
90  return mTabletEvent->rotation();
91  }
92  return 0.0;
93 }
94 
96 {
97  if (mTabletEvent)
98  {
99  return mTabletEvent->tangentialPressure();
100  }
101  return 0.0;
102 }
103 
104 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 
122 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 
140 {
141  if (mTabletEvent)
142  {
143  return true;
144  }
145  else
146  {
147  return false;
148  }
149 }
150 
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 
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 
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 
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 
212 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 
225 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 
237 QTabletEvent::TabletDevice PointerEvent::device() const
238 {
239  if (mTabletEvent)
240  {
241  return mTabletEvent->device();
242  }
243  return QTabletEvent::TabletDevice::NoDevice;
244 }
245 
246 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
Qt::MouseButton button() const const
qreal rotation() const const
typedef KeyboardModifiers
QEvent::Type type() const const
Qt::KeyboardModifiers modifiers() const
Returns the modifier created by keyboard while a device was in use.
qreal pressure() const const
int x() const const
int y() const const
MouseButton
QTabletEvent::TabletDevice device() const const
Qt::MouseButtons buttons() const const
QPointF posF() const
Returns the QPointF of the device Returns pos() if used on mouse event.
int x() const
Returns the x position of the input device in the widget.
const QPointF & localPos() const const
bool isAccepted() const const
void ignore()
Qt::MouseButton button() const const
QPoint pos() const
Returns QPoint of the device.
bool isTabletEvent() const
Returns true if the device was tablet, otherwise false.
Qt::MouseButtons buttons() const const
QTabletEvent::PointerType pointerType() const const
int x() const const
int y() const const
Qt::MouseButtons buttons() const
Returns Qt::MouseButtons()
Qt::KeyboardModifiers modifiers() const const
void accept()
qreal pressure() const
Returns a value between 0 and 1 for tablet events, otherwise 1.0.
qreal tangentialPressure() const
Returns the tangential pressure of a tablet's that support it This is typically given by a finger whe...
qreal rotation() const
Returns rotation value if any, otherwise 0.
qreal tangentialPressure() const const
Qt::MouseButton button() const
Returns Qt::MouseButton()
QPoint pos() const const
QPoint pos() const const
int y() const
Returns the y position of the input device in the widget.
const QPointF & posF() const const