aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-02-12 13:40:20 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-02-12 13:56:03 +0000
commit572d7011f123324e70dde4c75260f32cd696f709 (patch)
tree8b57b4b19c51bc69aa2bdc15f0a3d1a12e9bd174
parent17614b700e313648839885ae9814e7f62682be88 (diff)
Test and fix AbstractButton::pressAndHold()
Using the same auto test that already exists for TextField and TextArea nicely exposed some difference in the behavior: - the signal wasn't canceled on second press - the signal was canceled right away on any tiny move. now it allows the same little threshold than TextField and TextArea Change-Id: I6b9bd19c614b36dd0ec7b232f821af3aa929d02a Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--src/templates/qquickabstractbutton.cpp7
-rw-r--r--tests/auto/pressandhold/tst_pressandhold.cpp11
2 files changed, 12 insertions, 6 deletions
diff --git a/src/templates/qquickabstractbutton.cpp b/src/templates/qquickabstractbutton.cpp
index 6aa44cad..95afc09d 100644
--- a/src/templates/qquickabstractbutton.cpp
+++ b/src/templates/qquickabstractbutton.cpp
@@ -122,6 +122,7 @@ void QQuickAbstractButtonPrivate::startPressAndHold()
{
Q_Q(QQuickAbstractButton);
wasHeld = false;
+ stopPressAndHold();
if (isPressAndHoldConnected())
holdTimer = q->startTimer(QGuiApplication::styleHints()->mousePressAndHoldInterval());
}
@@ -515,8 +516,10 @@ void QQuickAbstractButton::mousePressEvent(QMouseEvent *event)
if (d->autoRepeat) {
d->startRepeatDelay();
d->repeatButton = event->button();
- } else {
+ } else if (Qt::LeftButton == (event->buttons() & Qt::LeftButton)) {
d->startPressAndHold();
+ } else {
+ d->stopPressAndHold();
}
}
@@ -528,7 +531,7 @@ void QQuickAbstractButton::mouseMoveEvent(QMouseEvent *event)
if (d->autoRepeat)
d->stopPressRepeat();
- else if (!d->pressed)
+ else if (d->holdTimer > 0 && QLineF(d->pressPoint, event->localPos()).length() > QGuiApplication::styleHints()->startDragDistance())
d->stopPressAndHold();
}
diff --git a/tests/auto/pressandhold/tst_pressandhold.cpp b/tests/auto/pressandhold/tst_pressandhold.cpp
index 33d93cc0..8c4cf673 100644
--- a/tests/auto/pressandhold/tst_pressandhold.cpp
+++ b/tests/auto/pressandhold/tst_pressandhold.cpp
@@ -54,14 +54,17 @@ private slots:
void tst_PressAndHold::pressAndHold_data()
{
QTest::addColumn<QByteArray>("data");
+ QTest::addColumn<QByteArray>("signal");
- QTest::newRow("TextField") << QByteArray("import Qt.labs.controls 1.0; TextField { text: 'TextField' }");
- QTest::newRow("TextArea") << QByteArray("import Qt.labs.controls 1.0; TextArea { text: 'TextArea' }");
+ QTest::newRow("Button") << QByteArray("import Qt.labs.controls 1.0; Button { text: 'Button' }") << QByteArray(SIGNAL(pressAndHold()));
+ QTest::newRow("TextField") << QByteArray("import Qt.labs.controls 1.0; TextField { text: 'TextField' }") << QByteArray(SIGNAL(pressAndHold(QQuickMouseEvent*)));
+ QTest::newRow("TextArea") << QByteArray("import Qt.labs.controls 1.0; TextArea { text: 'TextArea' }") << QByteArray(SIGNAL(pressAndHold(QQuickMouseEvent*)));
}
void tst_PressAndHold::pressAndHold()
{
QFETCH(QByteArray, data);
+ QFETCH(QByteArray, signal);
QQmlEngine engine;
QQmlComponent component(&engine);
@@ -71,8 +74,8 @@ void tst_PressAndHold::pressAndHold()
QScopedPointer<QObject> waitControl(component.create());
QVERIFY(!control.isNull() && !waitControl.isNull());
- QSignalSpy spy(control.data(), SIGNAL(pressAndHold(QQuickMouseEvent*)));
- QSignalSpy waitSpy(waitControl.data(), SIGNAL(pressAndHold(QQuickMouseEvent*)));
+ QSignalSpy spy(control.data(), signal);
+ QSignalSpy waitSpy(waitControl.data(), signal);
QVERIFY(spy.isValid() && waitSpy.isValid());
int startDragDistance = QGuiApplication::styleHints()->startDragDistance();