diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2010-04-16 06:50:27 (GMT) |
---|---|---|
committer | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2010-04-19 00:20:18 (GMT) |
commit | 5efb732bc78e15605ac9d9f770e1bd24c01bb778 (patch) | |
tree | 952639777368bcdfd444415d9890cf1403d0ec3b /src/declarative/graphicsitems/qdeclarativemousearea.cpp | |
parent | 465f4df8ad4be9485c37ecc379c45e758b2842ad (diff) | |
download | Qt-5efb732bc78e15605ac9d9f770e1bd24c01bb778.zip Qt-5efb732bc78e15605ac9d9f770e1bd24c01bb778.tar.gz Qt-5efb732bc78e15605ac9d9f770e1bd24c01bb778.tar.bz2 |
Update mouse area coordinates automatically when changing position
Mouse area coordinates are now updated when the mouse area changes position
and positionChanged signals are not emitted on mousePress anymore (only
mousePosChanged signals).
Task-number: QTBUG-9716
Reviewed-by: Michael Brasser
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativemousearea.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativemousearea.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index a6cc75e..52dbc42 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -466,6 +466,9 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) d->moved = true; } QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit mousePosChanged(&me); + me.setX(d->lastPos.x()); + me.setY(d->lastPos.y()); emit positionChanged(&me); } @@ -518,6 +521,9 @@ void QDeclarativeMouseArea::hoverMoveEvent(QGraphicsSceneHoverEvent *event) } else { d->lastPos = event->pos(); QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit mousePosChanged(&me); + me.setX(d->lastPos.x()); + me.setY(d->lastPos.y()); emit positionChanged(&me); } } @@ -561,6 +567,18 @@ void QDeclarativeMouseArea::timerEvent(QTimerEvent *event) } } +void QDeclarativeMouseArea::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + Q_D(QDeclarativeMouseArea); + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); + + if (d->lastScenePos.isNull) + d->lastScenePos = mapToScene(d->lastPos); + else if (newGeometry.x() != oldGeometry.x() || newGeometry.y() != oldGeometry.y()) + d->lastPos = mapFromScene(d->lastScenePos); +} + /*! \qmlproperty bool MouseArea::hoverEnabled This property holds whether hover events are handled. @@ -648,9 +666,13 @@ bool QDeclarativeMouseArea::setPressed(bool p) QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); if (d->pressed) { emit pressed(&me); - emit positionChanged(&me); + me.setX(d->lastPos.x()); + me.setY(d->lastPos.y()); + emit mousePosChanged(&me); } else { emit released(&me); + me.setX(d->lastPos.x()); + me.setY(d->lastPos.y()); if (isclick && !d->longPress) emit clicked(&me); } |