2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include "gestures.h"
|
|
|
|
|
|
|
|
#include <QTouchEvent>
|
|
|
|
|
|
|
|
Qt::GestureType ThreeFingerSlideGesture::Type = Qt::CustomGesture;
|
|
|
|
|
|
|
|
QGesture *ThreeFingerSlideGestureRecognizer::create(QObject *)
|
|
|
|
{
|
|
|
|
return new ThreeFingerSlideGesture;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
|
|
|
|
{
|
|
|
|
ThreeFingerSlideGesture *d = static_cast<ThreeFingerSlideGesture *>(state);
|
|
|
|
QGestureRecognizer::Result result;
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::TouchBegin:
|
|
|
|
result = QGestureRecognizer::MayBeGesture;
|
2019-03-06 11:50:26 +00:00
|
|
|
break;
|
2011-04-27 10:05:43 +00:00
|
|
|
case QEvent::TouchEnd:
|
|
|
|
if (d->gestureFired)
|
|
|
|
result = QGestureRecognizer::FinishGesture;
|
|
|
|
else
|
|
|
|
result = QGestureRecognizer::CancelGesture;
|
2019-03-06 11:50:26 +00:00
|
|
|
break;
|
2011-04-27 10:05:43 +00:00
|
|
|
case QEvent::TouchUpdate:
|
|
|
|
if (d->state() != Qt::NoGesture) {
|
|
|
|
QTouchEvent *ev = static_cast<QTouchEvent*>(event);
|
2020-07-07 06:19:12 +00:00
|
|
|
if (ev->points().size() == 3) {
|
2011-04-27 10:05:43 +00:00
|
|
|
d->gestureFired = true;
|
|
|
|
result = QGestureRecognizer::TriggerGesture;
|
|
|
|
} else {
|
|
|
|
result = QGestureRecognizer::MayBeGesture;
|
2020-07-07 06:19:12 +00:00
|
|
|
for (const QEventPoint &pt : ev->points()) {
|
|
|
|
const int distance = (pt.globalPosition().toPoint() - pt.globalPressPosition().toPoint()).manhattanLength();
|
|
|
|
if (distance > 20)
|
2011-04-27 10:05:43 +00:00
|
|
|
result = QGestureRecognizer::CancelGesture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = QGestureRecognizer::CancelGesture;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
case QEvent::MouseMove:
|
|
|
|
if (d->state() != Qt::NoGesture)
|
|
|
|
result = QGestureRecognizer::Ignore;
|
|
|
|
else
|
|
|
|
result = QGestureRecognizer::CancelGesture;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = QGestureRecognizer::Ignore;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreeFingerSlideGestureRecognizer::reset(QGesture *state)
|
|
|
|
{
|
|
|
|
static_cast<ThreeFingerSlideGesture *>(state)->gestureFired = false;
|
|
|
|
QGestureRecognizer::reset(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QGesture *RotateGestureRecognizer::create(QObject *)
|
|
|
|
{
|
|
|
|
return new QGesture;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGestureRecognizer::Result RotateGestureRecognizer::recognize(QGesture *, QObject *, QEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::TouchBegin:
|
|
|
|
case QEvent::TouchEnd:
|
|
|
|
case QEvent::TouchUpdate:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QGestureRecognizer::Ignore;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RotateGestureRecognizer::reset(QGesture *state)
|
|
|
|
{
|
|
|
|
QGestureRecognizer::reset(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_gestures.cpp"
|