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
8 changes: 3 additions & 5 deletions plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2016 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2016 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand All @@ -10,12 +10,13 @@
#include "bluetoothconstants.h"
#include "device.h"
#include "horizontalseparator.h"
#include "jumpsettingbutton.h"

Check warning on line 13 in plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "jumpsettingbutton.h" not found.
#include "constants.h"

Check warning on line 14 in plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "constants.h" not found.
#include "plugins-logging-category.h"

Check warning on line 15 in plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "plugins-logging-category.h" not found.
#include "touchscrollfilter.h"

Check warning on line 16 in plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "touchscrollfilter.h" not found.

#include <DDBusSender>

Check warning on line 18 in plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DDBusSender> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DIconButton>

Check warning on line 19 in plugins/dde-dock/bluetooth/componments/bluetoothapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DIconButton> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DLabel>
#include <DListView>
#include <DScrollArea>
Expand Down Expand Up @@ -229,10 +230,7 @@
m_scrollArea->setPalette(scrollAreaBackground);

// QScroller::grabGesture(m_scrollArea->viewport(), QScroller::LeftMouseButtonGesture);
QScroller *scroller = QScroller::scroller(m_scrollArea);
Comment thread
yixinshark marked this conversation as resolved.
QScrollerProperties sp;
sp.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
scroller->setScrollerProperties(sp);
new TouchScrollFilter(m_scrollArea);

m_mainLayout->setSpacing(0);
m_mainLayout->setContentsMargins(0, 10, 0, 0);
Expand Down
94 changes: 94 additions & 0 deletions plugins/dde-dock/common/touchscrollfilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "touchscrollfilter.h"

#include <QEvent>

Check warning on line 7 in plugins/dde-dock/common/touchscrollfilter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTouchEvent>

Check warning on line 8 in plugins/dde-dock/common/touchscrollfilter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTouchEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMouseEvent>

Check warning on line 9 in plugins/dde-dock/common/touchscrollfilter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QScrollBar>

Check warning on line 10 in plugins/dde-dock/common/touchscrollfilter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QScrollBar> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QApplication>

TouchScrollFilter::TouchScrollFilter(QAbstractScrollArea *area)
: QObject(area)
, m_area(area)
, m_isDrag(false)
{
if (m_area) {
m_area->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true);
m_area->setAttribute(Qt::WA_AcceptTouchEvents, true);
m_area->viewport()->installEventFilter(this);
}
}

bool TouchScrollFilter::eventFilter(QObject *watched, QEvent *event)
{
if (!m_area)
return QObject::eventFilter(watched, event);

const QEvent::Type type = event->type();
if (type != QEvent::TouchBegin && type != QEvent::TouchUpdate &&
type != QEvent::TouchEnd && type != QEvent::TouchCancel) {
return QObject::eventFilter(watched, event);
}

QTouchEvent *te = static_cast<QTouchEvent *>(event);
if (te->points().isEmpty()) {
event->accept();
return true;
}

QEventPoint pt = te->points().first();

switch (type) {
case QEvent::TouchBegin: {
m_lastPos = pt.globalPosition();
m_isDrag = false;
break;
}
case QEvent::TouchUpdate: {
qreal deltaY = pt.globalPosition().y() - m_lastPos.y();
qreal deltaX = pt.globalPosition().x() - m_lastPos.x();

if (!m_isDrag && (qAbs(deltaY) >= QApplication::startDragDistance() || qAbs(deltaX) >= QApplication::startDragDistance())) {
m_isDrag = true;
}

if (m_isDrag) {
if (qAbs(deltaY) > 0 && m_area->verticalScrollBar()) {
m_area->verticalScrollBar()->setValue(m_area->verticalScrollBar()->value() - deltaY);
}
if (qAbs(deltaX) > 0 && m_area->horizontalScrollBar()) {
m_area->horizontalScrollBar()->setValue(m_area->horizontalScrollBar()->value() - deltaX);
}
m_lastPos = pt.globalPosition();
}
break;
}
case QEvent::TouchEnd: {
Comment thread
yixinshark marked this conversation as resolved.
if (!m_isDrag) {
// Determine the correct target widget for the click
QWidget *target = m_area->viewport();
QPoint widgetPos = pt.position().toPoint();

// If it's a QScrollArea, the content widget is usually a child of the viewport
if (QWidget *child = target->childAt(widgetPos)) {
target = child;
widgetPos = target->mapFrom(m_area->viewport(), widgetPos);
}

QMouseEvent press(QEvent::MouseButtonPress, widgetPos, pt.globalPosition(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QCoreApplication::sendEvent(target, &press);
QMouseEvent release(QEvent::MouseButtonRelease, widgetPos, pt.globalPosition(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QCoreApplication::sendEvent(target, &release);
}
break;
}
default:
break;
}

event->accept();
return true;
}
27 changes: 27 additions & 0 deletions plugins/dde-dock/common/touchscrollfilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#ifndef TOUCHSCROLLFILTER_H
#define TOUCHSCROLLFILTER_H

#include <QObject>
#include <QPointF>
#include <QAbstractScrollArea>

class TouchScrollFilter : public QObject
{
public:
explicit TouchScrollFilter(QAbstractScrollArea *area);
~TouchScrollFilter() override = default;

protected:
bool eventFilter(QObject *watched, QEvent *event) override;

private:
QAbstractScrollArea *m_area;
QPointF m_lastPos;
bool m_isDrag;
};

#endif // TOUCHSCROLLFILTER_H