-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpqBasicWidgetEventTranslator.cxx
More file actions
159 lines (147 loc) · 4.69 KB
/
pqBasicWidgetEventTranslator.cxx
File metadata and controls
159 lines (147 loc) · 4.69 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
// SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
// SPDX-License-Identifier: BSD-3-Clause
#include "pqBasicWidgetEventTranslator.h"
#include <QDialog>
#include <QEvent>
#include <QKeyEvent>
#include <QMetaProperty>
#include <QScrollBar>
#include <QWidget>
#include "pqEventTypes.h"
pqBasicWidgetEventTranslator::pqBasicWidgetEventTranslator(QObject* p)
: pqWidgetEventTranslator(p)
{
}
pqBasicWidgetEventTranslator::~pqBasicWidgetEventTranslator() {}
bool pqBasicWidgetEventTranslator::translateEvent(
QObject* object, QEvent* event, int eventType, bool& error)
{
QWidget* widget = qobject_cast<QWidget*>(object);
if (!widget)
return false;
if (eventType == pqEventTypes::ACTION_EVENT)
{
switch (event->type())
{
case QEvent::KeyPress:
{
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (qobject_cast<QDialog*>(object))
{
Q_EMIT recordEvent(widget, "key", QString::number(keyEvent->key()));
}
return true;
break;
}
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonRelease:
{
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
auto pos = mouseEvent->pos();
#else
auto pos = mouseEvent->position().toPoint();
#endif
QString info = QString("%1,%2,%3,%4,%5")
.arg(mouseEvent->button())
.arg(static_cast<int>(mouseEvent->buttons()))
.arg(static_cast<int>(mouseEvent->modifiers()))
.arg(pos.x())
.arg(pos.y());
if (event->type() != QEvent::MouseButtonRelease)
{
this->LastPos = mouseEvent->pos();
}
if (event->type() == QEvent::MouseButtonPress)
{
Q_EMIT recordEvent(widget, "mousePress", info);
}
if (event->type() == QEvent::MouseButtonDblClick)
{
Q_EMIT recordEvent(widget, "mouseDblClick", info);
}
else if (event->type() == QEvent::MouseButtonRelease)
{
if (this->LastPos != mouseEvent->pos())
{
Q_EMIT recordEvent(widget, "mouseMove", info);
}
Q_EMIT recordEvent(widget, "mouseRelease", info);
}
return true;
break;
}
case QEvent::Wheel:
{
if (qobject_cast<QScrollBar*>(object))
{
QWheelEvent* wheelEvent = dynamic_cast<QWheelEvent*>(event);
if (wheelEvent)
{
int buttons = wheelEvent->buttons();
int modifiers = wheelEvent->modifiers();
int numStep = wheelEvent->angleDelta().y();
Q_EMIT recordEvent(object, "mouseWheel",
QString("%1,%2,%3,%4,%5")
.arg(numStep)
.arg(buttons)
.arg(modifiers)
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
.arg(wheelEvent->position().x())
.arg(wheelEvent->position().y()));
#else
.arg(wheelEvent->x())
.arg(wheelEvent->y()));
#endif
}
}
return true;
break;
}
default:
break;
}
}
else if (eventType == pqEventTypes::CHECK_EVENT)
{
if (event->type() == QEvent::MouseMove)
{
// Check for available meta prop
QMetaProperty metaProp = widget->metaObject()->userProperty();
if (!metaProp.isValid() && qobject_cast<QWidget*>(widget->parent()) != NULL)
{
// MouseEvent can be received by the viewport
metaProp = widget->parent()->metaObject()->userProperty();
}
if (metaProp.isValid())
{
return true;
}
}
// Clicking while checking, actual check event
if (event->type() == QEvent::MouseButtonRelease)
{
// Generic Meta prop check
QMetaProperty metaProp = widget->metaObject()->userProperty();
if (!metaProp.isValid() && widget->parent() != NULL)
{
// MouseEvent can be received by the viewport, so try the parent widget
metaProp = widget->parent()->metaObject()->userProperty();
widget = qobject_cast<QWidget*>(widget->parent());
}
if (metaProp.isValid() && widget)
{
// Recover meto prop name
QString propName = metaProp.name();
// Record check event
Q_EMIT recordEvent(widget, propName,
widget->property(propName.toUtf8().data()).toString().replace("\t", " "),
pqEventTypes::CHECK_EVENT);
return true;
}
}
}
return this->Superclass::translateEvent(object, event, eventType, error);
}