From 9a72d823f08b72450f1dccfb609885c8832336db Mon Sep 17 00:00:00 2001 From: wangxuwen Date: Tue, 24 Sep 2019 19:17:51 +0800 Subject: [PATCH] feat(dock): click app item is easy to drag app --- frame/panel/mainpanelcontrol.cpp | 15 ++++++++++++++- frame/panel/mainpanelcontrol.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/frame/panel/mainpanelcontrol.cpp b/frame/panel/mainpanelcontrol.cpp index bafa011cc..163400e46 100644 --- a/frame/panel/mainpanelcontrol.cpp +++ b/frame/panel/mainpanelcontrol.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -535,11 +536,24 @@ bool MainPanelControl::eventFilter(QObject *watched, QEvent *event) if (item->itemType() != DockItem::App && item->itemType() != DockItem::Plugins && item->itemType() != DockItem::FixedPlugin) return false; + const QPoint pos = mouseEvent->globalPos(); + const QPoint distance = pos - m_mousePressPos; + if (distance.manhattanLength() < QApplication::startDragDistance()) + return false; + startDrag(item); return QWidget::eventFilter(watched, event); } +void MainPanelControl::mousePressEvent(QMouseEvent *e) +{ + if (e->button() == Qt::LeftButton) + m_mousePressPos = e->globalPos(); + + QWidget::mousePressEvent(e); +} + void MainPanelControl::startDrag(DockItem *item) { const QPixmap pixmap = item->grab(); @@ -660,7 +674,6 @@ DockItem *MainPanelControl::dropTargetItem(DockItem *sourceItem, QPoint point) targetItem = last; } } - } return targetItem; diff --git a/frame/panel/mainpanelcontrol.h b/frame/panel/mainpanelcontrol.h index 4295661d5..7d5a9355d 100644 --- a/frame/panel/mainpanelcontrol.h +++ b/frame/panel/mainpanelcontrol.h @@ -78,6 +78,7 @@ private: void dragLeaveEvent(QDragLeaveEvent *e) override; void dropEvent(QDropEvent *) override; bool eventFilter(QObject *watched, QEvent *event) override; + void mousePressEvent(QMouseEvent *e) override; void startDrag(DockItem *); DockItem *dropTargetItem(DockItem *sourceItem, QPoint point); @@ -110,6 +111,7 @@ private: QLabel *m_fixedSpliter; QLabel *m_appSpliter; QLabel *m_traySpliter; + QPoint m_mousePressPos; }; #endif // MAINPANELCONTROL_H