Commit 774944e0 authored by Clinton Stimpson's avatar Clinton Stimpson
Browse files

BUG: Better support for recording/playback of the flat tree view.

      Fixes #4380.
parent 58748a4c
......@@ -64,56 +64,34 @@ bool pqBasicWidgetEventTranslator::translateEvent(QObject* Object,
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonRelease:
{
bool consumeThisEvent = false;
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(Event);
if(!this->Parents.empty() && this->Parents.first() == object)
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)
{
// right on track
consumeThisEvent = true;
this->Parents.removeFirst();
this->LastPos = mouseEvent->pos();
}
if(!consumeThisEvent)
if(Event->type() == QEvent::MouseButtonPress)
{
// 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)
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())
{
if(this->LastPos != mouseEvent->pos())
{
emit recordEvent(object, "mouseMove", info);
}
emit recordEvent(object, "mouseRelease", info);
emit recordEvent(object, "mouseMove", info);
}
emit recordEvent(object, "mouseRelease", info);
}
}
break;
......
......@@ -55,7 +55,6 @@ public:
virtual bool translateEvent(QObject* Object, QEvent* Event, bool& Error);
protected:
QList<QPointer<QWidget> > Parents;
QPoint LastPos;
private:
......
......@@ -61,6 +61,10 @@ struct pqEventTranslator::pqImplementation
QVector<pqWidgetEventTranslator*> Translators;
/// Stores the set of objects that should be ignored when translating events
QSet<QObject*> IgnoredObjects;
// list of widgets for which mouse propagation will happen
// we'll only translate the first and ignore the rest
QList<QWidget*> MouseParents;
};
////////////////////////////////////////////////////////////////////////////////
......@@ -124,6 +128,36 @@ void pqEventTranslator::ignoreObject(QObject* Object)
bool pqEventTranslator::eventFilter(QObject* Object, QEvent* Event)
{
// mouse events are propagated to parents
// our event translators/players don't quite like that,
// so lets consume those extra ones
if(Event->type() == QEvent::MouseButtonPress ||
Event->type() == QEvent::MouseButtonDblClick ||
Event->type() == QEvent::MouseButtonRelease)
{
if(!this->Implementation->MouseParents.empty() &&
this->Implementation->MouseParents.first() == Object)
{
// right on track
this->Implementation->MouseParents.removeFirst();
return false;
}
QWidget* widget = qobject_cast<QWidget*>(Object);
// find the chain of parent that will get this mouse event
this->Implementation->MouseParents.clear();
for(QWidget* w = widget->parentWidget(); w; w = w->parentWidget())
{
this->Implementation->MouseParents.append(w);
if(w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation))
{
break;
}
}
}
for(int i = 0; i != this->Implementation->Translators.size(); ++i)
{
bool error = false;
......
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