Skip to content

Commit

Permalink
[ApplicationWindow] Fixup touch events for swipe back
Browse files Browse the repository at this point in the history
  • Loading branch information
neochapay committed Oct 12, 2023
1 parent d30a5d4 commit c93440f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/controls/editfilter.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2017 Eetu Kahelin
* Copyright (C) 2023 Chupligin Sergey <neochapay@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -29,6 +30,10 @@ EditFilter::EditFilter(QObject* parent)

bool EditFilter::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchEnd) {
emit touchEvent(event);
}

if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::TouchBegin) {
NemoFocusSingleton* nemoFocus = NemoFocusSingleton::instance();
if (nemoFocus->edit() != NULL) {
Expand Down
5 changes: 5 additions & 0 deletions src/controls/editfilter.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2017 Eetu Kahelin
* Copyright (C) 2023 Chupligin Sergey <neochapay@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand All @@ -16,6 +17,7 @@
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#ifndef EDITFILTER_H
#define EDITFILTER_H

Expand All @@ -27,6 +29,9 @@ class EditFilter : public QObject {
public:
explicit EditFilter(QObject* parent = 0);

signals:
void touchEvent(QEvent* event);

protected:
bool eventFilter(QObject* obj, QEvent* event);
};
Expand Down
15 changes: 15 additions & 0 deletions src/controls/nemowindow.cpp
Expand Up @@ -37,6 +37,7 @@ NemoWindow::NemoWindow(QWindow* parent)

installEventFilter(m_filter);
connect(m_screen, &QScreen::orientationChanged, this, &NemoWindow::orientationChanged);
connect(m_filter, &EditFilter::touchEvent, this, &NemoWindow::touchEventHandler);
}

Qt::ScreenOrientation NemoWindow::primaryOrientation() const
Expand Down Expand Up @@ -89,6 +90,20 @@ void NemoWindow::mouseMoveEvent(QMouseEvent* event)
}
}

void NemoWindow::touchEventHandler(QEvent* event)
{
QTouchEvent* tEvent = static_cast<QTouchEvent*>(event);
if (event->type() == QEvent::TouchBegin) {
m_mousePressed = true;
m_firstPoint = tEvent->points().first().position();
} else if (event->type() == QEvent::TouchEnd
&& tEvent->points().first().position().x() - m_firstPoint.x() > width() / 4
&& m_firstPoint.x() < width() / 4
&& allowExtendedEvents()) {
emit goBack();
}
}

bool NemoWindow::allowExtendedEvents() const
{
if (qEnvironmentVariableIsSet("NEMO_DISABLE_EXTENDED_EVENTS")) {
Expand Down
3 changes: 3 additions & 0 deletions src/controls/nemowindow.h
Expand Up @@ -47,6 +47,9 @@ class NemoWindow : public QQuickWindow {

void allowExtendedEventsChanged();

private slots:
void touchEventHandler(QEvent* event);

private:
EditFilter* m_filter;
QScreen* m_screen;
Expand Down

0 comments on commit c93440f

Please sign in to comment.