pay attention to not emit 2 signals per event

This commit is contained in:
Marco Martin 2012-09-17 16:27:06 +02:00
parent 5ec3f33717
commit d3d96826ac
2 changed files with 22 additions and 1 deletions

View File

@ -28,7 +28,8 @@
MouseEventListener::MouseEventListener(QDeclarativeItem *parent)
: QDeclarativeItem(parent),
m_pressed(false),
m_pressAndHoldEvent(0)
m_pressAndHoldEvent(0),
m_lastEvent(0)
{
qmlRegisterType<KDeclarativeMouseEvent>();
qmlRegisterType<KDeclarativeWheelEvent>();
@ -43,6 +44,10 @@ MouseEventListener::~MouseEventListener()
void MouseEventListener::mousePressEvent(QGraphicsSceneMouseEvent *me)
{
if (m_lastEvent == me) {
return;
}
//FIXME: when a popup window is visible: a click anywhere hides it: but the old qgraphicswidget will continue to think it's under the mouse
//doesn't seem to be any good way to properly reset this.
//this msolution will still caused a missed click after the popup is gone, but gets the situation unblocked.
@ -63,12 +68,20 @@ void MouseEventListener::mousePressEvent(QGraphicsSceneMouseEvent *me)
void MouseEventListener::mouseMoveEvent(QGraphicsSceneMouseEvent *me)
{
if (m_lastEvent == me) {
return;
}
KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
emit positionChanged(&dme);
}
void MouseEventListener::mouseReleaseEvent(QGraphicsSceneMouseEvent *me)
{
if (m_lastEvent == me) {
return;
}
KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers());
m_pressed = false;
emit released(&dme);
@ -76,6 +89,10 @@ void MouseEventListener::mouseReleaseEvent(QGraphicsSceneMouseEvent *me)
void MouseEventListener::wheelEvent(QGraphicsSceneWheelEvent *we)
{
if (m_lastEvent == we) {
return;
}
KDeclarativeWheelEvent dwe(we->pos(), we->screenPos(), we->delta(), we->buttons(), we->modifiers(), we->orientation());
emit wheelMoved(&dwe);
}
@ -98,6 +115,8 @@ bool MouseEventListener::sceneEventFilter(QGraphicsItem *item, QEvent *event)
return false;
}
m_lastEvent = event;
switch (event->type()) {
case QEvent::GraphicsSceneMousePress: {
QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);

View File

@ -148,6 +148,8 @@ private:
bool m_pressed;
KDeclarativeMouseEvent* m_pressAndHoldEvent;
QPointF m_pressAndHoldPosition;
//Important: used only for comparison. If you will ever need to access this pointer, make it a QWekapointer
QEvent *m_lastEvent;
};
#endif