if hover events are accepted, intercept them too

This commit is contained in:
Marco Martin 2013-08-20 23:03:57 +02:00
parent 4426b4e089
commit 0a73ce2850
2 changed files with 38 additions and 0 deletions

View File

@ -24,6 +24,7 @@
#include <QEvent>
#include <QMouseEvent>
#include <QTimer>
#include <QQuickWindow>
#include <QDebug>
@ -83,6 +84,22 @@ void MouseEventListener::hoverLeaveEvent(QHoverEvent *event)
emit containsMouseChanged(false);
}
void MouseEventListener::hoverMoveEvent(QHoverEvent * event)
{
if (m_lastEvent == event) {
return;
}
QQuickWindow *w = window();
QPoint screenPos = QPoint();
if (w) {
w->mapToGlobal(event->pos());
}
KDeclarativeMouseEvent dme(event->pos().x(), event->pos().y(), screenPos.x(), screenPos.y(), Qt::NoButton, Qt::NoButton, event->modifiers());
emit positionChanged(&dme);
}
bool MouseEventListener::containsMouse() const
{
return m_containsMouse;
@ -185,6 +202,26 @@ bool MouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *event)
m_pressAndHoldTimer->start(PressAndHoldDelay);
break;
}
case QEvent::HoverMove: {
if (!acceptHoverEvents()) {
break;
}
m_lastEvent = event;
QHoverEvent *he = static_cast<QHoverEvent *>(event);
const QPointF myPos = item->mapToItem(this, he->pos());
QQuickWindow *w = window();
QPoint screenPos = QPoint();
if (w) {
w->mapToGlobal(myPos.toPoint());
}
KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), screenPos.x(), screenPos.y(), Qt::NoButton, Qt::NoButton, he->modifiers());
//qDebug() << "positionChanged..." << dme.x() << dme.y();
m_pressAndHoldEvent = new KDeclarativeMouseEvent(myPos.x(), myPos.y(), screenPos.x(), screenPos.y(), Qt::NoButton, Qt::NoButton, he->modifiers());
emit positionChanged(&dme);
break;
}
case QEvent::MouseMove: {
m_lastEvent = event;
QMouseEvent *me = static_cast<QMouseEvent *>(event);

View File

@ -146,6 +146,7 @@ public:
protected:
void hoverEnterEvent(QHoverEvent *event);
void hoverLeaveEvent(QHoverEvent *event);
void hoverMoveEvent(QHoverEvent * event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);