-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpq3DViewEventPlayer.cxx
52 lines (49 loc) · 1.91 KB
/
pq3DViewEventPlayer.cxx
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
// SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
// SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
// SPDX-License-Identifier: BSD-3-Clause
#include "pq3DViewEventPlayer.h"
#include <QApplication>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QRegularExpression>
#include <QWidget>
#include <QtDebug>
pq3DViewEventPlayer::pq3DViewEventPlayer(const QByteArray& classname, QObject* p)
: pqWidgetEventPlayer(p)
, mClassType(classname)
{
}
bool pq3DViewEventPlayer::playEvent(
QObject* Object, const QString& Command, const QString& Arguments, bool& Error)
{
QWidget* widget = qobject_cast<QWidget*>(Object);
if (widget && Object->inherits(mClassType.data()))
{
if (Command == "mousePress" || Command == "mouseRelease" || Command == "mouseMove")
{
QRegularExpression mouseRegExp("\\(([^,]*),([^,]*),([^,]),([^,]),([^,]*)\\)");
QRegularExpressionMatch match = mouseRegExp.match(Arguments);
if (match.hasMatch())
{
QVariant v = match.captured(1);
int x = static_cast<int>(v.toDouble() * widget->size().width());
v = match.captured(2);
int y = static_cast<int>(v.toDouble() * widget->size().height());
v = match.captured(3);
Qt::MouseButton button = static_cast<Qt::MouseButton>(v.toInt());
v = match.captured(4);
Qt::MouseButtons buttons = static_cast<Qt::MouseButton>(v.toInt());
v = match.captured(5);
Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(v.toInt());
QEvent::Type type = (Command == "mousePress")
? QEvent::MouseButtonPress
: ((Command == "mouseMove") ? QEvent::MouseMove : QEvent::MouseButtonRelease);
QPoint pos(x, y);
QMouseEvent e(type, pos, widget->mapToGlobal(pos), button, buttons, keym);
qApp->notify(Object, &e);
}
return true;
}
}
return this->Superclass::playEvent(Object, Command, Arguments, Error);
}