Revert "Move gesture direction to base class"
This reverts commit 634182d489
.
It was pushed with unreviewed changes and not fully resolved issues.
This commit is contained in:
parent
e3df43c701
commit
db1ec66eb1
4 changed files with 62 additions and 27 deletions
|
@ -19,8 +19,10 @@ class GestureTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void testDirection_data();
|
void testSwipeDirection_data();
|
||||||
void testDirection();
|
void testSwipeDirection();
|
||||||
|
void testPinchDirection_data();
|
||||||
|
void testPinchDirection();
|
||||||
|
|
||||||
// swipe only
|
// swipe only
|
||||||
void testMinimumX_data();
|
void testMinimumX_data();
|
||||||
|
@ -52,28 +54,46 @@ private Q_SLOTS:
|
||||||
void testSwipeGeometryStart();
|
void testSwipeGeometryStart();
|
||||||
};
|
};
|
||||||
|
|
||||||
void GestureTest::testDirection_data()
|
void GestureTest::testSwipeDirection_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<GestureDirection>("direction");
|
QTest::addColumn<GestureDirection>("swipe_direction");
|
||||||
|
|
||||||
QTest::newRow("Up") << GestureDirection::Up;
|
QTest::newRow("Up") << GestureDirection::Up;
|
||||||
QTest::newRow("Left") << GestureDirection::Left;
|
QTest::newRow("Left") << GestureDirection::Left;
|
||||||
QTest::newRow("Right") << GestureDirection::Right;
|
QTest::newRow("Right") << GestureDirection::Right;
|
||||||
QTest::newRow("Down") << GestureDirection::Down;
|
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<GestureDirection>("pinch_direction");
|
||||||
|
|
||||||
QTest::newRow("Contracting") << GestureDirection::Contracting;
|
QTest::newRow("Contracting") << GestureDirection::Contracting;
|
||||||
QTest::newRow("Expanding") << GestureDirection::Expanding;
|
QTest::newRow("Expanding") << GestureDirection::Expanding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestureTest::testDirection()
|
void GestureTest::testPinchDirection()
|
||||||
{
|
{
|
||||||
SwipeGesture gesture;
|
PinchGesture gesture;
|
||||||
QCOMPARE(gesture.direction(), 0);
|
QCOMPARE(gesture.direction(), GestureDirection::Expanding);
|
||||||
QFETCH(GestureDirection, direction);
|
QFETCH(GestureDirection, pinch_direction);
|
||||||
gesture.setDirection(direction);
|
gesture.setDirection(pinch_direction);
|
||||||
QCOMPARE(gesture.direction(), direction);
|
QCOMPARE(gesture.direction(), pinch_direction);
|
||||||
// back to down
|
// back to down
|
||||||
gesture.setDirection(GestureDirection::Down);
|
gesture.setDirection(GestureDirection::Expanding);
|
||||||
QCOMPARE(gesture.direction(), GestureDirection::Down);
|
QCOMPARE(gesture.direction(), GestureDirection::Expanding);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestureTest::testMinimumX_data()
|
void GestureTest::testMinimumX_data()
|
||||||
|
|
|
@ -367,6 +367,16 @@ void GestureRecognizer::endPinchGesture() // because fingers up
|
||||||
m_currentSwipeAxis = Axis::None;
|
m_currentSwipeAxis = Axis::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GestureDirections SwipeGesture::direction() const
|
||||||
|
{
|
||||||
|
return m_direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwipeGesture::setDirection(GestureDirections direction)
|
||||||
|
{
|
||||||
|
m_direction = direction;
|
||||||
|
}
|
||||||
|
|
||||||
void SwipeGesture::setMinimumX(int x)
|
void SwipeGesture::setMinimumX(int x)
|
||||||
{
|
{
|
||||||
m_minimumX = x;
|
m_minimumX = x;
|
||||||
|
@ -447,6 +457,16 @@ bool SwipeGesture::isMinimumDeltaRelevant() const
|
||||||
return m_minimumDeltaRelevant;
|
return m_minimumDeltaRelevant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GestureDirections PinchGesture::direction() const
|
||||||
|
{
|
||||||
|
return m_direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PinchGesture::setDirection(GestureDirections direction)
|
||||||
|
{
|
||||||
|
m_direction = direction;
|
||||||
|
}
|
||||||
|
|
||||||
qreal PinchGesture::minimumScaleDelta() const
|
qreal PinchGesture::minimumScaleDelta() const
|
||||||
{
|
{
|
||||||
return m_minimumScaleDelta;
|
return m_minimumScaleDelta;
|
||||||
|
@ -490,14 +510,4 @@ QSet<uint> Gesture::acceptableFingerCounts() const
|
||||||
{
|
{
|
||||||
return m_validFingerCounts;
|
return m_validFingerCounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
GestureDirections Gesture::direction() const
|
|
||||||
{
|
|
||||||
return m_direction;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gesture::setDirection(GestureDirections direction)
|
|
||||||
{
|
|
||||||
m_direction = direction;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,8 @@ public:
|
||||||
bool isFingerCountAcceptable(uint fingers) const;
|
bool isFingerCountAcceptable(uint fingers) const;
|
||||||
QSet<uint> acceptableFingerCounts() const;
|
QSet<uint> acceptableFingerCounts() const;
|
||||||
|
|
||||||
GestureDirections direction() const;
|
|
||||||
void setDirection(GestureDirections direction);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Gesture(QObject *parent);
|
explicit Gesture(QObject *parent);
|
||||||
GestureDirections m_direction;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
|
@ -84,6 +80,9 @@ public:
|
||||||
explicit SwipeGesture(QObject *parent = nullptr);
|
explicit SwipeGesture(QObject *parent = nullptr);
|
||||||
~SwipeGesture() override;
|
~SwipeGesture() override;
|
||||||
|
|
||||||
|
GestureDirections direction() const;
|
||||||
|
void setDirection(GestureDirections direction);
|
||||||
|
|
||||||
void setMinimumX(int x);
|
void setMinimumX(int x);
|
||||||
int minimumX() const;
|
int minimumX() const;
|
||||||
bool minimumXIsRelevant() const;
|
bool minimumXIsRelevant() const;
|
||||||
|
@ -119,6 +118,7 @@ Q_SIGNALS:
|
||||||
void deltaProgress(const QSizeF &delta);
|
void deltaProgress(const QSizeF &delta);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
GestureDirections m_direction = GestureDirection::Down;
|
||||||
bool m_minimumXRelevant = false;
|
bool m_minimumXRelevant = false;
|
||||||
int m_minimumX = 0;
|
int m_minimumX = 0;
|
||||||
bool m_minimumYRelevant = false;
|
bool m_minimumYRelevant = false;
|
||||||
|
@ -138,6 +138,9 @@ public:
|
||||||
explicit PinchGesture(QObject *parent = nullptr);
|
explicit PinchGesture(QObject *parent = nullptr);
|
||||||
~PinchGesture() override;
|
~PinchGesture() override;
|
||||||
|
|
||||||
|
GestureDirections direction() const;
|
||||||
|
void setDirection(GestureDirections direction);
|
||||||
|
|
||||||
qreal minimumScaleDelta() const;
|
qreal minimumScaleDelta() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,6 +161,7 @@ Q_SIGNALS:
|
||||||
void progress(qreal);
|
void progress(qreal);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
GestureDirections m_direction = GestureDirection::Expanding;
|
||||||
bool m_minimumScaleDeltaRelevant = false;
|
bool m_minimumScaleDeltaRelevant = false;
|
||||||
qreal m_minimumScaleDelta = DEFAULT_UNIT_SCALE_DELTA;
|
qreal m_minimumScaleDelta = DEFAULT_UNIT_SCALE_DELTA;
|
||||||
};
|
};
|
||||||
|
|
|
@ -128,6 +128,7 @@ void GlobalShortcutsManager::registerGesture(GestureDeviceType device, GestureDi
|
||||||
if (isSwipeDirection(direction)) {
|
if (isSwipeDirection(direction)) {
|
||||||
std::unique_ptr<SwipeGesture> gesture = std::make_unique<SwipeGesture>();
|
std::unique_ptr<SwipeGesture> gesture = std::make_unique<SwipeGesture>();
|
||||||
gesture->addFingerCount(fingerCount);
|
gesture->addFingerCount(fingerCount);
|
||||||
|
gesture->setDirection(direction);
|
||||||
gesture->setMinimumDelta(QSizeF(200, 200));
|
gesture->setMinimumDelta(QSizeF(200, 200));
|
||||||
connect(gesture.get(), &SwipeGesture::progress, progressCallback);
|
connect(gesture.get(), &SwipeGesture::progress, progressCallback);
|
||||||
connect(gesture.get(), &Gesture::triggered, onUp, &QAction::trigger, Qt::QueuedConnection);
|
connect(gesture.get(), &Gesture::triggered, onUp, &QAction::trigger, Qt::QueuedConnection);
|
||||||
|
@ -136,12 +137,12 @@ void GlobalShortcutsManager::registerGesture(GestureDeviceType device, GestureDi
|
||||||
} else if (isPinchDirection(direction)) {
|
} else if (isPinchDirection(direction)) {
|
||||||
std::unique_ptr<PinchGesture> gesture = std::make_unique<PinchGesture>();
|
std::unique_ptr<PinchGesture> gesture = std::make_unique<PinchGesture>();
|
||||||
gesture->addFingerCount(fingerCount);
|
gesture->addFingerCount(fingerCount);
|
||||||
|
gesture->setDirection(direction);
|
||||||
connect(gesture.get(), &PinchGesture::progress, progressCallback);
|
connect(gesture.get(), &PinchGesture::progress, progressCallback);
|
||||||
connect(gesture.get(), &Gesture::triggered, onUp, &QAction::trigger, Qt::QueuedConnection);
|
connect(gesture.get(), &Gesture::triggered, onUp, &QAction::trigger, Qt::QueuedConnection);
|
||||||
connect(gesture.get(), &Gesture::cancelled, onUp, &QAction::trigger, Qt::QueuedConnection);
|
connect(gesture.get(), &Gesture::cancelled, onUp, &QAction::trigger, Qt::QueuedConnection);
|
||||||
shortcut.pinchGesture = std::move(gesture);
|
shortcut.pinchGesture = std::move(gesture);
|
||||||
}
|
}
|
||||||
shortcut.gesture()->setDirection(direction);
|
|
||||||
|
|
||||||
addIfNotExists(GlobalShortcut(std::move(shortcut), onUp), device);
|
addIfNotExists(GlobalShortcut(std::move(shortcut), onUp), device);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue