feat(dock): click app item is easy to drag app

This commit is contained in:
wangxuwen 2019-09-24 19:17:51 +08:00
parent cd405aee3e
commit 9a72d823f0
2 changed files with 16 additions and 1 deletions

View File

@ -30,6 +30,7 @@
#include <QTimer>
#include <QStandardPaths>
#include <QString>
#include <QApplication>
#include <DGuiApplicationHelper>
#include <DWindowManagerHelper>
@ -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;

View File

@ -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