A long press should allow onClicked if there is no onPressAndHold
Fixes: QTBUG-19726 Change-Id: I896c9264c1cf408dcd533b5d6d463d53c785d787 Reviewed-on: http://codereview.qt.nokia.com/2155 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
This commit is contained in:
parent
3870e1478b
commit
83eb5ba008
|
@ -803,6 +803,8 @@ void QSGMouseArea::timerEvent(QTimerEvent *event)
|
|||
emit pressAndHold(&me);
|
||||
if (!me.isAccepted())
|
||||
d->propagate(&me, QSGMouseAreaPrivate::PressAndHold);
|
||||
if (!me.isAccepted()) // no one handled the long press - allow click
|
||||
d->longPress = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
import QtQuick 2.0
|
||||
|
||||
Item {
|
||||
id: root
|
||||
property bool clicked: false
|
||||
|
||||
MouseArea {
|
||||
width: 200; height: 200
|
||||
onClicked: { root.clicked = true }
|
||||
}
|
||||
}
|
|
@ -331,27 +331,53 @@ void tst_QSGMouseArea::updateMouseAreaPosOnResize()
|
|||
|
||||
void tst_QSGMouseArea::noOnClickedWithPressAndHold()
|
||||
{
|
||||
QSGView *canvas = createView();
|
||||
canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/clickandhold.qml"));
|
||||
canvas->show();
|
||||
canvas->setFocus();
|
||||
QVERIFY(canvas->rootObject() != 0);
|
||||
{
|
||||
// We handle onPressAndHold, therefore no onClicked
|
||||
QSGView *canvas = createView();
|
||||
canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/clickandhold.qml"));
|
||||
canvas->show();
|
||||
canvas->setFocus();
|
||||
QVERIFY(canvas->rootObject() != 0);
|
||||
|
||||
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
||||
QApplication::sendEvent(canvas, &pressEvent);
|
||||
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
||||
QApplication::sendEvent(canvas, &pressEvent);
|
||||
|
||||
QVERIFY(!canvas->rootObject()->property("clicked").toBool());
|
||||
QVERIFY(!canvas->rootObject()->property("held").toBool());
|
||||
QVERIFY(!canvas->rootObject()->property("clicked").toBool());
|
||||
QVERIFY(!canvas->rootObject()->property("held").toBool());
|
||||
|
||||
QTest::qWait(1000);
|
||||
QTest::qWait(1000);
|
||||
|
||||
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
||||
QApplication::sendEvent(canvas, &releaseEvent);
|
||||
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
||||
QApplication::sendEvent(canvas, &releaseEvent);
|
||||
|
||||
QVERIFY(!canvas->rootObject()->property("clicked").toBool());
|
||||
QVERIFY(canvas->rootObject()->property("held").toBool());
|
||||
QVERIFY(!canvas->rootObject()->property("clicked").toBool());
|
||||
QVERIFY(canvas->rootObject()->property("held").toBool());
|
||||
|
||||
delete canvas;
|
||||
delete canvas;
|
||||
}
|
||||
|
||||
{
|
||||
// We do not handle onPressAndHold, therefore we get onClicked
|
||||
QSGView *canvas = createView();
|
||||
canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/noclickandhold.qml"));
|
||||
canvas->show();
|
||||
canvas->setFocus();
|
||||
QVERIFY(canvas->rootObject() != 0);
|
||||
|
||||
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
||||
QApplication::sendEvent(canvas, &pressEvent);
|
||||
|
||||
QVERIFY(!canvas->rootObject()->property("clicked").toBool());
|
||||
|
||||
QTest::qWait(1000);
|
||||
|
||||
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
||||
QApplication::sendEvent(canvas, &releaseEvent);
|
||||
|
||||
QVERIFY(canvas->rootObject()->property("clicked").toBool());
|
||||
|
||||
delete canvas;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSGMouseArea::onMousePressRejected()
|
||||
|
|
Loading…
Reference in New Issue