From 31663a9ded96519fd0827a581d8d87f3119c0560 Mon Sep 17 00:00:00 2001 From: liuxing Date: Mon, 27 Jul 2020 14:32:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=BB=E5=8A=A1=E6=A0=8F=E5=8D=95?= =?UTF-8?q?=E6=8C=87=E9=95=BF=E6=8C=89=E6=94=AF=E6=8C=81=E6=8B=96=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 任务栏图标拖动需要单指长按超过200ms后(后端提供判断信号),才可进行 Log: 根据后端长按信号,任务栏图标单指长按超过200ms后才可拖动 Task: https://pms.uniontech.com/zentao/task-view-30976.html Change-Id: Ia75e7b09b7ea2421089a0e5b8be4ff9a5049bae3 Reviewed-on: http://gerrit.uniontech.com/c/dde-dock/+/864 Reviewed-by: Reviewed-by: wangwei Reviewed-by: niecheng Tested-by: --- frame/panel/mainpanelcontrol.cpp | 17 ++++++++++++++++- frame/panel/mainpanelcontrol.h | 7 +++++++ .../fashiontray/fashiontraywidgetwrapper.cpp | 19 +++++++++++++++++++ .../fashiontray/fashiontraywidgetwrapper.h | 7 +++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/frame/panel/mainpanelcontrol.cpp b/frame/panel/mainpanelcontrol.cpp index e34421965..f2ed5f07b 100755 --- a/frame/panel/mainpanelcontrol.cpp +++ b/frame/panel/mainpanelcontrol.cpp @@ -77,6 +77,8 @@ MainPanelControl::MainPanelControl(QWidget *parent) , m_isHover(false) , m_needRecoveryWin(false) , m_isEnableLaunch(true) + , m_longPressed(false) + , m_gestureInter(new Gesture("com.deepin.daemon.Gesture", "/com/deepin/daemon/Gesture", QDBusConnection::systemBus(), this)) { init(); updateMainPanelLayout(); @@ -95,6 +97,14 @@ MainPanelControl::MainPanelControl(QWidget *parent) m_fixedSpliter->setFixedSize(0,0); m_appSpliter ->setFixedSize(0,0); m_traySpliter->setFixedSize(0,0); + + // 根据后端延迟触屏信号控制是否可进行图标拖动,收到延迟触屏信号可拖动,没有收到延迟触屏信号、点击松开就不可拖动 + connect(m_gestureInter, &Gesture::TouchSinglePressTimeout, this, [this]{ + m_longPressed = true; + }); + connect(m_gestureInter, &Gesture::TouchUpOrCancel, this, [this]{ + m_longPressed = false; + }); } MainPanelControl::~MainPanelControl() @@ -611,7 +621,7 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event) if (event->type() != QEvent::MouseMove) return false; - QMouseEvent *mouseEvent = static_cast(event); + QMouseEvent *mouseEvent = dynamic_cast(event); if (!mouseEvent || mouseEvent->buttons() != Qt::LeftButton) return false; @@ -627,6 +637,11 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event) if (distance.manhattanLength() < QApplication::startDragDistance()) return false; + // source为MouseEventSynthesizedByQt时,事件由触屏事件转换而来,触屏没有收到后端的延迟触屏信号时不进行拖动 + if (mouseEvent->source() == Qt::MouseEventSynthesizedByQt && !m_longPressed) { + return false; + } + startDrag(item); return QWidget::eventFilter(watched, event); diff --git a/frame/panel/mainpanelcontrol.h b/frame/panel/mainpanelcontrol.h index 9f67bfb14..6f2b07d13 100755 --- a/frame/panel/mainpanelcontrol.h +++ b/frame/panel/mainpanelcontrol.h @@ -28,7 +28,10 @@ #include #include +#include + using namespace Dock; +using Gesture = com::deepin::daemon::Gesture; class TrayPluginItem; class PluginsItem; @@ -142,6 +145,10 @@ private: bool m_isHover;//判断鼠标是否移到desktop区域 bool m_needRecoveryWin; // 判断鼠标移出desktop区域是否恢复之前窗口 bool m_isEnableLaunch;//判断是否使能了com.deepin.dde.dock.module.launcher + + // 保存触控屏长按状态 + bool m_longPressed; + Gesture* m_gestureInter; }; #endif // MAINPANELCONTROL_H diff --git a/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp b/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp index a3361eea1..bcefb23b2 100644 --- a/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp +++ b/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp @@ -38,6 +38,12 @@ DWIDGET_USE_NAMESPACE +Gesture *FashionTrayWidgetWrapper::m_gestureInter = new Gesture("com.deepin.daemon.Gesture" + , "/com/deepin/daemon/Gesture" + , QDBusConnection::systemBus() + , nullptr); +bool FashionTrayWidgetWrapper::m_longPressed = false; + FashionTrayWidgetWrapper::FashionTrayWidgetWrapper(const QString &itemKey, AbstractTrayWidget *absTrayWidget, QWidget *parent) : QWidget(parent), m_absTrayWidget(absTrayWidget), @@ -67,6 +73,14 @@ FashionTrayWidgetWrapper::FashionTrayWidgetWrapper(const QString &itemKey, Abstr setMinimumSize(PLUGIN_BACKGROUND_MIN_SIZE, PLUGIN_BACKGROUND_MIN_SIZE); m_absTrayWidget->show(); + + // 根据后端信号,记录触屏长按状态 + connect(m_gestureInter, &Gesture::TouchSinglePressTimeout, m_gestureInter, []{ + m_longPressed = true; + }, Qt::UniqueConnection); + connect(m_gestureInter, &Gesture::TouchUpOrCancel, m_gestureInter, []{ + m_longPressed = false; + }, Qt::UniqueConnection); } QPointer FashionTrayWidgetWrapper::absTrayWidget() const @@ -221,6 +235,11 @@ void FashionTrayWidgetWrapper::handleMouseMove(QMouseEvent *event) return; } + // 如果是触屏事件转换而来并且没有收到后端的延时触屏消息,不进行拖拽 + if (event->source() == Qt::MouseEventSynthesizedByQt && !m_longPressed) { + return; + } + event->accept(); QDrag drag(this); diff --git a/plugins/tray/fashiontray/fashiontraywidgetwrapper.h b/plugins/tray/fashiontray/fashiontraywidgetwrapper.h index 2ad938c23..3a7160d40 100644 --- a/plugins/tray/fashiontray/fashiontraywidgetwrapper.h +++ b/plugins/tray/fashiontray/fashiontraywidgetwrapper.h @@ -28,6 +28,10 @@ #include #include +#include + +using Gesture = com::deepin::daemon::Gesture; + #define TRAY_ITEM_DRAG_MIMEDATA "TrayItemDragDrop" class FashionTrayWidgetWrapper : public QWidget @@ -75,6 +79,9 @@ private: bool m_pressed; QString m_itemKey; QPoint MousePressPoint; + + static Gesture *m_gestureInter; + static bool m_longPressed; }; #endif //FASHIONTRAYWIDGETWRAPPER_H