summaryrefslogtreecommitdiffstats
path: root/src/declarative/fx/qfxmouseregion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/fx/qfxmouseregion.cpp')
-rw-r--r--src/declarative/fx/qfxmouseregion.cpp59
1 files changed, 36 insertions, 23 deletions
diff --git a/src/declarative/fx/qfxmouseregion.cpp b/src/declarative/fx/qfxmouseregion.cpp
index 0af3cea..be56786 100644
--- a/src/declarative/fx/qfxmouseregion.cpp
+++ b/src/declarative/fx/qfxmouseregion.cpp
@@ -41,6 +41,7 @@
#include "qfxmouseregion.h"
#include "qfxmouseregion_p.h"
+#include "qfxevents_p.h"
#include <QGraphicsSceneMouseEvent>
@@ -154,12 +155,15 @@ void QFxDrag::setYmax(int m)
</Rect>
\endcode
- For the mouse handlers the variable mouseButton is set to be one of 'Left', 'Right', 'Middle',
- or 'None'. This allows you to distinguish left and right clicking. Below we have the previous
+ Many MouseRegion signals pass a \l {qml-mouseevent}{mouse} parameter that contains
+ additional information about the mouse event, such as the position, button,
+ and any key modifiers.
+
+ Below we have the previous
example extended so as to give a different color when you right click.
\code
<Rect width="100" height="100">
- <MouseRegion anchors.fill="{parent}" onClick="if(mouseButton=='Right') { parent.color='blue';} else { parent.color = 'red';}"/>
+ <MouseRegion anchors.fill="{parent}" onClick="if(mouse.button=='Right') { parent.color='blue';} else { parent.color = 'red';}"/>
</Rect>
\endcode
@@ -197,46 +201,50 @@ void QFxDrag::setYmax(int m)
*/
/*!
- \qmlsignal MouseRegion::onClicked
+ \qmlsignal MouseRegion::onClicked(mouse)
This handler is called when there is a click. A click is defined as a press followed by a release,
both inside the MouseRegion (pressing, moving outside the MouseRegion, and then moving back inside and
releasing is also considered a click).
- The x and y parameters tell you the position of the release of the click. The followsPressAndHold parameter tells
- you whether or not the release portion of the click followed a long 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.
*/
/*!
- \qmlsignal MouseRegion::onPressed
+ \qmlsignal MouseRegion::onPressed(mouse)
This handler is called when there is a press.
- The x and y parameters tell you the position of the 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.
*/
/*!
- \qmlsignal MouseRegion::onReleased
+ \qmlsignal MouseRegion::onReleased(mouse)
This handler is called when there is a release.
- The x and y parameters tell you the position of the release. The isClick parameter tells you whether
- or not the release is part of a click. The followsPressAndHold parameter tells you whether or not the
- release followed a long 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.
*/
/*!
- \qmlsignal MouseRegion::onPressAndHold
+ \qmlsignal MouseRegion::onPressAndHold(mouse)
This handler is called when there is a long press (currently 800ms).
- The x and y parameters tell you the position of the long 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.
*/
/*!
- \qmlsignal MouseRegion::onDoubleClicked
+ \qmlsignal MouseRegion::onDoubleClicked(mouse)
This handler is called when there is a double-click (a press followed by a release followed by a press).
- The x and y parameters tell you the position of the double-click.
+ 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.
*/
QML_DEFINE_TYPE(QFxMouseRegion,MouseRegion);
+
/*!
\internal
\class QFxMouseRegion
@@ -331,7 +339,7 @@ void QFxMouseRegion::mousePressEvent(QGraphicsSceneMouseEvent *event)
emit hoveredChanged();
}
d->longPress = false;
- d->lastPos = event->pos();
+ d->saveEvent(event);
d->dragX = drag()->axis().contains(QLatin1String("x"));
d->dragY = drag()->axis().contains(QLatin1String("y"));
d->dragged = false;
@@ -355,7 +363,7 @@ void QFxMouseRegion::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
return;
}
- d->lastPos = event->pos();
+ d->saveEvent(event);
// ### we should skip this if these signals aren't used
const QRect &bounds = itemBoundingRect();
@@ -427,6 +435,7 @@ void QFxMouseRegion::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
if(!d->absorb)
QFxItem::mouseReleaseEvent(event);
else {
+ d->saveEvent(event);
setPressed(false);
//d->inside = false;
//emit hoveredChanged();
@@ -442,8 +451,10 @@ void QFxMouseRegion::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
else {
//d->inside = true;
//emit hoveredChanged();
+ d->saveEvent(event);
setPressed(true);
- emit this->doubleClicked(d->lastPos.x(), d->lastPos.y());
+ QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false);
+ emit this->doubleClicked(&me);
event->accept();
}
}
@@ -491,7 +502,8 @@ void QFxMouseRegion::timerEvent(QTimerEvent *event)
d->pressAndHoldTimer.stop();
if (d->pressed && d->dragged == false && d->inside == true) {
d->longPress = true;
- emit pressAndHold(d->lastPos.x(), d->lastPos.y());
+ QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress);
+ emit pressAndHold(&me);
}
}
}
@@ -534,12 +546,13 @@ void QFxMouseRegion::setPressed(bool p)
if(d->pressed != p) {
d->pressed = p;
+ QFxMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress);
if(d->pressed)
- emit pressed(d->lastPos.x(), d->lastPos.y());
+ emit pressed(&me);
else {
- emit released(d->lastPos.x(), d->lastPos.y(), isclick, d->longPress);
+ emit released(&me);
if (isclick)
- emit clicked(d->lastPos.x(), d->lastPos.y(), d->longPress);
+ emit clicked(&me);
}
emit pressedChanged();