mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
add drag & drop
Change-Id: Ic940c761dee0abe2b1f2ed8952ef5070fe49a30e
This commit is contained in:
parent
dcca4fcad4
commit
c08a847a10
@ -69,9 +69,11 @@ void AppItem::paintEvent(QPaintEvent *e)
|
||||
|
||||
void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
// activate
|
||||
// TODO: dbus signature changed
|
||||
if (e->button() == Qt::LeftButton)
|
||||
if (e->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
const QPoint distance = MousePressPos - e->pos();
|
||||
if (distance.manhattanLength() < APP_DRAG_THRESHOLD)
|
||||
m_itemEntry->Activate();
|
||||
}
|
||||
|
||||
@ -129,12 +131,14 @@ void AppItem::startDrag()
|
||||
drag->setHotSpot(pixmap.rect().center());
|
||||
drag->setMimeData(new QMimeData);
|
||||
|
||||
emit dragStarted();
|
||||
const Qt::DropAction result = drag->exec(Qt::MoveAction);
|
||||
|
||||
qDebug() << "dnd result: " << result;
|
||||
|
||||
m_draging = false;
|
||||
update();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
void AppItem::initClientManager()
|
||||
|
@ -24,6 +24,9 @@ public:
|
||||
|
||||
ItemType itemType() const;
|
||||
|
||||
signals:
|
||||
void dragStarted() const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <QBoxLayout>
|
||||
#include <QDragEnterEvent>
|
||||
|
||||
DockItem *MainPanel::DragingItem = nullptr;
|
||||
|
||||
MainPanel::MainPanel(QWidget *parent)
|
||||
: QFrame(parent),
|
||||
m_itemLayout(new QBoxLayout(QBoxLayout::LeftToRight, this)),
|
||||
@ -25,7 +27,10 @@ MainPanel::MainPanel(QWidget *parent)
|
||||
|
||||
const QList<DockItem *> itemList = m_itemController->itemList();
|
||||
for (auto item : itemList)
|
||||
{
|
||||
initItemConnection(item);
|
||||
m_itemLayout->addWidget(item);
|
||||
}
|
||||
|
||||
setLayout(m_itemLayout);
|
||||
}
|
||||
@ -52,16 +57,36 @@ void MainPanel::dragEnterEvent(QDragEnterEvent *e)
|
||||
{
|
||||
// TODO: check
|
||||
e->accept();
|
||||
|
||||
if (!DragingItem)
|
||||
return;
|
||||
DragingItem->show();
|
||||
}
|
||||
|
||||
void MainPanel::dragMoveEvent(QDragMoveEvent *e)
|
||||
{
|
||||
qDebug() << e;
|
||||
Q_UNUSED(e);
|
||||
// qDebug() << e;
|
||||
}
|
||||
|
||||
void MainPanel::dragLeaveEvent(QDragLeaveEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
|
||||
if (!DragingItem)
|
||||
return;
|
||||
DragingItem->hide();
|
||||
}
|
||||
|
||||
void MainPanel::dropEvent(QDropEvent *e)
|
||||
{
|
||||
qDebug() << e;
|
||||
Q_UNUSED(e)
|
||||
// qDebug() << e;
|
||||
}
|
||||
|
||||
void MainPanel::initItemConnection(DockItem *item)
|
||||
{
|
||||
connect(item, &DockItem::dragStarted, this, &MainPanel::itemDragStarted);
|
||||
}
|
||||
|
||||
void MainPanel::adjustItemSize()
|
||||
@ -82,6 +107,7 @@ void MainPanel::adjustItemSize()
|
||||
|
||||
void MainPanel::itemInserted(const int index, DockItem *item)
|
||||
{
|
||||
initItemConnection(item);
|
||||
m_itemLayout->insertWidget(index, item);
|
||||
|
||||
item->setFixedWidth(80);
|
||||
@ -93,3 +119,8 @@ void MainPanel::itemRemoved(DockItem *item)
|
||||
{
|
||||
m_itemLayout->removeWidget(item);
|
||||
}
|
||||
|
||||
void MainPanel::itemDragStarted()
|
||||
{
|
||||
DragingItem = qobject_cast<DockItem *>(sender());
|
||||
}
|
||||
|
@ -20,16 +20,23 @@ private:
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void dragEnterEvent(QDragEnterEvent *e);
|
||||
void dragMoveEvent(QDragMoveEvent *e);
|
||||
void dragLeaveEvent(QDragLeaveEvent *e);
|
||||
void dropEvent(QDropEvent *e);
|
||||
|
||||
void initItemConnection(DockItem *item);
|
||||
|
||||
private slots:
|
||||
void adjustItemSize();
|
||||
void itemInserted(const int index, DockItem *item);
|
||||
void itemRemoved(DockItem *item);
|
||||
void itemDragStarted();
|
||||
|
||||
private:
|
||||
QBoxLayout *m_itemLayout;
|
||||
|
||||
DockItemController *m_itemController;
|
||||
|
||||
static DockItem *DragingItem;
|
||||
};
|
||||
|
||||
#endif // MAINPANEL_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user