Skip to content

Commit

Permalink
fix: [touch] Optimize drag in touch.
Browse files Browse the repository at this point in the history
When touch screen drag and drop, it takes about 1 second to trigger the drag issue according to the icon.
Optimizing the time take.

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-298333.html
  • Loading branch information
GongHeng2017 authored and deepin-bot[bot] committed Jan 6, 2025
1 parent 0d51772 commit 695c7d8
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/plugins/desktop/core/ddplugin-canvas/view/canvasview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
DFMBASE_USE_NAMESPACE
using namespace ddplugin_canvas;

inline constexpr int kStartDragDistance { 20 };

CanvasView::CanvasView(QWidget *parent)
: QAbstractItemView(parent), d(new CanvasViewPrivate(this))
{
Expand Down Expand Up @@ -432,6 +434,8 @@ void CanvasView::dragLeaveEvent(QDragLeaveEvent *event)

void CanvasView::dropEvent(QDropEvent *event)
{
d->isTouchDrag = false;

if (d->dragDropOper->drop(event)) {
activateWindow();
setState(NoState);
Expand Down Expand Up @@ -656,6 +660,15 @@ void CanvasView::mousePressEvent(QMouseEvent *event)
// must get index on pos before QAbstractItemView::mousePressEvent
auto index = indexAt(event->pos());
d->viewSetting->checkTouchDrag(event);

if (event->source() == Qt::MouseEventSynthesizedByQt
&& event->button() == Qt::LeftButton
&& index.isValid()) {
d->isTouchDrag = true;
d->mousePressPosForTouch = event->pos();
}


QAbstractItemView::mousePressEvent(event);

if (!index.isValid() && event->button() == Qt::LeftButton) { //empty area
Expand All @@ -668,6 +681,13 @@ void CanvasView::mousePressEvent(QMouseEvent *event)

void CanvasView::mouseMoveEvent(QMouseEvent *event)
{
if (event->source() == Qt::MouseEventSynthesizedByQt
&& d->isTouchDrag) {
const QPoint distance = event->pos() - d->mousePressPosForTouch;
if (distance.manhattanLength() > kStartDragDistance)
startDrag(Qt::MoveAction);
}

QAbstractItemView::mouseMoveEvent(event);
}

Expand Down
3 changes: 3 additions & 0 deletions src/plugins/desktop/core/ddplugin-canvas/view/canvasview_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class CanvasViewPrivate : public QObject
bool showGrid = false;
int screenNum;

QPoint mousePressPosForTouch;
bool isTouchDrag { false };

CanvasInfo canvasInfo;
QMargins gridMargins; // grid inner margin.
QMargins viewMargins; // view margin is to decrease canvas rect on view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ void ViewSettingUtil::checkTouchDrag(QMouseEvent *event)
if (themeSettings)
touchFlickBeginMoveDelay = themeSettings->property("touchFlickBeginMoveDelay");

//若dde配置了则使用dde的配置,若没有则使用默认的200ms
touchDragTimer.setInterval(touchFlickBeginMoveDelay.isValid() ? touchFlickBeginMoveDelay.toInt() : 200);
touchDragTimer.start();
//若dde配置了则使用dde的配置,若没有则不延时
if (touchFlickBeginMoveDelay.isValid()) {
touchDragTimer.setInterval(touchFlickBeginMoveDelay.toInt());
touchDragTimer.start();
}
} else {
touchDragTimer.stop();
}
Expand Down
26 changes: 24 additions & 2 deletions src/plugins/desktop/ddplugin-organizer/view/collectionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ static constexpr int kCollectionItemVerticalMargin = 2;
static constexpr int kIconOffset = 10;
static constexpr int kIconSelectMargin = 3;

inline constexpr int kStartDragDistance { 20 };

CollectionViewPrivate::CollectionViewPrivate(const QString &uuid, CollectionDataProvider *dataProvider, CollectionView *qq, QObject *parent)
: QObject(parent), q(qq), id(uuid), provider(dataProvider), menuProxy(new CollectionViewMenu(qq))
{
Expand Down Expand Up @@ -295,8 +297,10 @@ void CollectionViewPrivate::checkTouchDarg(QMouseEvent *event)
if (themeSettings)
touchFlickBeginMoveDelay = themeSettings->property("touchFlickBeginMoveDelay");

touchDragTimer.setInterval(touchFlickBeginMoveDelay.isValid() ? touchFlickBeginMoveDelay.toInt() : 200);
touchDragTimer.start();
if (touchFlickBeginMoveDelay.isValid()) {
touchDragTimer.setInterval(touchFlickBeginMoveDelay.toInt());
touchDragTimer.start();
}
} else {
touchDragTimer.stop();
}
Expand Down Expand Up @@ -1807,6 +1811,13 @@ void CollectionView::mousePressEvent(QMouseEvent *event)
if (index.isValid() && isPersistentEditorOpen(index))
return;

if (event->source() == Qt::MouseEventSynthesizedByQt
&& event->button() == Qt::LeftButton
&& index.isValid()) {
d->isTouchDrag = true;
d->mousePressPosForTouch = event->pos();
}

d->pressedModifiers = event->modifiers();
d->pressedAlreadySelected = selectionModel()->isSelected(index);
d->pressedIndex = index;
Expand Down Expand Up @@ -1864,6 +1875,14 @@ void CollectionView::mouseMoveEvent(QMouseEvent *event)
{
if (d->ignoreMouseEvent)
return;

if (event->source() == Qt::MouseEventSynthesizedByQt
&& d->isTouchDrag) {
const QPoint distance = event->pos() - d->mousePressPosForTouch;
if (distance.manhattanLength() > kStartDragDistance)
startDrag(Qt::MoveAction);
}

QAbstractItemView::mouseMoveEvent(event);

// left button pressed on empty area.
Expand Down Expand Up @@ -2239,7 +2258,10 @@ void CollectionView::dragLeaveEvent(QDragLeaveEvent *event)

void CollectionView::dropEvent(QDropEvent *event)
{
d->isTouchDrag = false;

if (d->drop(event)) {
activateWindow();
setState(NoState);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ private slots:
bool pressedAlreadySelected = false;
bool ignoreMouseEvent = false;

QPoint mousePressPosForTouch;
bool isTouchDrag { false };

Qt::SortOrder sortOrder = Qt::DescendingOrder;
int sortRole = DFMGLOBAL_NAMESPACE::ItemRoles::kItemFileMimeTypeRole;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ using namespace dfmplugin_workspace;
DFMGLOBAL_USE_NAMESPACE
DFMBASE_USE_NAMESPACE

inline constexpr int kStartDragDistance { 20 };

FileView::FileView(const QUrl &url, QWidget *parent)
: DListView(parent), d(new FileViewPrivate(this))
{
Expand Down Expand Up @@ -1210,6 +1212,13 @@ void FileView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFla

void FileView::mousePressEvent(QMouseEvent *event)
{
if (event->source() == Qt::MouseEventSynthesizedByQt
&& event->button() == Qt::LeftButton
&& indexAt(event->pos()).isValid()) {
d->isTouchDrag = true;
d->mousePressPosForTouch = event->pos();
}

if (event->buttons().testFlag(Qt::LeftButton)) {
d->mouseLeftPressed = true;
d->mouseLastPos = event->globalPos();
Expand Down Expand Up @@ -1300,6 +1309,13 @@ void FileView::mouseMoveEvent(QMouseEvent *event)
if (d->pressedStartWithExpand)
return;

if (event->source() == Qt::MouseEventSynthesizedByQt
&& d->isTouchDrag) {
const QPoint distance = event->pos() - d->mousePressPosForTouch;
if (distance.manhattanLength() > kStartDragDistance)
startDrag(Qt::MoveAction);
}

if (event->buttons() & Qt::LeftButton)
d->mouseMoveRect = QRect(event->globalPos(), d->mouseLastPos);

Expand Down Expand Up @@ -1356,6 +1372,7 @@ void FileView::dragLeaveEvent(QDragLeaveEvent *event)

void FileView::dropEvent(QDropEvent *event)
{
d->isTouchDrag = false;
setViewSelectState(false);
d->dragDropHelper->drop(event);
setState(NoState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class FileViewPrivate
QPoint mouseLastPos { QPoint(0, 0) };
QRect mouseMoveRect { QRect(-1, -1, 1, 1) };

QPoint mousePressPosForTouch;
bool isTouchDrag { false };

bool itemsExpandable { false };
std::atomic_bool isShowSmbMountError { false };

Expand Down

0 comments on commit 695c7d8

Please sign in to comment.