summaryrefslogtreecommitdiffstats
path: root/src/declarative/fx
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-08-19 03:34:59 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-08-19 03:34:59 (GMT)
commit84b76c452833f52891593f317a64bc78c7486bbf (patch)
treeddb0455d0404f25f49c15b65568518a77d42f532 /src/declarative/fx
parentb3c992c9b53d8f1630bdbc7472a29910f11ee035 (diff)
downloadQt-84b76c452833f52891593f317a64bc78c7486bbf.zip
Qt-84b76c452833f52891593f317a64bc78c7486bbf.tar.gz
Qt-84b76c452833f52891593f317a64bc78c7486bbf.tar.bz2
Make MouseRegion event propagation match GV.
Diffstat (limited to 'src/declarative/fx')
-rw-r--r--src/declarative/fx/qfxevents_p.h2
-rw-r--r--src/declarative/fx/qfxmouseregion.cpp42
-rw-r--r--src/declarative/fx/qfxmouseregion.h6
-rw-r--r--src/declarative/fx/qfxmouseregion_p.h13
4 files changed, 47 insertions, 16 deletions
diff --git a/src/declarative/fx/qfxevents_p.h b/src/declarative/fx/qfxevents_p.h
index fbf0c5f..7b0c24c 100644
--- a/src/declarative/fx/qfxevents_p.h
+++ b/src/declarative/fx/qfxevents_p.h
@@ -105,7 +105,7 @@ public:
QFxMouseEvent(int x, int y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers
, bool isClick=false, bool wasHeld=false)
: _x(x), _y(y), _button(button), _buttons(buttons), _modifiers(modifiers)
- , _wasHeld(wasHeld), _isClick(isClick), _accepted(false) {}
+ , _wasHeld(wasHeld), _isClick(isClick), _accepted(true) {}
int x() const { return _x; }
int y() const { return _y; }
diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp
index 2a198f2..1125673 100644
--- a/src/declarative/fx/qfxmouseregion.cpp
+++ b/src/declarative/fx/qfxmouseregion.cpp
@@ -164,6 +164,8 @@ void QFxDrag::setYmax(qreal m)
The \l {MouseEvent}{mouse} parameter provides information about the mouse, including the x and y
position, and any buttons currently pressed.
+
+ The \e accepted property of the MouseEvent parameter is ignored in this handler.
*/
/*!
@@ -175,6 +177,8 @@ void QFxDrag::setYmax(qreal m)
The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y
position of the release of the click, and whether the click wasHeld.
+
+ The \e accepted property of the MouseEvent parameter is ignored in this handler.
*/
/*!
@@ -183,6 +187,12 @@ void QFxDrag::setYmax(qreal m)
This handler is called when there is a press.
The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y
position and which button was pressed.
+
+ The \e accepted property of the MouseEvent parameter determines whether this MouseRegion
+ will handle the press \b {and all future mouse events until release}. The default is to accept
+ the event and not allow other MouseRegions beneath this one to handle the event. If \e accepted
+ is set to false, \b {no further events will be sent to this MouseRegion} until the button is next
+ pressed.
*/
/*!
@@ -191,6 +201,8 @@ void QFxDrag::setYmax(qreal m)
This handler is called when there is a release.
The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y
position of the release of the click, and whether the click wasHeld.
+
+ The \e accepted property of the MouseEvent parameter is ignored in this handler.
*/
/*!
@@ -199,6 +211,8 @@ void QFxDrag::setYmax(qreal m)
This handler is called when there is a long press (currently 800ms).
The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y
position of the press, and which button is pressed.
+
+ The \e accepted property of the MouseEvent parameter is ignored in this handler.
*/
/*!
@@ -207,6 +221,8 @@ void QFxDrag::setYmax(qreal m)
This handler is called when there is a double-click (a press followed by a release followed by a press).
The \l {MouseEvent}{mouse} parameter provides information about the click, including the x and y
position of the release of the click, and whether the click wasHeld.
+
+ The \e accepted property of the MouseEvent parameter is ignored in this handler.
*/
QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,MouseRegion,QFxMouseRegion)
@@ -292,11 +308,11 @@ void QFxMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event)
d->dragged = false;
d->start = event->pos();
d->startScene = event->scenePos();
- // ### we should only start timer if pressAndHold is connected to (but connectNotify doesn't work)
- d->pressAndHoldTimer.start(PressAndHoldDelay, this);
+ // we should only start timer if pressAndHold is connected to.
+ if (d->isConnected("pressAndHold(QFxMouseEvent*)"))
+ d->pressAndHoldTimer.start(PressAndHoldDelay, this);
setKeepMouseGrab(false);
- setPressed(true);
- event->accept();
+ event->setAccepted(setPressed(true));
}
}
@@ -366,7 +382,6 @@ void QFxMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
d->moved = true;
QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress);
emit positionChanged(&me);
- event->accept();
}
@@ -378,7 +393,6 @@ void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
else {
d->saveEvent(event);
setPressed(false);
- event->accept();
}
}
@@ -388,11 +402,13 @@ void QFxMouseRegion::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
if (!d->absorb)
QFxItem::mouseDoubleClickEvent(event);
else {
- d->saveEvent(event);
- setPressed(true);
- QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false);
- emit this->doubleClicked(&me);
- event->accept();
+ QFxItem::mouseDoubleClickEvent(event);
+ if (event->isAccepted()) {
+ // Only deliver the event if we have accepted the press.
+ d->saveEvent(event);
+ QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false);
+ emit this->doubleClicked(&me);
+ }
}
}
@@ -523,7 +539,7 @@ void QFxMouseRegion::setAcceptedButtons(Qt::MouseButtons buttons)
}
}
-void QFxMouseRegion::setPressed(bool p)
+bool QFxMouseRegion::setPressed(bool p)
{
Q_D(QFxMouseRegion);
bool isclick = d->pressed == true && p == false && d->dragged == false && d->hovered == true;
@@ -541,7 +557,9 @@ void QFxMouseRegion::setPressed(bool p)
}
emit pressedChanged();
+ return me.isAccepted();
}
+ return false;
}
QFxDrag *QFxMouseRegion::drag()
diff --git a/src/declarative/fx/qfxmouseregion.h b/src/declarative/fx/qfxmouseregion.h
index 84bb493..ae54ff6 100644
--- a/src/declarative/fx/qfxmouseregion.h
+++ b/src/declarative/fx/qfxmouseregion.h
@@ -121,9 +121,6 @@ public:
bool hovered() const;
bool pressed() const;
- void setHovered(bool);
- void setPressed(bool);
-
Qt::MouseButtons acceptedButtons() const;
void setAcceptedButtons(Qt::MouseButtons buttons);
@@ -145,6 +142,9 @@ Q_SIGNALS:
void exited();
protected:
+ void setHovered(bool);
+ bool setPressed(bool);
+
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
diff --git a/src/declarative/fx/qfxmouseregion_p.h b/src/declarative/fx/qfxmouseregion_p.h
index d981b85..70df8d1 100644
--- a/src/declarative/fx/qfxmouseregion_p.h
+++ b/src/declarative/fx/qfxmouseregion_p.h
@@ -83,6 +83,19 @@ public:
lastModifiers = event->modifiers();
}
+ bool isConnected(const char *signal) {
+ Q_Q(QFxMouseRegion);
+ int idx = QFxMouseRegion::staticMetaObject.indexOfSignal(signal);
+ if (idx < 32) {
+ quint32 mask = 1 << idx;
+ return QObjectPrivate::get(q)->connectedSignals[0] & mask;
+ } else if (idx < 64) {
+ quint32 mask = 1 << (idx-32);
+ return QObjectPrivate::get(q)->connectedSignals[1] & mask;
+ }
+ return false;
+ }
+
bool absorb : 1;
bool hovered : 1;
bool pressed : 1;