┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/private/ktwofingerswipe.cpp
diff options
context:
space:
mode:
authorSteffen Hartleib <[email protected]>2020-09-13 18:53:32 +0000
committerElvis Angelaccio <[email protected]>2020-09-13 18:53:32 +0000
commitd7b33b76a18b14e9f286e4d8326b00910b9ea02a (patch)
treeade5042c74a0d172172a9327244858825076c333 /src/kitemviews/private/ktwofingerswipe.cpp
parentd899c2b401869d29558f62fba3479bf744b0577c (diff)
Improve Touch support
With this patch dolphin now supports the following touch gestures: * Tap gesture to interact/open with directories, files and so on * TapAndHold and release gesture for access to the context menu (main window, panel folder, places and information) * TapAndHold and moving gesture for drag and drop action (main windows, panel folder and places) * pinch gesture for zoom in main window * kinetic scrolling (QScroller) for main window, panel folder, panel places, panel information, setting preview and service * two fingers swipe gesture to left, right and up as shortcut to navigate back, forward and up * two finger tap gesture to toggle item selection, similar to Ctrl and left mouse click FEATURE: 385066 FIXED-IN: 20.11.80 You are currently rebasing branch 'touch' on '85241a924'.
Diffstat (limited to 'src/kitemviews/private/ktwofingerswipe.cpp')
-rw-r--r--src/kitemviews/private/ktwofingerswipe.cpp139
1 files changed, 139 insertions, 0 deletions
diff --git a/src/kitemviews/private/ktwofingerswipe.cpp b/src/kitemviews/private/ktwofingerswipe.cpp
new file mode 100644
index 000000000..6d0e18e65
--- /dev/null
+++ b/src/kitemviews/private/ktwofingerswipe.cpp
@@ -0,0 +1,139 @@
+/*
+ * SPDX-FileCopyrightText: 2020 Steffen Hartleib <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+// Self
+#include "ktwofingerswipe.h"
+
+// Qt
+#include <QTouchEvent>
+#include <QLineF>
+
+KTwoFingerSwipeRecognizer::KTwoFingerSwipeRecognizer() :
+ QGestureRecognizer(),
+ m_touchBeginnTimestamp(0),
+ m_gestureAlreadyTriggered(false)
+{
+}
+
+KTwoFingerSwipeRecognizer::~KTwoFingerSwipeRecognizer()
+{
+}
+
+QGesture* KTwoFingerSwipeRecognizer::create(QObject*)
+{
+ return static_cast<QGesture*>(new KTwoFingerSwipe());
+}
+
+QGestureRecognizer::Result KTwoFingerSwipeRecognizer::recognize(QGesture* gesture, QObject* watched, QEvent* event)
+{
+ Q_UNUSED(watched)
+
+ KTwoFingerSwipe* const kTwoFingerSwipe = static_cast<KTwoFingerSwipe*>(gesture);
+ const QTouchEvent* touchEvent = static_cast<const QTouchEvent*>(event);
+
+ const int maxTimeFrameForSwipe = 90;
+ const int minDistanceForSwipe = 30;
+
+ switch (event->type()) {
+ case QEvent::TouchBegin: {
+ m_touchBeginnTimestamp = touchEvent->timestamp();
+ m_gestureAlreadyTriggered = false;
+ kTwoFingerSwipe->setHotSpot(touchEvent->touchPoints().first().startScreenPos());
+ kTwoFingerSwipe->setPos(touchEvent->touchPoints().first().startPos());
+ kTwoFingerSwipe->setScreenPos(touchEvent->touchPoints().first().startScreenPos());
+ kTwoFingerSwipe->setScenePos(touchEvent->touchPoints().first().startScenePos());
+ return MayBeGesture;
+ }
+
+ case QEvent::TouchUpdate: {
+ const qint64 now = touchEvent->timestamp();
+ const qint64 elapsedTime = now - m_touchBeginnTimestamp;
+ const QPointF distance = touchEvent->touchPoints().first().startPos() - touchEvent->touchPoints().first().pos();
+ kTwoFingerSwipe->setHotSpot(touchEvent->touchPoints().first().startScreenPos());
+ kTwoFingerSwipe->setPos(touchEvent->touchPoints().first().startPos());
+ kTwoFingerSwipe->setScreenPos(touchEvent->touchPoints().first().startScreenPos());
+ kTwoFingerSwipe->setScenePos(touchEvent->touchPoints().first().startScenePos());
+ const QLineF ql = QLineF(touchEvent->touchPoints().first().startPos(), touchEvent->touchPoints().first().pos());
+ kTwoFingerSwipe->setSwipeAngle(ql.angle());
+
+ if (touchEvent->touchPoints().size() > 2) {
+ return CancelGesture;
+ }
+
+ if (touchEvent->touchPoints().size() == 2) {
+ if ((elapsedTime) > maxTimeFrameForSwipe) {
+ return CancelGesture;
+ }
+
+ if (distance.manhattanLength() >= minDistanceForSwipe &&
+ (elapsedTime) <= maxTimeFrameForSwipe && !m_gestureAlreadyTriggered) {
+ m_gestureAlreadyTriggered = true;
+ return FinishGesture;
+ } else if ((elapsedTime) <= maxTimeFrameForSwipe && !m_gestureAlreadyTriggered) {
+ return TriggerGesture;
+ }
+ }
+ break;
+ }
+
+ default:
+ return Ignore;
+ }
+ return Ignore;
+}
+
+KTwoFingerSwipe::KTwoFingerSwipe(QObject* parent) :
+ QGesture(parent),
+ m_pos(QPointF(-1, -1)),
+ m_screenPos(QPointF(-1, -1)),
+ m_scenePos(QPointF(-1, -1)),
+ m_swipeAngle(0.0)
+{
+}
+
+KTwoFingerSwipe::~KTwoFingerSwipe()
+{
+}
+
+QPointF KTwoFingerSwipe::pos() const
+{
+ return m_pos;
+}
+
+void KTwoFingerSwipe::setPos(QPointF _pos)
+{
+ m_pos = _pos;
+}
+
+QPointF KTwoFingerSwipe::screenPos() const
+{
+ return m_screenPos;
+}
+
+void KTwoFingerSwipe::setScreenPos(QPointF _screenPos)
+{
+ m_screenPos = _screenPos;
+}
+
+QPointF KTwoFingerSwipe::scenePos() const
+{
+ return m_scenePos;
+}
+
+void KTwoFingerSwipe::setScenePos(QPointF _scenePos)
+{
+ m_scenePos = _scenePos;
+}
+
+qreal KTwoFingerSwipe::swipeAngle() const
+{
+ return m_swipeAngle;
+}
+ void KTwoFingerSwipe::setSwipeAngle(qreal _swipeAngle)
+{
+ m_swipeAngle = _swipeAngle;
+}
+