Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions src/input/gestures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,16 @@ GestureRecognizer::GestureRecognizer(QObject *parent)
void GestureRecognizer::registerSwipeGesture(SwipeGesture *gesture)
{
Q_ASSERT(!m_swipeGestures.contains(gesture));
auto connection = connect(gesture,
&QObject::destroyed,
this,
std::bind(&GestureRecognizer::unregisterSwipeGesture, this, gesture));
m_destroyConnections.insert(gesture, connection);
connect(gesture, &QObject::destroyed, this, [this, gesture] {
m_swipeGestures.removeOne(gesture);
m_activeSwipeGestures.removeOne(gesture);
});
m_swipeGestures << gesture;
}

void GestureRecognizer::unregisterSwipeGesture(SwipeGesture *gesture)
{
auto it = m_destroyConnections.find(gesture);
if (it != m_destroyConnections.end()) {
disconnect(it.value());
m_destroyConnections.erase(it);
}
m_swipeGestures.removeAll(gesture);
m_swipeGestures.removeOne(gesture);
if (m_activeSwipeGestures.removeOne(gesture)) {
Q_EMIT gesture->cancelled();
}
Expand Down Expand Up @@ -371,7 +365,6 @@ HoldGesture::~HoldGesture()
{
if (m_holdTimer != nullptr) {
m_holdTimer->stop();
m_holdTimer->deleteLater();
}
}

Expand All @@ -398,22 +391,17 @@ bool HoldGesture::isActive() const
void GestureRecognizer::registerHoldGesture(HoldGesture *gesture)
{
Q_ASSERT(!m_holdGestures.contains(gesture));
auto connection = connect(gesture,
&QObject::destroyed,
this,
std::bind(&GestureRecognizer::unregisterHoldGesture, this, gesture));
m_destroyConnections.insert(gesture, connection);
connect(gesture, &QObject::destroyed, this, [this, gesture] {
m_holdGestures.removeOne(gesture);
m_activeHoldGestures.removeOne(gesture);
});
m_holdGestures << gesture;
}

void GestureRecognizer::unregisterHoldGesture(HoldGesture *gesture)
{
auto it = m_destroyConnections.find(gesture);
if (it != m_destroyConnections.end()) {
disconnect(it.value());
m_destroyConnections.erase(it);
}
if (m_holdGestures.removeOne(gesture)) {
m_holdGestures.removeOne(gesture);
if (m_activeHoldGestures.removeOne(gesture)) {
Q_EMIT gesture->cancelled();
}
gesture->deleteLater();
Expand Down
3 changes: 1 addition & 2 deletions src/input/gestures.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Copyright (C) 2024-2025 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2024-2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#pragma once
Expand Down Expand Up @@ -158,7 +158,6 @@ class GestureRecognizer : public QObject
QList<SwipeGesture *> m_activeSwipeGestures;
QList<HoldGesture *> m_holdGestures;
QList<HoldGesture *> m_activeHoldGestures;
QMap<Gesture *, QMetaObject::Connection> m_destroyConnections;

QPointF m_currentDelta = QPointF(0, 0);
uint m_currentFingerCount = 0;
Expand Down
Loading