From ea2f6864875cf2055f91c5fbfed4502ab17c3214 Mon Sep 17 00:00:00 2001 From: Vivienne Watermeier Date: Wed, 23 Feb 2022 12:53:04 +0100 Subject: [PATCH] qt: Add touch event support Part-of: --- subprojects/gst-plugins-good/ext/qt/qtitem.cc | 68 +++++++++++++++++++++++++++ subprojects/gst-plugins-good/ext/qt/qtitem.h | 1 + 2 files changed, 69 insertions(+) diff --git a/subprojects/gst-plugins-good/ext/qt/qtitem.cc b/subprojects/gst-plugins-good/ext/qt/qtitem.cc index b29e600..2ffd5d3 100644 --- a/subprojects/gst-plugins-good/ext/qt/qtitem.cc +++ b/subprojects/gst-plugins-good/ext/qt/qtitem.cc @@ -124,6 +124,12 @@ QtGLVideoItem::QtGLVideoItem() setAcceptedMouseButtons(Qt::AllButtons); setAcceptHoverEvents(true); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) + setAcceptTouchEvents(true); +#else + GST_INFO ("Qt version is below 5.10, touchscreen events will not work"); +#endif + GST_DEBUG ("%p init Qt Video Item", this); } @@ -485,6 +491,68 @@ QtGLVideoItem::hoverMoveEvent(QHoverEvent * event) } void +QtGLVideoItem::touchEvent(QTouchEvent * event) +{ + g_mutex_lock (&this->priv->lock); + + /* can't do anything when we don't have input format */ + if (!this->priv->caps) { + g_mutex_unlock (&this->priv->lock); + return; + } + + GstElement *element = GST_ELEMENT_CAST (g_weak_ref_get (&this->priv->sink)); + if (element == NULL) + return; + + if (event->type() == QEvent::TouchCancel) { + gst_navigation_send_event_simple (GST_NAVIGATION (element), + gst_navigation_event_new_touch_cancel ()); + } else { + const QList points = event->touchPoints(); + gboolean sent_event = FALSE; + + for (int i = 0; i < points.count(); i++) { + GstEvent *nav_event; + QPointF pos = mapPointToStreamSize(points[i].pos()); + + switch (points[i].state()) { + case Qt::TouchPointPressed: + nav_event = gst_navigation_event_new_touch_down ((guint) points[i].id(), + pos.x(), pos.y(), (gdouble) points[i].pressure()); + break; + case Qt::TouchPointMoved: + nav_event = gst_navigation_event_new_touch_motion ((guint) points[i].id(), + pos.x(), pos.y(), (gdouble) points[i].pressure()); + break; + case Qt::TouchPointReleased: + nav_event = gst_navigation_event_new_touch_up ((guint) points[i].id(), + pos.x(), pos.y()); + break; + /* Don't send an event if the point did not change */ + default: + nav_event = NULL; + break; + } + + if (nav_event) { + gst_navigation_send_event_simple (GST_NAVIGATION (element), nav_event); + sent_event = TRUE; + } + } + + /* Group simultaneos touch events with a frame event */ + if (sent_event) { + gst_navigation_send_event_simple (GST_NAVIGATION (element), + gst_navigation_event_new_touch_frame ()); + } + } + + g_object_unref (element); + g_mutex_unlock (&this->priv->lock); +} + +void QtGLVideoItem::sendMouseEvent(QMouseEvent * event, gboolean is_press) { quint32 button = 0; diff --git a/subprojects/gst-plugins-good/ext/qt/qtitem.h b/subprojects/gst-plugins-good/ext/qt/qtitem.h index 9e16503..f65f631 100644 --- a/subprojects/gst-plugins-good/ext/qt/qtitem.h +++ b/subprojects/gst-plugins-good/ext/qt/qtitem.h @@ -103,6 +103,7 @@ protected: void hoverMoveEvent (QHoverEvent *) override; void mousePressEvent(QMouseEvent*) override; void mouseReleaseEvent(QMouseEvent*) override; + void touchEvent(QTouchEvent*) override; private: -- 2.7.4