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
10 changes: 4 additions & 6 deletions common-plugin/networkdialog/networkpanel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand Down Expand Up @@ -111,6 +111,7 @@ void NetworkPanel::initUi()
m_netListView->setMouseTracking(true);
m_netListView->setItemMargins(QMargins(10, 0, 10, 0));
m_netListView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
m_netListView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
m_netListView->setItemRadius(0);

NetworkDelegate *delegate = new NetworkDelegate(m_netListView);
Expand Down Expand Up @@ -163,11 +164,8 @@ void NetworkPanel::initUi()
setControlBackground();

// 支持在触摸屏上滚动
QScroller::grabGesture(m_netListView->viewport(), QScroller::LeftMouseButtonGesture);
QScroller *scroller = QScroller::scroller(m_netListView->window());
QScrollerProperties sp;
sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
scroller->setScrollerProperties(sp);
m_netListView->setAttribute(Qt::WA_AcceptTouchEvents, true);
m_netListView->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true);
}

void NetworkPanel::initConnection()
Expand Down
80 changes: 73 additions & 7 deletions net-view/window/netview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
#include <DStyle>
#include <DStyleOption>

#include <QEvent>

Check warning on line 15 in net-view/window/netview.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 <QHoverEvent>

Check warning on line 16 in net-view/window/netview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 17 in net-view/window/netview.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 <QCoreApplication>

Check warning on line 18 in net-view/window/netview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 19 in net-view/window/netview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 20 in net-view/window/netview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 21 in net-view/window/netview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

DWIDGET_USE_NAMESPACE
Expand Down Expand Up @@ -66,6 +67,8 @@
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);

setSelectionMode(QAbstractItemView::NoSelection);
setRootIsDecorated(false);
Expand All @@ -83,13 +86,8 @@
connect(this, &NetView::activated, this, &NetView::onActivated);

// 支持在触摸屏上滚动
QScroller::grabGesture(viewport(), QScroller::TouchGesture);
QScrollerProperties sp = QScroller::scroller(viewport())->scrollerProperties();
sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
sp.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
sp.setScrollMetric(QScrollerProperties::DecelerationFactor, 0.5);
sp.setScrollMetric(QScrollerProperties::MaximumVelocity, 0.5);
QScroller::scroller(viewport())->setScrollerProperties(sp);
setAttribute(Qt::WA_AcceptTouchEvents, true);
viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true);
}

NetView::~NetView() = default;
Expand Down Expand Up @@ -183,6 +181,74 @@

bool NetView::viewportEvent(QEvent *event)
Comment thread
yixinshark marked this conversation as resolved.
{
const QEvent::Type type = event->type();
if (type == QEvent::TouchBegin || type == QEvent::TouchUpdate ||
type == QEvent::TouchEnd || type == QEvent::TouchCancel) {

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_touchPressPos = pt.globalPosition();
m_isDrag = false;
break;
}
case QEvent::TouchUpdate: {
QPointF delta = pt.globalPosition() - m_touchPressPos;

if (!m_isDrag && (qAbs(delta.y()) >= QApplication::startDragDistance() || qAbs(delta.x()) >= QApplication::startDragDistance())) {
m_isDrag = true;
}

if (m_isDrag) {
if (qAbs(delta.y()) > 0 && verticalScrollBar()) {
verticalScrollBar()->setValue(verticalScrollBar()->value() - delta.y());
}
if (qAbs(delta.x()) > 0 && horizontalScrollBar()) {
horizontalScrollBar()->setValue(horizontalScrollBar()->value() - delta.x());
}
m_touchPressPos = pt.globalPosition();
}
break;
}
case QEvent::TouchEnd: {
if (!m_isDrag) {
// Determine the correct target widget for the click
QWidget *target = viewport();
QPoint widgetPos = pt.position().toPoint();

if (QWidget *child = target->childAt(widgetPos)) {
target = child;
if (target) {
widgetPos = target->mapFrom(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::NoButton, Qt::NoModifier);
QCoreApplication::sendEvent(target, &release);
}
break;
}
case QEvent::TouchCancel: {
m_isDrag = false;
break;
}
default:
break;
}

event->accept();
return true;
}

switch (event->type()) {
case QEvent::HoverLeave: {
setCurrentIndex(QModelIndex());
Expand Down
4 changes: 3 additions & 1 deletion net-view/window/netview.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef NETVIEW_H
Expand Down Expand Up @@ -74,6 +74,8 @@ protected Q_SLOTS:
NetDelegate *m_delegate;
bool m_closeOnClear;
int m_maxHeight;
QPointF m_touchPressPos;
bool m_isDrag = false;
};

} // namespace network
Expand Down