Commit b85c0b4f authored by Benjamin Long's avatar Benjamin Long

Add mousewheel support to both basic widget and itemView

parent 1452c3d2
...@@ -40,6 +40,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -40,6 +40,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QtDebug> #include <QtDebug>
#include <QList> #include <QList>
#include <QListWidget> #include <QListWidget>
#include <QWheelEvent>
#include "pqEventDispatcher.h" #include "pqEventDispatcher.h"
...@@ -152,7 +153,6 @@ bool pqAbstractItemViewEventPlayer::playEvent(QObject* Object, const QString& Co ...@@ -152,7 +153,6 @@ bool pqAbstractItemViewEventPlayer::playEvent(QObject* Object, const QString& Co
QStringList args = Arguments.split(','); QStringList args = Arguments.split(',');
if(args.size() == 6) if(args.size() == 6)
{ {
Qt::MouseButton button = static_cast<Qt::MouseButton>(args[0].toInt());
Qt::MouseButtons buttons = static_cast<Qt::MouseButton>(args[1].toInt()); Qt::MouseButtons buttons = static_cast<Qt::MouseButton>(args[1].toInt());
Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(args[2].toInt()); Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(args[2].toInt());
int x = args[3].toInt(); int x = args[3].toInt();
...@@ -178,7 +178,15 @@ bool pqAbstractItemViewEventPlayer::playEvent(QObject* Object, const QString& Co ...@@ -178,7 +178,15 @@ bool pqAbstractItemViewEventPlayer::playEvent(QObject* Object, const QString& Co
QRect r = object->visualRect(idx); QRect r = object->visualRect(idx);
pt = r.topLeft() + QPoint(x,y); pt = r.topLeft() + QPoint(x,y);
} }
if (Command == "mouseWheel")
{
// QEvent::Type type = QEvent::Wheel;
int delta = args[0].toInt();
QWheelEvent we(QPoint(x,y), delta, buttons, keym);
QCoreApplication::sendEvent(Object, &we);
return true;
}
Qt::MouseButton button = static_cast<Qt::MouseButton>(args[0].toInt());
QEvent::Type type = QEvent::MouseButtonPress; QEvent::Type type = QEvent::MouseButtonPress;
type = Command == "mouseMove" ? QEvent::MouseMove : type; type = Command == "mouseMove" ? QEvent::MouseMove : type;
type = Command == "mouseRelease" ? QEvent::MouseButtonRelease : type; type = Command == "mouseRelease" ? QEvent::MouseButtonRelease : type;
......
...@@ -136,6 +136,34 @@ bool pqAbstractItemViewEventTranslator::translateEvent(QObject* Object, QEvent* ...@@ -136,6 +136,34 @@ bool pqAbstractItemViewEventTranslator::translateEvent(QObject* Object, QEvent*
emit recordEvent(object, "mouseRelease", info); emit recordEvent(object, "mouseRelease", info);
} }
} }
case QEvent::Wheel:
{
if(Object == object)
{
return false;
}
QPoint relPt = QPoint(0,0);
QWheelEvent* wheelEvent = dynamic_cast<QWheelEvent*>(Event);
if(wheelEvent)
{
QString idxStr;
QModelIndex idx = object->indexAt(wheelEvent->pos());
idxStr = toIndexStr(idx);
QRect r = object->visualRect(idx);
relPt = wheelEvent->pos() - r.topLeft();
int numStep = wheelEvent->delta();
int buttons = wheelEvent->buttons();
int modifiers = wheelEvent->modifiers();
emit emit recordEvent(Object, "mouseWheel", QString("%1,%2,%3,%4,%5")
.arg(numStep)
.arg(buttons)
.arg(modifiers)
.arg(relPt.x())
.arg(relPt.y())
.arg(idxStr));
}
}
break;
default: default:
break; break;
} }
......
...@@ -83,12 +83,20 @@ bool pqBasicWidgetEventPlayer::playEvent(QObject* Object, ...@@ -83,12 +83,20 @@ bool pqBasicWidgetEventPlayer::playEvent(QObject* Object,
QStringList args = Arguments.split(','); QStringList args = Arguments.split(',');
if(args.size() == 5) 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::MouseButtons buttons = static_cast<Qt::MouseButton>(args[1].toInt());
Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(args[2].toInt()); Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(args[2].toInt());
int x = args[3].toInt(); int x = args[3].toInt();
int y = args[4].toInt(); int y = args[4].toInt();
QPoint pt(x,y); QPoint pt(x,y);
if (Command == "mouseWheel")
{
// QEvent::Type type = QEvent::Wheel;
int delta = args[0].toInt();
QWheelEvent we(QPoint(x,y), delta, buttons, keym);
QCoreApplication::sendEvent(Object, &we);
return true;
}
Qt::MouseButton button = static_cast<Qt::MouseButton>(args[0].toInt());
QEvent::Type type = QEvent::MouseButtonPress; QEvent::Type type = QEvent::MouseButtonPress;
type = Command == "mouseMove" ? QEvent::MouseMove : type; type = Command == "mouseMove" ? QEvent::MouseMove : type;
type = Command == "mouseRelease" ? QEvent::MouseButtonRelease : type; type = Command == "mouseRelease" ? QEvent::MouseButtonRelease : type;
......
...@@ -95,6 +95,22 @@ bool pqBasicWidgetEventTranslator::translateEvent(QObject* Object, ...@@ -95,6 +95,22 @@ bool pqBasicWidgetEventTranslator::translateEvent(QObject* Object,
} }
} }
break; break;
case QEvent::Wheel:
{
QWheelEvent* wheelEvent = dynamic_cast<QWheelEvent*>(Event);
if(wheelEvent)
{
int buttons = wheelEvent->buttons();
int modifiers = wheelEvent->modifiers();
emit emit recordEvent(Object, "mouseWheel", QString("%1,%2,%3,%4,%5")
.arg(wheelEvent->delta())
.arg(buttons)
.arg(modifiers)
.arg(wheelEvent->x())
.arg(wheelEvent->y()));
}
}
break;
default: default:
break; break;
} }
......
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