Commit f504e4a5 authored by Steffen Hartleib's avatar Steffen Hartleib Committed by Laurent Montel
Browse files

Improve touch support for messagelist

parent 26fa1f02
Pipeline #62967 passed with stage
in 38 minutes and 42 seconds
......@@ -25,6 +25,7 @@ set(libmessagelist_SRCS
core/theme.cpp
core/themedelegate.cpp
core/threadingcache.cpp
core/twofingertap.cpp
core/storagemodelbase.cpp
core/sortorder.cpp
core/view.cpp
......
/******************************************************************************
*
* SPDX-FileCopyrightText: 2021 Steffen Hartleib <steffenhartleib@t-online.de>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
*******************************************************************************/
// Self
#include "twofingertap.h"
// Qt
#include <QApplication>
#include <QGraphicsWidget>
#include <QTouchEvent>
using namespace MessageList::Core;
TwoFingerTapRecognizer::TwoFingerTapRecognizer()
: QGestureRecognizer()
{
}
TwoFingerTapRecognizer::~TwoFingerTapRecognizer()
{
}
QGesture* TwoFingerTapRecognizer::create(QObject *)
{
return static_cast<QGesture*>(new TwoFingerTap());
}
QGestureRecognizer::Result TwoFingerTapRecognizer::recognize(QGesture *gesture, QObject *watched, QEvent *event)
{
if (qobject_cast<QGraphicsWidget *>(watched)) {
return Ignore;
}
TwoFingerTap *twoFingerTap = static_cast<TwoFingerTap *>(gesture);
const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event);
switch (event->type()) {
case QEvent::TouchBegin: {
twoFingerTap->setHotSpot(touchEvent->touchPoints().first().startScreenPos());
twoFingerTap->setPos(touchEvent->touchPoints().first().startPos());
twoFingerTap->setScreenPos(touchEvent->touchPoints().first().startScreenPos());
twoFingerTap->setScenePos(touchEvent->touchPoints().first().startScenePos());
mGestureTriggered = false;
return MayBeGesture;
}
case QEvent::TouchUpdate: {
const int touchPointSize = touchEvent->touchPoints().size();
if (touchPointSize > 2) {
mGestureTriggered = false;
return CancelGesture;
}
if (touchPointSize == 2) {
if ((touchEvent->touchPoints().first().startPos() - touchEvent->touchPoints().first().pos()).manhattanLength() >= QApplication::startDragDistance()) {
mGestureTriggered = false;
return CancelGesture;
}
if ((touchEvent->touchPoints().at(1).startPos() - touchEvent->touchPoints().at(1).pos()).manhattanLength() >= QApplication::startDragDistance()) {
mGestureTriggered = false;
return CancelGesture;
}
if (touchEvent->touchPointStates() & Qt::TouchPointPressed) {
mGestureTriggered = true;
}
if (touchEvent->touchPointStates() & Qt::TouchPointReleased && mGestureTriggered) {
mGestureTriggered = false;
return FinishGesture;
}
}
break;
}
default:
return Ignore;
}
return Ignore;
}
TwoFingerTap::TwoFingerTap(QObject *parent)
: QGesture(parent)
{
}
TwoFingerTap::~TwoFingerTap()
{
}
QPointF TwoFingerTap::pos() const
{
return mPos;
}
void TwoFingerTap::setPos(QPointF _pos)
{
mPos = _pos;
}
QPointF TwoFingerTap::screenPos() const
{
return mScreenPos;
}
void TwoFingerTap::setScreenPos(QPointF _screenPos)
{
mScreenPos = _screenPos;
}
QPointF TwoFingerTap::scenePos() const
{
return mScenePos;
}
void TwoFingerTap::setScenePos(QPointF _scenePos)
{
mScenePos = _scenePos;
}
/******************************************************************************
*
* SPDX-FileCopyrightText: 2021 Steffen Hartleib <steffenhartleib@t-online.de>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
*******************************************************************************/
#pragma once
#include <QGesture>
#include <QGestureRecognizer>
namespace MessageList
{
namespace Core
{
class TwoFingerTap : public QGesture
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
Q_PROPERTY(QPointF screenPos READ screenPos WRITE setScreenPos)
Q_PROPERTY(QPointF scenePos READ scenePos WRITE setScenePos)
public:
explicit TwoFingerTap(QObject *parent = nullptr);
~TwoFingerTap() override;
Q_REQUIRED_RESULT QPointF pos() const;
void setPos(QPointF pos);
Q_REQUIRED_RESULT QPointF screenPos() const;
void setScreenPos(QPointF screenPos);
Q_REQUIRED_RESULT QPointF scenePos() const;
void setScenePos(QPointF scenePos);
private:
QPointF mPos = QPointF(-1, -1);
QPointF mScreenPos = QPointF(-1, -1);
QPointF mScenePos = QPointF(-1, -1);
}; // class TwoFingerTap
class TwoFingerTapRecognizer : public QGestureRecognizer
{
public:
explicit TwoFingerTapRecognizer();
~TwoFingerTapRecognizer() override;
QGesture* create(QObject *) override;
Result recognize(QGesture *, QObject *, QEvent *) override;
private:
Q_DISABLE_COPY(TwoFingerTapRecognizer)
bool mGestureTriggered = false;
}; // class TwoFingerTapRecognizer
} // namespace Core
} // namespace MessageList
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment