mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +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;
|
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)
|
DockItemController::DockItemController(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_appInter(new DBusDock(this)),
|
m_appInter(new DBusDock(this)),
|
||||||
|
@ -22,6 +22,9 @@ signals:
|
|||||||
void itemInserted(const int index, DockItem *item);
|
void itemInserted(const int index, DockItem *item);
|
||||||
void itemRemoved(DockItem *item);
|
void itemRemoved(DockItem *item);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void itemMove(DockItem * const moveItem, DockItem * const replaceItem);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit DockItemController(QObject *parent = 0);
|
explicit DockItemController(QObject *parent = 0);
|
||||||
void appItemAdded(const QDBusObjectPath &path, const int index);
|
void appItemAdded(const QDBusObjectPath &path, const int index);
|
||||||
|
@ -138,7 +138,6 @@ void AppItem::startDrag()
|
|||||||
|
|
||||||
m_draging = false;
|
m_draging = false;
|
||||||
update();
|
update();
|
||||||
setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppItem::initClientManager()
|
void AppItem::initClientManager()
|
||||||
|
@ -58,23 +58,24 @@ void MainPanel::dragEnterEvent(QDragEnterEvent *e)
|
|||||||
// TODO: check
|
// TODO: check
|
||||||
e->accept();
|
e->accept();
|
||||||
|
|
||||||
if (!DragingItem)
|
// qDebug() << e->pos() << itemAt(e->pos());
|
||||||
return;
|
|
||||||
DragingItem->show();
|
DragingItem->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPanel::dragMoveEvent(QDragMoveEvent *e)
|
void MainPanel::dragMoveEvent(QDragMoveEvent *e)
|
||||||
{
|
{
|
||||||
Q_UNUSED(e);
|
DockItem *item = itemAt(e->pos());
|
||||||
// qDebug() << e;
|
if (item == DragingItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_itemController->itemMove(DragingItem, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPanel::dragLeaveEvent(QDragLeaveEvent *e)
|
void MainPanel::dragLeaveEvent(QDragLeaveEvent *e)
|
||||||
{
|
{
|
||||||
Q_UNUSED(e)
|
Q_UNUSED(e)
|
||||||
|
|
||||||
if (!DragingItem)
|
|
||||||
return;
|
|
||||||
DragingItem->hide();
|
DragingItem->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +90,23 @@ void MainPanel::initItemConnection(DockItem *item)
|
|||||||
connect(item, &DockItem::dragStarted, this, &MainPanel::itemDragStarted);
|
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()
|
void MainPanel::adjustItemSize()
|
||||||
{
|
{
|
||||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||||
@ -123,4 +141,6 @@ void MainPanel::itemRemoved(DockItem *item)
|
|||||||
void MainPanel::itemDragStarted()
|
void MainPanel::itemDragStarted()
|
||||||
{
|
{
|
||||||
DragingItem = qobject_cast<DockItem *>(sender());
|
DragingItem = qobject_cast<DockItem *>(sender());
|
||||||
|
|
||||||
|
DragingItem->setVisible(rect().contains(QCursor::pos()));
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ private:
|
|||||||
void dropEvent(QDropEvent *e);
|
void dropEvent(QDropEvent *e);
|
||||||
|
|
||||||
void initItemConnection(DockItem *item);
|
void initItemConnection(DockItem *item);
|
||||||
|
DockItem *itemAt(const QPoint &point);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void adjustItemSize();
|
void adjustItemSize();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user