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);
}
SwipeArea::Mode SwipeArea::mode()
{
return m_mode;
}
void SwipeArea::setMode(Mode mode)
{
m_mode = mode;
Q_EMIT modeChanged();
}
bool SwipeArea::interactive()
{
return m_interactive;
@ -251,7 +262,11 @@ void SwipeArea::handleMoveEvent(QPointerEvent *event, QPointF point)
if (!m_stealMouse) {
// 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;
}

View file

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

View file

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

View file

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

View file

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