-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouseeventpacket.cpp
68 lines (57 loc) · 1.84 KB
/
mouseeventpacket.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "mouseeventpacket.h"
#include "util.h"
#include "packet.h"
using namespace DG;
MouseEventPacket::MouseEventPacket():EventPacket(){
}
MouseEventPacket::MouseEventPacket(QEvent::Type type, const QGraphicsSceneMouseEvent* ev):EventPacket(){
_type = type;
_point = ev->scenePos().toPoint();
_button = ev->button();
_buttons = ev->buttons();
_modifires = ev->modifiers();
}
MouseEventPacket::MouseEventPacket(QEvent::Type type, const QGraphicsSceneWheelEvent* ev):EventPacket(){
_type = type;
_point = ev->scenePos().toPoint();
_buttons = ev->buttons();
_modifires = ev->modifiers();
_delta = ev->delta();
_orient = ev->orientation();
}
QEvent::Type MouseEventPacket::mouseEventType() const{
return _type;
}
const QPoint& MouseEventPacket::point() const{
return _point;
}
void MouseEventPacket::reflect() const{
if(_type == QEvent::Wheel){
QWheelEvent* event = new QWheelEvent(_point, _delta, _buttons, _modifires, _orient);
DG::Util::fireEvent(event);
}else{
QMouseEvent* event = new QMouseEvent(_type, _point, _point, _button, _buttons, _modifires);
DG::Util::fireEvent(event);
}
}
quint64 MouseEventPacket::size(){
return (sizeof(int)*4)+(sizeof(qint32)*2);
}
QDataStream& DG::operator<<(QDataStream& stream, const MouseEventPacket& packet){
stream << packet._type << packet._point << packet._button << packet._buttons << packet._modifires << packet._orient;
return stream;
}
QDataStream& DG::operator>>(QDataStream& stream, MouseEventPacket& packet){
int type;
int button;
int buttons;
int modifires;
int orient;
stream >> type >> packet._point >> button >> buttons >> modifires >> orient;
packet._type = (QEvent::Type)type;
packet._button = (Qt::MouseButton)button;
packet._buttons = (Qt::MouseButtons)buttons;
packet._modifires = (Qt::KeyboardModifiers)modifires;
packet._orient = (Qt::Orientation)orient;
return stream;
}