aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickpopup.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-04-20 16:28:59 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-04-21 07:52:32 +0000
commit7f06ac49129d9048e98afb14b0ff4ebdcb821c35 (patch)
tree3a6edd982ae2cb9e644665bdaae246f8f555af7f /src/quicktemplates2/qquickpopup.cpp
parentc8e9b5f25fb12c3b7983658d738165181b4d6672 (diff)
Prepare QQuickPopup for touch event handling
Add acceptTouch() and handlePress/Move/Release/Ungrab() to QQuickPopupPrivate, similarly to the recent changes to QQuickControl. Task-number: QTBUG-58389 Change-Id: I45bc0c51f7db79d0d3291f4beee6dab45b158e8a Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickpopup.cpp')
-rw-r--r--src/quicktemplates2/qquickpopup.cpp102
1 files changed, 95 insertions, 7 deletions
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp
index 915cf8f8..cc62db10 100644
--- a/src/quicktemplates2/qquickpopup.cpp
+++ b/src/quicktemplates2/qquickpopup.cpp
@@ -225,6 +225,7 @@ QQuickPopupPrivate::QQuickPopupPrivate()
allowHorizontalResize(true),
hadActiveFocusBeforeExitTransition(false),
interactive(true),
+ touchId(-1),
x(0),
y(0),
effectiveX(0),
@@ -290,6 +291,44 @@ bool QQuickPopupPrivate::tryClose(QQuickItem *item, QMouseEvent *event)
return false;
}
+bool QQuickPopupPrivate::acceptTouch(const QTouchEvent::TouchPoint &point)
+{
+ if (point.id() == touchId)
+ return true;
+
+ if (touchId == -1 && point.state() == Qt::TouchPointPressed) {
+ touchId = point.id();
+ return true;
+ }
+
+ return false;
+}
+
+void QQuickPopupPrivate::handlePress(const QPointF &)
+{
+}
+
+void QQuickPopupPrivate::handleMove(const QPointF &)
+{
+}
+
+void QQuickPopupPrivate::handleRelease(const QPointF &)
+{
+ touchId = -1;
+}
+
+void QQuickPopupPrivate::handleUngrab()
+{
+ Q_Q(QQuickPopup);
+ QQuickOverlay *overlay = QQuickOverlay::overlay(window);
+ if (overlay) {
+ QQuickOverlayPrivate *p = QQuickOverlayPrivate::get(overlay);
+ if (p->mouseGrabberPopup == q)
+ p->mouseGrabberPopup = nullptr;
+ }
+ touchId = -1;
+}
+
bool QQuickPopupPrivate::prepareEnterTransition()
{
Q_Q(QQuickPopup);
@@ -1800,16 +1839,22 @@ void QQuickPopup::keyReleaseEvent(QKeyEvent *event)
void QQuickPopup::mousePressEvent(QMouseEvent *event)
{
+ Q_D(QQuickPopup);
+ d->handlePress(event->localPos());
event->accept();
}
void QQuickPopup::mouseMoveEvent(QMouseEvent *event)
{
+ Q_D(QQuickPopup);
+ d->handleMove(event->localPos());
event->accept();
}
void QQuickPopup::mouseReleaseEvent(QMouseEvent *event)
{
+ Q_D(QQuickPopup);
+ d->handleRelease(event->localPos());
event->accept();
}
@@ -1820,12 +1865,8 @@ void QQuickPopup::mouseDoubleClickEvent(QMouseEvent *event)
void QQuickPopup::mouseUngrabEvent()
{
- QQuickOverlay *overlay = QQuickOverlay::overlay(window());
- if (overlay) {
- QQuickOverlayPrivate *p = QQuickOverlayPrivate::get(overlay);
- if (p->mouseGrabberPopup == this)
- p->mouseGrabberPopup = nullptr;
- }
+ Q_D(QQuickPopup);
+ d->handleUngrab();
}
bool QQuickPopup::overlayEvent(QQuickItem *item, QEvent *event)
@@ -1854,12 +1895,59 @@ bool QQuickPopup::overlayEvent(QQuickItem *item, QEvent *event)
void QQuickPopup::touchEvent(QTouchEvent *event)
{
- // TODO: QQuickPopup and QQuickDrawer still rely on synthesized mouse events
+ Q_D(QQuickPopup);
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ for (const QTouchEvent::TouchPoint &point : event->touchPoints()) {
+ if (d->acceptTouch(point))
+ d->handlePress(point.pos());
+ }
+ break;
+
+ case QEvent::TouchUpdate:
+ for (const QTouchEvent::TouchPoint &point : event->touchPoints()) {
+ if (!d->acceptTouch(point))
+ 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 (d->acceptTouch(point))
+ d->handleRelease(point.pos());
+ }
+ break;
+
+ case QEvent::TouchCancel:
+ d->handleUngrab();
+ break;
+
+ default:
+ break;
+ }
+
+ // TODO: QQuickPopup still relies on synthesized mouse events
event->ignore();
}
void QQuickPopup::touchUngrabEvent()
{
+ Q_D(QQuickPopup);
+ d->handleUngrab();
}
#if QT_CONFIG(wheelevent)