components: Add SwipeArea filter modes

This commit is contained in:
Devin Lin 2023-09-30 10:06:41 -07:00
parent e5c80e5f38
commit 552ab53b49
5 changed files with 28 additions and 1 deletions

View file

@ -22,6 +22,17 @@ SwipeArea::SwipeArea(QQuickItem *parent)
setFiltersChildMouseEvents(true); setFiltersChildMouseEvents(true);
} }
SwipeArea::Mode SwipeArea::mode()
{
return m_mode;
}
void SwipeArea::setMode(Mode mode)
{
m_mode = mode;
Q_EMIT modeChanged();
}
bool SwipeArea::interactive() bool SwipeArea::interactive()
{ {
return m_interactive; return m_interactive;
@ -251,7 +262,11 @@ void SwipeArea::handleMoveEvent(QPointerEvent *event, QPointF point)
if (!m_stealMouse) { if (!m_stealMouse) {
// if we haven't reached the swipe registering threshold yet, don't start the swipe // if we haven't reached the swipe registering threshold yet, don't start the swipe
if (qAbs(point.manhattanLength() - m_pressPos.manhattanLength()) < SWIPE_REGISTER_THRESHOLD) { if (m_mode == Mode::VerticalOnly && qAbs(point.y() - m_pressPos.y()) < SWIPE_REGISTER_THRESHOLD) {
return;
} else if (m_mode == Mode::HorizontalOnly && qAbs(point.x() - m_pressPos.x()) < SWIPE_REGISTER_THRESHOLD) {
return;
} else if (m_mode == Mode::BothAxis && qAbs(point.manhattanLength() - m_pressPos.manhattanLength()) < SWIPE_REGISTER_THRESHOLD) {
return; return;
} }

View file

@ -22,6 +22,7 @@
class SwipeArea : public QQuickItem class SwipeArea : public QQuickItem
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(SwipeArea::Mode mode READ mode WRITE setMode NOTIFY modeChanged)
Q_PROPERTY(bool interactive READ interactive NOTIFY interactiveChanged) Q_PROPERTY(bool interactive READ interactive NOTIFY interactiveChanged)
Q_PROPERTY(bool moving READ moving NOTIFY movingChanged) Q_PROPERTY(bool moving READ moving NOTIFY movingChanged)
Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
@ -31,11 +32,18 @@ class SwipeArea : public QQuickItem
public: public:
SwipeArea(QQuickItem *parent = nullptr); SwipeArea(QQuickItem *parent = nullptr);
enum Mode { BothAxis = 0, VerticalOnly, HorizontalOnly };
Q_ENUM(Mode)
Mode mode();
void setMode(Mode mode);
bool interactive(); bool interactive();
bool moving(); bool moving();
bool pressed(); bool pressed();
Q_SIGNALS: Q_SIGNALS:
void modeChanged();
void interactiveChanged(); void interactiveChanged();
void movingChanged(); void movingChanged();
void pressedChanged(); void pressedChanged();
@ -69,6 +77,7 @@ private:
void resetSwipe(); void resetSwipe();
Mode m_mode = Mode::BothAxis;
bool m_interactive = true; bool m_interactive = true;
bool m_pressed = false; bool m_pressed = false;

View file

@ -231,6 +231,7 @@ Item {
MobileShell.SwipeArea { MobileShell.SwipeArea {
id: swipeArea id: swipeArea
mode: MobileShell.SwipeArea.VerticalOnly
anchors.fill: parent anchors.fill: parent
onSwipeStarted: { onSwipeStarted: {

View file

@ -14,6 +14,7 @@ import org.kde.plasma.private.mobileshell as MobileShell
*/ */
MobileShell.SwipeArea { MobileShell.SwipeArea {
id: root id: root
mode: MobileShell.SwipeArea.VerticalOnly
required property ActionDrawer actionDrawer required property ActionDrawer actionDrawer

View file

@ -9,6 +9,7 @@ import org.kde.plasma.private.mobileshell as MobileShell
MobileShell.SwipeArea { MobileShell.SwipeArea {
id: root id: root
mode: MobileShell.SwipeArea.VerticalOnly
property int position: 0 property int position: 0