aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-04-19 13:39:41 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-04-19 12:50:52 +0000
commita02a54622a4eef49807060f9735c4c0d09833267 (patch)
tree6abb7770f72a7415021503ad7fc2ff3f64fdc080
parent0846541cd97b0fb30d51796ab9bf31d7684eb15b (diff)
QQuickComboBox: handle touch events
Task-number: QTBUG-58389 Change-Id: I7120d7bce827beb97a9ae3eaf4e99cf6b6e9f209 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp61
-rw-r--r--src/quicktemplates2/qquickcombobox_p.h2
-rw-r--r--tests/auto/controls/data/tst_combobox.qml44
3 files changed, 107 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index 1e24f022..09a5eede 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -257,6 +257,7 @@ public:
bool hasCurrentIndex;
int highlightedIndex;
int currentIndex;
+ int touchId;
QVariant model;
QString textRole;
QString currentText;
@@ -295,6 +296,7 @@ QQuickComboBoxPrivate::QQuickComboBoxPrivate()
hasCurrentIndex(false),
highlightedIndex(-1),
currentIndex(-1),
+ touchId(-1),
delegateModel(nullptr),
delegate(nullptr),
indicator(nullptr),
@@ -646,12 +648,14 @@ void QQuickComboBoxPrivate::handleRelease(const QPointF &)
q->setPressed(false);
togglePopup(false);
}
+ touchId = -1;
}
void QQuickComboBoxPrivate::handleUngrab()
{
Q_Q(QQuickComboBox);
q->setPressed(false);
+ touchId = -1;
}
QQuickComboBox::QQuickComboBox(QQuickItem *parent)
@@ -1531,6 +1535,63 @@ void QQuickComboBox::mouseUngrabEvent()
d->handleUngrab();
}
+void QQuickComboBox::touchEvent(QTouchEvent *event)
+{
+ Q_D(QQuickComboBox);
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ if (d->touchId == -1) {
+ const QTouchEvent::TouchPoint point = event->touchPoints().first();
+ d->touchId = point.id();
+ d->handlePress(point.pos());
+ }
+ break;
+
+ case QEvent::TouchUpdate:
+ for (const QTouchEvent::TouchPoint &point : event->touchPoints()) {
+ if (point.id() != d->touchId)
+ continue;
+
+ switch (point.state()) {
+ case Qt::TouchPointPressed:
+ d->handlePress(point.pos());
+ break;
+ case Qt::TouchPointMoved:
+ d->handleMove(point.pos());
+ break;
+ case Qt::TouchPointReleased:
+ d->handleRelease(point.pos());
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+
+ case QEvent::TouchEnd:
+ for (const QTouchEvent::TouchPoint &point : event->touchPoints()) {
+ if (point.id() == d->touchId)
+ d->handleRelease(point.pos());
+ }
+ break;
+
+ case QEvent::TouchCancel:
+ d->handleUngrab();
+ break;
+
+ default:
+ QQuickControl::touchEvent(event);
+ break;
+ }
+}
+
+void QQuickComboBox::touchUngrabEvent()
+{
+ Q_D(QQuickComboBox);
+ QQuickControl::touchUngrabEvent();
+ d->handleUngrab();
+}
+
#if QT_CONFIG(wheelevent)
void QQuickComboBox::wheelEvent(QWheelEvent *event)
{
diff --git a/src/quicktemplates2/qquickcombobox_p.h b/src/quicktemplates2/qquickcombobox_p.h
index 76dce2d5..652a6be4 100644
--- a/src/quicktemplates2/qquickcombobox_p.h
+++ b/src/quicktemplates2/qquickcombobox_p.h
@@ -187,6 +187,8 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseUngrabEvent() override;
+ void touchEvent(QTouchEvent *event) override;
+ void touchUngrabEvent() override;
#if QT_CONFIG(wheelevent)
void wheelEvent(QWheelEvent *event) override;
#endif
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 05eb2de1..7789f861 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -695,6 +695,50 @@ TestCase {
tryCompare(control.popup, "visible", false)
}
+ function test_touch() {
+ var control = createTemporaryObject(comboBox, testCase, {model: 3})
+ verify(control)
+
+ var touch = touchEvent(control)
+
+ var activatedSpy = signalSpy.createObject(control, {target: control, signalName: "activated"})
+ verify(activatedSpy.valid)
+
+ var highlightedSpy = signalSpy.createObject(control, {target: control, signalName: "highlighted"})
+ verify(highlightedSpy.valid)
+
+ touch.press(0, control).commit()
+ touch.release(0, control).commit()
+ compare(control.popup.visible, true)
+
+ var content = control.popup.contentItem
+ waitForRendering(content)
+
+ // press - move - release outside - not activated - not closed
+ touch.press(0, control).commit()
+ compare(activatedSpy.count, 0)
+ compare(highlightedSpy.count, 0)
+ touch.move(0, control, control.width * 2, control.height / 2).commit()
+ compare(activatedSpy.count, 0)
+ compare(highlightedSpy.count, 0)
+ touch.release(0, control, control.width * 2, control.height / 2).commit()
+ compare(activatedSpy.count, 0)
+ compare(highlightedSpy.count, 0)
+ compare(control.popup.visible, true)
+
+ // press - move - release inside - activated - closed
+ touch.press(0, content).commit()
+ compare(activatedSpy.count, 0)
+ compare(highlightedSpy.count, 0)
+ touch.move(0, content, content.width / 2 + 1, content.height / 2 + 1).commit()
+ compare(activatedSpy.count, 0)
+ compare(highlightedSpy.count, 0)
+ touch.release(0, content).commit()
+ compare(activatedSpy.count, 1)
+ compare(highlightedSpy.count, 1)
+ tryCompare(control.popup, "visible", false)
+ }
+
function test_down() {
var control = createTemporaryObject(comboBox, testCase, {model: 3})
verify(control)