New \l SpriteImage element renders animated sprites and can transition between animations.
It uses the \l Sprite element to represent each animation.
-MouseArea now propagates clicked, doubleClicked and pressAndHold differently to pressed.
-These will now be propagated to the highest-stacking-order enabled MouseArea which has a handler for them.
+MouseArea can now propagate clicked, doubleClicked and pressAndHold differently to pressed.
+These can now be propagated to the highest-stacking-order enabled MouseArea which has a handler for them.
You can still ignore these events in the handler to let them pass through.
+This behavior is triggered with the new property propagateComposedEvents.
The Binding element can now be used as a value source, and will also restore any previously
set binding when its \i when clause becomes false.
QQuickMouseAreaPrivate::QQuickMouseAreaPrivate()
: absorb(true), hovered(false), pressed(false), longPress(false),
moved(false), stealMouse(false), doubleClick(false), preventStealing(false),
- drag(0)
+ propagateComposedEvents(false), drag(0)
{
}
void QQuickMouseAreaPrivate::propagate(QQuickMouseEvent* event, PropagateType t)
{
Q_Q(QQuickMouseArea);
+ if (!propagateComposedEvents)
+ return;
QPointF scenePos = q->mapToScene(QPointF(event->x(), event->y()));
propagateHelper(event, canvas->rootItem(), scenePos, t);
}
Behavioral Change in QtQuick 2.0
From QtQuick 2.0, the signals clicked, doubleClicked and pressAndHold have a different interaction
- model with regards to the delivery of events to multiple overlapping MouseAreas. These signals will now propagate
+ model with regards to the delivery of events to multiple overlapping MouseAreas. These signals can now propagate
to all MouseAreas in the area, in painting order, until accepted by one of them. A signal is accepted by
default if there is a signal handler for it, use mouse.accepted = false; to ignore. This propagation
can send the signal to MouseAreas other than the one which accepted the press event, although that MouseArea
- will receive the signal first.
-
- Note that to get the same behavior as a QtQuick 1.0 MouseArea{} with regard to absorbing all mouse events, you will
- now need to add empty signal handlers for these three signals.
+ will receive the signal first. This behavior can be enabled by setting propagateComposedEvents to true.
\sa MouseEvent, {declarative/touchinteraction/mousearea}{MouseArea example}
*/
}
}
+
+/*!
+ \qmlproperty bool QtQuick2::MouseArea::propagateComposedEvents
+ This property holds whether composed mouse events will automatically propagate to
+ other MouseAreas.
+
+ MouseArea contains several composed events, clicked, doubleClicked,
+ and pressAndHold. These can propagate via a separate mechanism to basic
+ mouse events, like pressed, which they are composed of.
+
+ If propagateComposedEvents is set to true, then composed events will be automatically
+ propagated to other MouseAreas in the same location in the scene. They are propagated
+ in painting order until an item accepts them. Unlike pressed handling, events will
+ not be automatically accepted if no handler is present.
+
+ This property greatly simplifies the usecase of when you want to have overlapping MouseAreas
+ handling the composed events together. For example: if you want one MouseArea to handle click
+ signals and the other to handle pressAndHold, or if you want one MouseArea to handle click most
+ of the time, but pass it through when certain conditions are met.
+
+ By default this property is false.
+*/
+bool QQuickMouseArea::propagateComposedEvents() const
+{
+ Q_D(const QQuickMouseArea);
+ return d->propagateComposedEvents;
+}
+
+void QQuickMouseArea::setPropagateComposedEvents(bool prevent)
+{
+ Q_D(QQuickMouseArea);
+ if (prevent != d->propagateComposedEvents) {
+ d->propagateComposedEvents = prevent;
+ setKeepMouseGrab(d->propagateComposedEvents && d->absorb);
+ emit propagateComposedEventsChanged();
+ }
+}
+
/*!
\qmlproperty MouseButtons QtQuick2::MouseArea::pressedButtons
This property holds the mouse buttons currently pressed.
Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
Q_PROPERTY(QQuickDrag *drag READ drag CONSTANT) //### add flicking to QQuickDrag or add a QDeclarativeFlick ???
Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged)
+ Q_PROPERTY(bool propagateComposedEvents READ propagateComposedEvents WRITE setPropagateComposedEvents NOTIFY propagateComposedEventsChanged)
public:
QQuickMouseArea(QQuickItem *parent=0);
bool preventStealing() const;
void setPreventStealing(bool prevent);
+ bool propagateComposedEvents() const;
+ void setPropagateComposedEvents(bool propagate);
+
Q_SIGNALS:
void hoveredChanged();
void pressedChanged();
void mouseXChanged(QQuickMouseEvent *mouse);
void mouseYChanged(QQuickMouseEvent *mouse);
void preventStealingChanged();
+ void propagateComposedEventsChanged();
void pressed(QQuickMouseEvent *mouse);
void pressAndHold(QQuickMouseEvent *mouse);
QCOMPARE(canvas->rootObject()->property("doubleClicks").toInt(), 1);
QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 1);
+ canvas->rootObject()->setProperty("noPropagation", QVariant(true));
+
+ QTest::qWait(800); // to avoid generating a double click.
+ QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
+ QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
+
+ QTest::qWait(800); // to avoid generating a double click.
+ QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
+ QTest::qWait(1000);
+ QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
+ QTest::qWait(100);
+
+ QTest::mouseDClick(canvas, Qt::LeftButton, 0, QPoint(100,100));
+ QTest::qWait(100);
+
+ QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
+ QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 2);
+ QCOMPARE(canvas->rootObject()->property("doubleClicks").toInt(), 1);
+ QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 1);
+
delete canvas;
}