summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-04-16 06:50:27 (GMT)
committerLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-04-19 00:20:18 (GMT)
commit5efb732bc78e15605ac9d9f770e1bd24c01bb778 (patch)
tree952639777368bcdfd444415d9890cf1403d0ec3b /src/declarative
parent465f4df8ad4be9485c37ecc379c45e758b2842ad (diff)
downloadQt-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')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeevents_p_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp24
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea_p.h8
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea_p_p.h2
4 files changed, 35 insertions, 3 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeevents_p_p.h b/src/declarative/graphicsitems/qdeclarativeevents_p_p.h
index 65ac8de..0e0329e 100644
--- a/src/declarative/graphicsitems/qdeclarativeevents_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeevents_p_p.h
@@ -115,6 +115,10 @@ public:
bool wasHeld() const { return _wasHeld; }
bool isClick() const { return _isClick; }
+ // only for internal usage
+ void setX(int x) { _x = x; }
+ void setY(int y) { _y = y; }
+
bool isAccepted() { return _accepted; }
void setAccepted(bool accepted) { _accepted = accepted; }
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);
}
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h
index 58faac1..cfd5fc7 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h
+++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h
@@ -108,8 +108,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeMouseArea : public QDeclarativeItem
{
Q_OBJECT
- Q_PROPERTY(qreal mouseX READ mouseX NOTIFY positionChanged)
- Q_PROPERTY(qreal mouseY READ mouseY NOTIFY positionChanged)
+ Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mousePosChanged)
+ Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mousePosChanged)
Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged)
Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
@@ -144,6 +144,7 @@ Q_SIGNALS:
void enabledChanged();
void acceptedButtonsChanged();
void positionChanged(QDeclarativeMouseEvent *mouse);
+ void mousePosChanged(QDeclarativeMouseEvent *mouse);
void pressed(QDeclarativeMouseEvent *mouse);
void pressAndHold(QDeclarativeMouseEvent *mouse);
@@ -167,6 +168,9 @@ protected:
bool sceneEvent(QEvent *);
void timerEvent(QTimerEvent *event);
+ virtual void geometryChanged(const QRectF &newGeometry,
+ const QRectF &oldGeometry);
+
private:
void handlePress();
void handleRelease();
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
index 9068c7c..4973957 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
@@ -81,6 +81,7 @@ public:
void saveEvent(QGraphicsSceneMouseEvent *event) {
lastPos = event->pos();
+ lastScenePos = event->scenePos();
lastButton = event->button();
lastButtons = event->buttons();
lastModifiers = event->modifiers();
@@ -105,6 +106,7 @@ public:
qreal startX;
qreal startY;
QPointF lastPos;
+ QDeclarativeNullableValue<QPointF> lastScenePos;
Qt::MouseButton lastButton;
Qt::MouseButtons lastButtons;
Qt::KeyboardModifiers lastModifiers;