Commit 38461aa2 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

We can use code from kwidgetaddons now

parent f43ebfec
Pipeline #70027 passed with stage
in 40 minutes
......@@ -27,7 +27,6 @@ target_sources(KF5MessageList PRIVATE
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
......@@ -16,7 +16,6 @@
#include "core/model.h"
#include "core/storagemodelbase.h"
#include "core/theme.h"
#include "core/twofingertap.h"
#include "core/widgetbase.h"
#include "messagelistsettings.h"
#include "messagelistutil.h"
......@@ -27,6 +26,7 @@
#include <kmime/kmime_dateformatter.h> // kdepimlibs
#include <Item>
#include <KTwoFingerTap>
#include <QApplication>
#include <QGestureEvent>
#include <QHeaderView>
......@@ -60,7 +60,7 @@ public:
void gestureEvent(QGestureEvent *e);
void tapTriggered(QTapGesture *tap);
void tapAndHoldTriggered(QTapAndHoldGesture *tap);
void twoFingerTapTriggered(TwoFingerTap *tap);
void twoFingerTapTriggered(KTwoFingerTap *tap);
QColor mTextColor;
View *const q;
......@@ -113,7 +113,7 @@ View::View(Widget *pParent)
d->mScroller->grabGesture(viewport());
setAttribute(Qt::WA_AcceptTouchEvents);
d->mTwoFingerTap = QGestureRecognizer::registerRecognizer(new TwoFingerTapRecognizer());
d->mTwoFingerTap = QGestureRecognizer::registerRecognizer(new KTwoFingerTapRecognizer());
viewport()->grabGesture(d->mTwoFingerTap);
viewport()->grabGesture(Qt::TapGesture);
viewport()->grabGesture(Qt::TapAndHoldGesture);
......@@ -2730,7 +2730,7 @@ void View::Private::gestureEvent(QGestureEvent *e)
tapAndHoldTriggered(static_cast<QTapAndHoldGesture *>(gesture));
}
if (QGesture *gesture = e->gesture(mTwoFingerTap)) {
twoFingerTapTriggered(static_cast<TwoFingerTap *>(gesture));
twoFingerTapTriggered(static_cast<KTwoFingerTap *>(gesture));
}
}
......@@ -2815,7 +2815,7 @@ void View::Private::tapAndHoldTriggered(QTapAndHoldGesture *tap)
}
}
void View::Private::twoFingerTapTriggered(TwoFingerTap *tap)
void View::Private::twoFingerTapTriggered(KTwoFingerTap *tap)
{
if (tap->state() == Qt::GestureFinished) {
......
Supports Markdown
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