aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorGrigorii Zimin <gzimin@luxoft.com>2019-11-15 13:45:02 +0300
committerEgor Nemtsev <enemtsev@luxoft.com>2019-11-25 14:45:17 +0000
commit4780a300c43111edba1fc0b74677900d6fff7c8e (patch)
tree76e75cd2d725c7dd9921a3b50893c4ededaae852 /plugins
parent4bf603214cd4fd7f0329e27db2386f6a199bb058 (diff)
[utils] Add mouse/touch points trace
Add new plugin for events listeners. Now it consists of only one listener that allows to enable mouse/touch events tracking for debugging purposes. Fixes: AUTOSUITE-1001 Change-Id: I7b278e922df5eee46721a80d3499a21a3b3dde17 Reviewed-by: Kavindra Palaraja <kpalaraja@luxoft.com> Reviewed-by: Egor Nemtsev <enemtsev@luxoft.com>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/eventslisteners/eventsListenersPlugin.cpp51
-rw-r--r--plugins/eventslisteners/eventslisteners.pro13
-rw-r--r--plugins/eventslisteners/qmldir3
-rw-r--r--plugins/eventslisteners/touchPointsTracer.h115
-rw-r--r--plugins/plugins.pro3
5 files changed, 184 insertions, 1 deletions
diff --git a/plugins/eventslisteners/eventsListenersPlugin.cpp b/plugins/eventslisteners/eventsListenersPlugin.cpp
new file mode 100644
index 00000000..f7fc52fb
--- /dev/null
+++ b/plugins/eventslisteners/eventsListenersPlugin.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Luxoft Sweden AB
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Neptune IVI UI.
+**
+** $QT_BEGIN_LICENSE:GPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: GPL-3.0
+**
+****************************************************************************/
+
+#include <QtQml/qqmlextensionplugin.h>
+#include <QtQml>
+
+#include "touchPointsTracer.h"
+
+class EventsListenersPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
+public:
+ void registerTypes(const char *uri) override
+ {
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("shared.com.luxoft.eventslisteners"));
+
+ qmlRegisterUncreatableType<TouchPointsTracer>(uri, 1, 0, "TouchPointsTracer"
+ , "TouchPointsTracer is an attached property");
+ }
+};
+
+#include "eventsListenersPlugin.moc"
diff --git a/plugins/eventslisteners/eventslisteners.pro b/plugins/eventslisteners/eventslisteners.pro
new file mode 100644
index 00000000..c3a53ac5
--- /dev/null
+++ b/plugins/eventslisteners/eventslisteners.pro
@@ -0,0 +1,13 @@
+TEMPLATE = lib
+TARGET = eventslistenersplugin
+QT += qml quick gui
+CONFIG += qt plugin c++11
+
+uri = com.luxoft.eventslisteners
+load(qmlplugin)
+
+SOURCES += \
+ eventsListenersPlugin.cpp
+
+HEADERS += \
+ touchPointsTracer.h
diff --git a/plugins/eventslisteners/qmldir b/plugins/eventslisteners/qmldir
new file mode 100644
index 00000000..57c26504
--- /dev/null
+++ b/plugins/eventslisteners/qmldir
@@ -0,0 +1,3 @@
+module shared.com.luxoft.eventslisteners
+plugin eventslistenersplugin
+
diff --git a/plugins/eventslisteners/touchPointsTracer.h b/plugins/eventslisteners/touchPointsTracer.h
new file mode 100644
index 00000000..a92323ac
--- /dev/null
+++ b/plugins/eventslisteners/touchPointsTracer.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Luxoft Sweden AB
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Neptune 3 IVI UI.
+**
+** $QT_BEGIN_LICENSE:GPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: GPL-3.0
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QtGlobal>
+#include <QObject>
+#include <QTouchEvent>
+#include <QMouseEvent>
+#include <QQmlEngine>
+
+#include <QDebug>
+class TouchPointsTracer : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QObject *target READ getTarget WRITE setTarget)
+public:
+ explicit TouchPointsTracer(QObject *parent = nullptr) :
+ QObject(parent)
+ , m_filterTouches(!qgetenv("SHOW_TOUCH_POINTS").compare(QByteArrayLiteral("yes")))
+ {}
+
+ static TouchPointsTracer *qmlAttachedProperties(QObject *object) {
+ return new TouchPointsTracer(object);
+ }
+
+ QObject *getTarget() const {
+ return m_currentTarget;
+ }
+
+ void setTarget(QObject *target) {
+ if (m_currentTarget) {
+ removeEventFilter(m_currentTarget);
+ }
+
+ m_currentTarget = target;
+ listenTo(target);
+ }
+
+ bool eventFilter(QObject *object, QEvent *event) override {
+ if (m_filterTouches) {
+ if (event->type() == QEvent::TouchBegin
+ || event->type() == QEvent::TouchEnd
+ || event->type() == QEvent::TouchUpdate) {
+ auto tEvent = static_cast<QTouchEvent *>(event);
+ const QList<QTouchEvent::TouchPoint> touchPoints = tEvent->touchPoints();
+ QVector<int> points;
+ points.reserve(touchPoints.size() * 2); // 2 int = point
+ for (auto && tp : touchPoints) {
+ QPoint point = tp.pos().toPoint();
+ points << point.x() << point.y();
+ }
+
+ if (!points.isEmpty())
+ emit touchPointsChanged(object, points);
+ } else if (event->type() == QEvent::MouseButtonPress
+ || event->type() == QEvent::MouseButtonRelease
+ || event->type() == QEvent::MouseMove)
+ {
+ auto mouseEvent = static_cast<QMouseEvent *>(event);
+ if (mouseEvent->buttons()) {
+ emit touchPointsChanged(object, {mouseEvent->pos().x(), mouseEvent->pos().y()});
+ }
+ }
+ }
+
+ return false;
+ }
+
+signals:
+ // QVector<int> is transparently supported by qml, we are trying to reduce data conversions
+ void touchPointsChanged(QObject *object, QVector<int> points);
+
+private:
+ QObject* m_currentTarget{nullptr};
+ bool m_filterTouches{false};
+
+ void listenTo(QObject *object) {
+ if (!object || !m_filterTouches)
+ return;
+
+ object->installEventFilter(this);
+ }
+};
+
+QML_DECLARE_TYPEINFO(TouchPointsTracer, QML_HAS_ATTACHED_PROPERTIES)
diff --git a/plugins/plugins.pro b/plugins/plugins.pro
index c8ebc14a..7a8a126b 100644
--- a/plugins/plugins.pro
+++ b/plugins/plugins.pro
@@ -7,7 +7,8 @@ SUBDIRS = \
widgetgrid \
style \
systeminfo \
- com.pelagicore.map
+ eventslisteners \
+ com.pelagicore.map \
!isEmpty(SQUISH_PREFIX) {
SUBDIRS += squishhook