Skip to content
Merged
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
13 changes: 9 additions & 4 deletions net-view/window/netview.cpp
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
#include "netview.h"
Expand All @@ -13,11 +13,12 @@
#include <DStyleOption>

#include <QEvent>
#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 <QScroller>

Check warning on line 18 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 19 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 20 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>

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

DWIDGET_USE_NAMESPACE

Expand Down Expand Up @@ -82,9 +83,13 @@
connect(this, &NetView::activated, this, &NetView::onActivated);

// 支持在触摸屏上滚动
// QScroller::grabGesture(viewport(), QScroller::LeftMouseButtonGesture);
// QScrollerProperties sp;
// sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
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);
}
Comment on lines 85 to 93
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider extracting scroll tuning constants or referencing expected ranges.

These hard-coded 0.5 values effectively lock in your touch scroll UX and may need tuning later. Consider naming these as shared constants or centralizing them in a config so they’re easier to adjust, reason about, and keep aligned with Qt’s recommended or platform-specific ranges.

Suggested change
// 支持在触摸屏上滚动
// QScroller::grabGesture(viewport(), QScroller::LeftMouseButtonGesture);
// QScrollerProperties sp;
// sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
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);
}
// 支持在触摸屏上滚动
constexpr qreal kTouchScrollDecelerationFactor = 0.5; // Tunable: see Qt docs for recommended ranges
constexpr qreal kTouchScrollMaximumVelocity = 0.5; // Tunable: see Qt docs for recommended ranges
QScroller::grabGesture(viewport(), QScroller::TouchGesture);
QScroller *scroller = QScroller::scroller(viewport());
QScrollerProperties sp = scroller->scrollerProperties();
sp.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
sp.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
sp.setScrollMetric(QScrollerProperties::DecelerationFactor, kTouchScrollDecelerationFactor);
sp.setScrollMetric(QScrollerProperties::MaximumVelocity, kTouchScrollMaximumVelocity);
scroller->setScrollerProperties(sp);
}


NetView::~NetView() = default;
Expand Down
Loading