mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
add drag & drop swap
Change-Id: I4fd478a8a1c1a6150e7313439a06224e9c180a2a
This commit is contained in:
parent
c08a847a10
commit
35c5bd15f8
@ -27,6 +27,18 @@ const QList<DockItem *> DockItemController::itemList() const
|
||||
return m_itemList;
|
||||
}
|
||||
|
||||
void DockItemController::itemMove(DockItem * const moveItem, DockItem * const replaceItem)
|
||||
{
|
||||
const int moveIndex = m_itemList.indexOf(moveItem);
|
||||
const int replaceIndex = m_itemList.indexOf(replaceItem);
|
||||
|
||||
m_itemList.removeAt(moveIndex);
|
||||
emit itemRemoved(moveItem);
|
||||
|
||||
m_itemList.insert(replaceIndex, moveItem);
|
||||
emit itemInserted(replaceIndex, moveItem);
|
||||
}
|
||||
|
||||
DockItemController::DockItemController(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_appInter(new DBusDock(this)),
|
||||
|
@ -22,6 +22,9 @@ signals:
|
||||
void itemInserted(const int index, DockItem *item);
|
||||
void itemRemoved(DockItem *item);
|
||||
|
||||
public slots:
|
||||
void itemMove(DockItem * const moveItem, DockItem * const replaceItem);
|
||||
|
||||
private:
|
||||
explicit DockItemController(QObject *parent = 0);
|
||||
void appItemAdded(const QDBusObjectPath &path, const int index);
|
||||
|
@ -138,7 +138,6 @@ void AppItem::startDrag()
|
||||
|
||||
m_draging = false;
|
||||
update();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
void AppItem::initClientManager()
|
||||
|
@ -58,23 +58,24 @@ void MainPanel::dragEnterEvent(QDragEnterEvent *e)
|
||||
// TODO: check
|
||||
e->accept();
|
||||
|
||||
if (!DragingItem)
|
||||
return;
|
||||
// qDebug() << e->pos() << itemAt(e->pos());
|
||||
|
||||
DragingItem->show();
|
||||
}
|
||||
|
||||
void MainPanel::dragMoveEvent(QDragMoveEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
// qDebug() << e;
|
||||
DockItem *item = itemAt(e->pos());
|
||||
if (item == DragingItem)
|
||||
return;
|
||||
|
||||
m_itemController->itemMove(DragingItem, item);
|
||||
}
|
||||
|
||||
void MainPanel::dragLeaveEvent(QDragLeaveEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
|
||||
if (!DragingItem)
|
||||
return;
|
||||
DragingItem->hide();
|
||||
}
|
||||
|
||||
@ -89,6 +90,23 @@ void MainPanel::initItemConnection(DockItem *item)
|
||||
connect(item, &DockItem::dragStarted, this, &MainPanel::itemDragStarted);
|
||||
}
|
||||
|
||||
DockItem *MainPanel::itemAt(const QPoint &point)
|
||||
{
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
|
||||
for (auto item : itemList)
|
||||
{
|
||||
QRect rect;
|
||||
rect.setTopLeft(item->pos());
|
||||
rect.setSize(item->size());
|
||||
|
||||
if (rect.contains(point))
|
||||
return item;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MainPanel::adjustItemSize()
|
||||
{
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
@ -123,4 +141,6 @@ void MainPanel::itemRemoved(DockItem *item)
|
||||
void MainPanel::itemDragStarted()
|
||||
{
|
||||
DragingItem = qobject_cast<DockItem *>(sender());
|
||||
|
||||
DragingItem->setVisible(rect().contains(QCursor::pos()));
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ private:
|
||||
void dropEvent(QDropEvent *e);
|
||||
|
||||
void initItemConnection(DockItem *item);
|
||||
DockItem *itemAt(const QPoint &point);
|
||||
|
||||
private slots:
|
||||
void adjustItemSize();
|
||||
|
Loading…
x
Reference in New Issue
Block a user