| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKPOINTERMULTIHANDLER_H |
| 5 | #define QQUICKPOINTERMULTIHANDLER_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtGui/qevent.h> |
| 19 | #include <QtQuick/qquickitem.h> |
| 20 | |
| 21 | #include "qquickhandlerpoint_p.h" |
| 22 | #include "qquickpointerdevicehandler_p.h" |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QQuickMultiPointHandlerPrivate; |
| 27 | |
| 28 | class Q_QUICK_EXPORT QQuickMultiPointHandler : public QQuickPointerDeviceHandler |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | Q_PROPERTY(int minimumPointCount READ minimumPointCount WRITE setMinimumPointCount NOTIFY minimumPointCountChanged) |
| 32 | Q_PROPERTY(int maximumPointCount READ maximumPointCount WRITE setMaximumPointCount NOTIFY maximumPointCountChanged) |
| 33 | Q_PROPERTY(QQuickHandlerPoint centroid READ centroid NOTIFY centroidChanged) |
| 34 | |
| 35 | public: |
| 36 | explicit QQuickMultiPointHandler(QQuickItem *parent = nullptr, int minimumPointCount = 2, int maximumPointCount = -1); |
| 37 | |
| 38 | int minimumPointCount() const; |
| 39 | void setMinimumPointCount(int c); |
| 40 | |
| 41 | int maximumPointCount() const; |
| 42 | void setMaximumPointCount(int maximumPointCount); |
| 43 | |
| 44 | const QQuickHandlerPoint ¢roid() const; |
| 45 | |
| 46 | Q_SIGNALS: |
| 47 | void minimumPointCountChanged(); |
| 48 | void maximumPointCountChanged(); |
| 49 | void centroidChanged(); |
| 50 | |
| 51 | protected: |
| 52 | struct PointData { |
| 53 | PointData() : id(0), angle(0) {} |
| 54 | PointData(quint64 id, qreal angle) : id(id), angle(angle) {} |
| 55 | quint64 id; |
| 56 | qreal angle; |
| 57 | }; |
| 58 | |
| 59 | bool wantsPointerEvent(QPointerEvent *event) override; |
| 60 | void handlePointerEventImpl(QPointerEvent *event) override; |
| 61 | void onActiveChanged() override; |
| 62 | void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition, QPointerEvent *event, QEventPoint &point) override; |
| 63 | QList<QQuickHandlerPoint> ¤tPoints(); |
| 64 | QQuickHandlerPoint &mutableCentroid(); |
| 65 | bool hasCurrentPoints(QPointerEvent *event); |
| 66 | QVector<QEventPoint> eligiblePoints(QPointerEvent *event); |
| 67 | qreal averageTouchPointDistance(const QPointF &ref); |
| 68 | qreal averageStartingDistance(const QPointF &ref); |
| 69 | qreal averageTouchPointAngle(const QPointF &ref); |
| 70 | qreal averageStartingAngle(const QPointF &ref); |
| 71 | QVector<PointData> angles(const QPointF &ref) const; |
| 72 | static qreal averageAngleDelta(const QVector<PointData> &old, const QVector<PointData> &newAngles); |
| 73 | void acceptPoints(const QVector<QEventPoint> &points); |
| 74 | bool grabPoints(QPointerEvent *event, const QVector<QEventPoint> &points); |
| 75 | void moveTarget(QPointF pos); |
| 76 | |
| 77 | Q_DECLARE_PRIVATE(QQuickMultiPointHandler) |
| 78 | }; |
| 79 | |
| 80 | QT_END_NAMESPACE |
| 81 | |
| 82 | #endif // QQUICKPOINTERMULTIHANDLER_H |
| 83 | |