Commit ae1a4510 authored by Clinton Stimpson's avatar Clinton Stimpson
Browse files

ENH: Add support for recording mouse events for any QWidget that doesn't

      already have an event translator.  Then we don't have to make specialized
      event translators for everything.
parent 1897bd51
......@@ -78,6 +78,26 @@ bool pqBasicWidgetEventPlayer::playEvent(QObject* Object,
QCoreApplication::sendEvent(widget, &ke);
return true;
}
else if(Command.startsWith("mouse"))
{
QStringList args = Arguments.split(',');
if(args.size() == 5)
{
Qt::MouseButton button = static_cast<Qt::MouseButton>(args[0].toInt());
Qt::MouseButtons buttons = static_cast<Qt::MouseButton>(args[1].toInt());
Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(args[2].toInt());
int x = args[3].toInt();
int y = args[4].toInt();
QPoint pt(x,y);
QEvent::Type type = QEvent::MouseButtonPress;
type = Command == "mouseMove" ? QEvent::MouseMove : type;
type = Command == "mouseRelease" ? QEvent::MouseButtonRelease : type;
type = Command == "mouseDblClick" ? QEvent::MouseButtonDblClick : type;
QMouseEvent e(type, pt, button, buttons, keym);
QCoreApplication::sendEvent(widget, &e);
return true;
}
}
else
{
return false;
......
......@@ -52,7 +52,7 @@ bool pqBasicWidgetEventTranslator::translateEvent(QObject* Object,
QWidget* const object = qobject_cast<QWidget*>(Object);
if(!object)
return false;
switch(Event->type())
{
case QEvent::ContextMenu:
......@@ -60,6 +60,63 @@ bool pqBasicWidgetEventTranslator::translateEvent(QObject* Object,
emit recordEvent(Object, "contextMenu", "");
}
break;
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonRelease:
{
bool consumeThisEvent = false;
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(Event);
if(!this->Parents.empty() && this->Parents.first() == object)
{
// right on track
consumeThisEvent = true;
this->Parents.removeFirst();
}
if(!consumeThisEvent)
{
// find the chain of parent that will get this mouse event
this->Parents.clear();
for(QWidget* w = object->parentWidget(); w; w = w->parentWidget())
{
this->Parents.append(w);
if(w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
{
break;
}
}
QString info = QString("%1,%2,%3,%4,%5")
.arg(mouseEvent->button())
.arg(mouseEvent->buttons())
.arg(mouseEvent->modifiers())
.arg(mouseEvent->x())
.arg(mouseEvent->y());
if(Event->type() != QEvent::MouseButtonRelease)
{
this->LastPos = mouseEvent->pos();
}
if(Event->type() == QEvent::MouseButtonPress)
{
emit recordEvent(object, "mousePress", info);
}
if(Event->type() == QEvent::MouseButtonDblClick)
{
emit recordEvent(object, "mouseDblClick", info);
}
else if(Event->type() == QEvent::MouseButtonRelease)
{
if(this->LastPos != mouseEvent->pos())
{
emit recordEvent(object, "mouseMove", info);
}
emit recordEvent(object, "mouseRelease", info);
}
}
}
break;
default:
break;
}
......
......@@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define _pqBasicWidgetEventTranslator_h
#include "pqWidgetEventTranslator.h"
#include <QPointer>
#include <QWidget>
/**
Translates low-level Qt events into high-level ParaView events that can be recorded as test cases.
......@@ -52,6 +54,10 @@ public:
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
protected:
QList<QPointer<QWidget> > Parents;
QPoint LastPos;
private:
pqBasicWidgetEventTranslator(const pqBasicWidgetEventTranslator&);
pqBasicWidgetEventTranslator& operator=(const pqBasicWidgetEventTranslator&);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment