@@ -33,143 +33,141 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
33
#include " pq3DViewEventTranslator.h"
34
34
35
35
#include < QEvent>
36
- #include < QMouseEvent>
37
36
#include < QKeyEvent>
37
+ #include < QMouseEvent>
38
38
#include < QWidget>
39
39
40
40
pq3DViewEventTranslator::pq3DViewEventTranslator (const QByteArray& classname, QObject* p)
41
- : pqWidgetEventTranslator(p), mClassType(classname),
42
- lastMoveEvent(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(),
43
- Qt::MouseButtons(), Qt::KeyboardModifiers())
41
+ : pqWidgetEventTranslator(p)
42
+ , mClassType(classname)
43
+ , lastMoveEvent(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(), Qt::MouseButtons(),
44
+ Qt::KeyboardModifiers())
44
45
{
45
46
}
46
47
47
48
pq3DViewEventTranslator::~pq3DViewEventTranslator ()
48
49
{
49
50
}
50
51
51
- bool pq3DViewEventTranslator::translateEvent (QObject* Object, QEvent* Event,
52
- bool & Error)
52
+ bool pq3DViewEventTranslator::translateEvent (QObject* Object, QEvent* Event, bool & Error)
53
53
{
54
54
QWidget* widget = qobject_cast<QWidget*>(Object);
55
- if (!widget || !Object->inherits (mClassType .data ()))
56
- {
55
+ if (!widget || !Object->inherits (mClassType .data ()))
56
+ {
57
57
return false ;
58
- }
58
+ }
59
59
60
- switch (Event->type ())
61
- {
60
+ switch (Event->type ())
61
+ {
62
62
case QEvent::ContextMenu:
63
- {
63
+ {
64
64
return true ;
65
65
break ;
66
- }
66
+ }
67
67
68
68
case QEvent::MouseButtonPress:
69
- {
69
+ {
70
70
QMouseEvent* mouseEvent = dynamic_cast <QMouseEvent*>(Event);
71
71
if (mouseEvent)
72
- {
72
+ {
73
73
QSize size = widget->size ();
74
- double normalized_x = mouseEvent->x ()/ static_cast <double >(size.width ());
75
- double normalized_y = mouseEvent->y ()/ static_cast <double >(size.height ());
74
+ double normalized_x = mouseEvent->x () / static_cast <double >(size.width ());
75
+ double normalized_y = mouseEvent->y () / static_cast <double >(size.height ());
76
76
int button = mouseEvent->button ();
77
77
int buttons = mouseEvent->buttons ();
78
78
int modifiers = mouseEvent->modifiers ();
79
79
emit recordEvent (Object, " mousePress" , QString (" (%1,%2,%3,%4,%5)" )
80
- .arg (normalized_x)
81
- .arg (normalized_y)
82
- .arg (button)
83
- .arg (buttons)
84
- .arg (modifiers));
85
- }
80
+ .arg (normalized_x)
81
+ .arg (normalized_y)
82
+ .arg (button)
83
+ .arg (buttons)
84
+ .arg (modifiers));
85
+ }
86
86
87
87
// reset lastMoveEvent
88
- QMouseEvent e (QEvent::MouseButtonPress, QPoint (), Qt::MouseButton (),
89
- Qt::MouseButtons (), Qt::KeyboardModifiers ());
88
+ QMouseEvent e (QEvent::MouseButtonPress, QPoint (), Qt::MouseButton (), Qt::MouseButtons (),
89
+ Qt::KeyboardModifiers ());
90
90
91
91
lastMoveEvent = e;
92
92
return true ;
93
93
break ;
94
- }
94
+ }
95
95
96
96
case QEvent::MouseMove:
97
- {
97
+ {
98
98
QMouseEvent* mouseEvent = dynamic_cast <QMouseEvent*>(Event);
99
99
if (mouseEvent)
100
- {
100
+ {
101
101
QMouseEvent e (QEvent::MouseMove, QPoint (mouseEvent->x (), mouseEvent->y ()),
102
- mouseEvent->button (), mouseEvent->buttons (),
103
- mouseEvent->modifiers ());
102
+ mouseEvent->button (), mouseEvent->buttons (), mouseEvent->modifiers ());
104
103
105
104
lastMoveEvent = e;
106
- }
105
+ }
107
106
return true ;
108
107
break ;
109
- }
108
+ }
110
109
111
110
case QEvent::MouseButtonRelease:
112
- {
111
+ {
113
112
QMouseEvent* mouseEvent = dynamic_cast <QMouseEvent*>(Event);
114
113
if (mouseEvent)
115
- {
114
+ {
116
115
QSize size = widget->size ();
117
116
118
117
// record last move event if it is valid
119
- if (lastMoveEvent.type () == QEvent::MouseMove)
120
- {
121
- double normalized_x = lastMoveEvent.x ()/ static_cast <double >(size.width ());
122
- double normalized_y = lastMoveEvent.y ()/ static_cast <double >(size.height ());
118
+ if (lastMoveEvent.type () == QEvent::MouseMove)
119
+ {
120
+ double normalized_x = lastMoveEvent.x () / static_cast <double >(size.width ());
121
+ double normalized_y = lastMoveEvent.y () / static_cast <double >(size.height ());
123
122
int button = lastMoveEvent.button ();
124
123
int buttons = lastMoveEvent.buttons ();
125
124
int modifiers = lastMoveEvent.modifiers ();
126
125
127
126
emit recordEvent (Object, " mouseMove" , QString (" (%1,%2,%3,%4,%5)" )
128
- .arg (normalized_x)
129
- .arg (normalized_y)
130
- .arg (button)
131
- .arg (buttons)
132
- .arg (modifiers));
133
- }
134
-
127
+ .arg (normalized_x)
128
+ .arg (normalized_y)
129
+ .arg (button)
130
+ .arg (buttons)
131
+ .arg (modifiers));
132
+ }
135
133
136
- double normalized_x = mouseEvent->x ()/ static_cast <double >(size.width ());
137
- double normalized_y = mouseEvent->y ()/ static_cast <double >(size.height ());
134
+ double normalized_x = mouseEvent->x () / static_cast <double >(size.width ());
135
+ double normalized_y = mouseEvent->y () / static_cast <double >(size.height ());
138
136
int button = mouseEvent->button ();
139
137
int buttons = mouseEvent->buttons ();
140
138
int modifiers = mouseEvent->modifiers ();
141
139
142
140
emit recordEvent (Object, " mouseRelease" , QString (" (%1,%2,%3,%4,%5)" )
143
- .arg (normalized_x)
144
- .arg (normalized_y)
145
- .arg (button)
146
- .arg (buttons)
147
- .arg (modifiers));
148
- }
141
+ .arg (normalized_x)
142
+ .arg (normalized_y)
143
+ .arg (button)
144
+ .arg (buttons)
145
+ .arg (modifiers));
146
+ }
149
147
return true ;
150
148
break ;
151
- }
149
+ }
152
150
153
151
case QEvent::KeyPress:
154
152
case QEvent::KeyRelease:
155
- {
153
+ {
156
154
QKeyEvent* ke = static_cast <QKeyEvent*>(Event);
157
- QString data =QString (" %1:%2:%3:%4:%5:%6" )
158
- .arg (ke->type ())
159
- .arg (ke->key ())
160
- .arg (static_cast <int >(ke->modifiers ()))
161
- .arg (ke->text ())
162
- .arg (ke->isAutoRepeat ())
163
- .arg (ke->count ());
155
+ QString data = QString (" %1:%2:%3:%4:%5:%6" )
156
+ .arg (ke->type ())
157
+ .arg (ke->key ())
158
+ .arg (static_cast <int >(ke->modifiers ()))
159
+ .arg (ke->text ())
160
+ .arg (ke->isAutoRepeat ())
161
+ .arg (ke->count ());
164
162
emit recordEvent (Object, " keyEvent" , data);
165
163
return true ;
166
164
break ;
167
- }
165
+ }
168
166
169
167
default :
170
- {
168
+ {
171
169
break ;
172
- }
173
170
}
171
+ }
174
172
return this ->Superclass ::translateEvent (Object, Event, Error);
175
173
}
0 commit comments