From 634182d489c7d30f4150ccbd1842e4c757566970 Mon Sep 17 00:00:00 2001 From: Eric Edlund Date: Tue, 26 Jul 2022 11:35:07 -0400 Subject: [PATCH] Move gesture direction to base class --- autotests/test_gestures.cpp | 44 ++++++++++--------------------------- src/gestures.cpp | 30 +++++++++---------------- src/gestures.h | 12 ++++------ src/globalshortcuts.cpp | 3 +-- 4 files changed, 27 insertions(+), 62 deletions(-) diff --git a/autotests/test_gestures.cpp b/autotests/test_gestures.cpp index 422613c8c5..dc02818fd3 100644 --- a/autotests/test_gestures.cpp +++ b/autotests/test_gestures.cpp @@ -19,10 +19,8 @@ class GestureTest : public QObject { Q_OBJECT private Q_SLOTS: - void testSwipeDirection_data(); - void testSwipeDirection(); - void testPinchDirection_data(); - void testPinchDirection(); + void testDirection_data(); + void testDirection(); // swipe only void testMinimumX_data(); @@ -54,46 +52,28 @@ private Q_SLOTS: void testSwipeGeometryStart(); }; -void GestureTest::testSwipeDirection_data() +void GestureTest::testDirection_data() { - QTest::addColumn("swipe_direction"); + QTest::addColumn("direction"); QTest::newRow("Up") << GestureDirection::Up; QTest::newRow("Left") << GestureDirection::Left; QTest::newRow("Right") << GestureDirection::Right; QTest::newRow("Down") << GestureDirection::Down; -} - -void GestureTest::testSwipeDirection() -{ - SwipeGesture gesture; - QCOMPARE(gesture.direction(), GestureDirection::Down); - QFETCH(GestureDirection, swipe_direction); - gesture.setDirection(swipe_direction); - QCOMPARE(gesture.direction(), swipe_direction); - // back to down - gesture.setDirection(GestureDirection::Down); - QCOMPARE(gesture.direction(), GestureDirection::Down); -} - -void GestureTest::testPinchDirection_data() -{ - QTest::addColumn("pinch_direction"); - QTest::newRow("Contracting") << GestureDirection::Contracting; QTest::newRow("Expanding") << GestureDirection::Expanding; } -void GestureTest::testPinchDirection() +void GestureTest::testDirection() { - PinchGesture gesture; - QCOMPARE(gesture.direction(), GestureDirection::Expanding); - QFETCH(GestureDirection, pinch_direction); - gesture.setDirection(pinch_direction); - QCOMPARE(gesture.direction(), pinch_direction); + SwipeGesture gesture; + QCOMPARE(gesture.direction(), 0); + QFETCH(GestureDirection, direction); + gesture.setDirection(direction); + QCOMPARE(gesture.direction(), direction); // back to down - gesture.setDirection(GestureDirection::Expanding); - QCOMPARE(gesture.direction(), GestureDirection::Expanding); + gesture.setDirection(GestureDirection::Down); + QCOMPARE(gesture.direction(), GestureDirection::Down); } void GestureTest::testMinimumX_data() diff --git a/src/gestures.cpp b/src/gestures.cpp index 4f382ff95d..8af734f036 100644 --- a/src/gestures.cpp +++ b/src/gestures.cpp @@ -367,16 +367,6 @@ void GestureRecognizer::endPinchGesture() // because fingers up m_currentSwipeAxis = Axis::None; } -GestureDirections SwipeGesture::direction() const -{ - return m_direction; -} - -void SwipeGesture::setDirection(GestureDirections direction) -{ - m_direction = direction; -} - void SwipeGesture::setMinimumX(int x) { m_minimumX = x; @@ -457,16 +447,6 @@ bool SwipeGesture::isMinimumDeltaRelevant() const return m_minimumDeltaRelevant; } -GestureDirections PinchGesture::direction() const -{ - return m_direction; -} - -void PinchGesture::setDirection(GestureDirections direction) -{ - m_direction = direction; -} - qreal PinchGesture::minimumScaleDelta() const { return m_minimumScaleDelta; @@ -510,4 +490,14 @@ QSet Gesture::acceptableFingerCounts() const { return m_validFingerCounts; } + +GestureDirections Gesture::direction() const +{ + return m_direction; +} + +void Gesture::setDirection(GestureDirections direction) +{ + m_direction = direction; +} } diff --git a/src/gestures.h b/src/gestures.h index 3cfbc31c92..d70b42277e 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -50,8 +50,12 @@ public: bool isFingerCountAcceptable(uint fingers) const; QSet acceptableFingerCounts() const; + GestureDirections direction() const; + void setDirection(GestureDirections direction); + protected: explicit Gesture(QObject *parent); + GestureDirections m_direction; Q_SIGNALS: /** @@ -80,9 +84,6 @@ public: explicit SwipeGesture(QObject *parent = nullptr); ~SwipeGesture() override; - GestureDirections direction() const; - void setDirection(GestureDirections direction); - void setMinimumX(int x); int minimumX() const; bool minimumXIsRelevant() const; @@ -118,7 +119,6 @@ Q_SIGNALS: void deltaProgress(const QSizeF &delta); private: - GestureDirections m_direction = GestureDirection::Down; bool m_minimumXRelevant = false; int m_minimumX = 0; bool m_minimumYRelevant = false; @@ -138,9 +138,6 @@ public: explicit PinchGesture(QObject *parent = nullptr); ~PinchGesture() override; - GestureDirections direction() const; - void setDirection(GestureDirections direction); - qreal minimumScaleDelta() const; /** @@ -161,7 +158,6 @@ Q_SIGNALS: void progress(qreal); private: - GestureDirections m_direction = GestureDirection::Expanding; bool m_minimumScaleDeltaRelevant = false; qreal m_minimumScaleDelta = DEFAULT_UNIT_SCALE_DELTA; }; diff --git a/src/globalshortcuts.cpp b/src/globalshortcuts.cpp index 6e67a26077..19767fa683 100644 --- a/src/globalshortcuts.cpp +++ b/src/globalshortcuts.cpp @@ -128,7 +128,6 @@ void GlobalShortcutsManager::registerGesture(GestureDeviceType device, GestureDi if (isSwipeDirection(direction)) { std::unique_ptr gesture = std::make_unique(); gesture->addFingerCount(fingerCount); - gesture->setDirection(direction); gesture->setMinimumDelta(QSizeF(200, 200)); connect(gesture.get(), &SwipeGesture::progress, progressCallback); connect(gesture.get(), &Gesture::triggered, onUp, &QAction::trigger, Qt::QueuedConnection); @@ -137,12 +136,12 @@ void GlobalShortcutsManager::registerGesture(GestureDeviceType device, GestureDi } else if (isPinchDirection(direction)) { std::unique_ptr gesture = std::make_unique(); gesture->addFingerCount(fingerCount); - gesture->setDirection(direction); connect(gesture.get(), &PinchGesture::progress, progressCallback); connect(gesture.get(), &Gesture::triggered, onUp, &QAction::trigger, Qt::QueuedConnection); connect(gesture.get(), &Gesture::cancelled, onUp, &QAction::trigger, Qt::QueuedConnection); shortcut.pinchGesture = std::move(gesture); } + shortcut.gesture()->setDirection(direction); addIfNotExists(GlobalShortcut(std::move(shortcut), onUp), device); }